chore: use common header parsing
This commit is contained in:
7
go.mod
7
go.mod
@@ -1,8 +1,11 @@
|
||||
module monitoring-pf
|
||||
|
||||
go 1.25.0
|
||||
go 1.25.7
|
||||
|
||||
require modernc.org/sqlite v1.50.1
|
||||
require (
|
||||
gitea.estateliga.work/admin/portal-common v0.3.0
|
||||
modernc.org/sqlite v1.50.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
|
||||
2
go.sum
2
go.sum
@@ -1,3 +1,5 @@
|
||||
gitea.estateliga.work/admin/portal-common v0.3.0 h1:xpr9UeLXk5pCcNXcTVGZzJZr0Ni7An7DV0OkuYv9qVM=
|
||||
gitea.estateliga.work/admin/portal-common v0.3.0/go.mod h1:C860q6g38KVMsv+mKv6k1Vm7smVRCycl+N6r63TElnk=
|
||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs=
|
||||
|
||||
@@ -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