chore: use common header parsing
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user