chore: use common header parsing

This commit is contained in:
Grendgi
2026-06-17 14:19:13 +03:00
parent 703f544cdf
commit ea2063ff40
3 changed files with 12 additions and 17 deletions

View File

@@ -7,6 +7,8 @@ import (
"net/http"
"strconv"
"strings"
commonmw "gitea.estateliga.work/admin/portal-common/middleware"
)
type Server struct {
@@ -510,11 +512,11 @@ func portalUserID(r *http.Request) string {
}
func isAdmin(r *http.Request) bool {
return r.Header.Get("X-User-Is-Admin") == "1"
return commonmw.HeaderBool(r, "X-User-Is-Admin")
}
func canViewTeam(r *http.Request) bool {
return isAdmin(r) || r.Header.Get("X-User-Is-Department-Head") == "1"
return isAdmin(r) || commonmw.HeaderBool(r, "X-User-Is-Department-Head")
}
func canManagePortalUser(r *http.Request, targetPortalID string) bool {
@@ -534,19 +536,7 @@ func canManagePortalUser(r *http.Request, targetPortalID string) bool {
}
func subordinatePortalIDs(r *http.Request) []string {
raw := strings.TrimSpace(r.Header.Get("X-User-Subordinates"))
if raw == "" {
return []string{}
}
parts := strings.Split(raw, ",")
out := make([]string, 0, len(parts))
for _, part := range parts {
id := strings.TrimSpace(part)
if id != "" {
out = append(out, id)
}
}
return out
return commonmw.HeaderCSV(r, "X-User-Subordinates")
}
func ownerPortalIDFromQuery(r *http.Request) *string {