chore: use common header parsing
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
|||||||
"monitoring-tg/internal/aiservice"
|
"monitoring-tg/internal/aiservice"
|
||||||
"monitoring-tg/internal/dbretry"
|
"monitoring-tg/internal/dbretry"
|
||||||
|
|
||||||
|
commonmw "gitea.estateliga.work/admin/portal-common/middleware"
|
||||||
"github.com/jackc/pgx/v5"
|
"github.com/jackc/pgx/v5"
|
||||||
"github.com/jackc/pgx/v5/pgxpool"
|
"github.com/jackc/pgx/v5/pgxpool"
|
||||||
"github.com/minio/minio-go/v7"
|
"github.com/minio/minio-go/v7"
|
||||||
@@ -1515,12 +1516,12 @@ func (a *app) readScope(w http.ResponseWriter, r *http.Request, manage bool) (ac
|
|||||||
}
|
}
|
||||||
|
|
||||||
func readAccess(r *http.Request) accessScope {
|
func readAccess(r *http.Request) accessScope {
|
||||||
admin := r.Header.Get("X-User-Is-Admin") == "1"
|
admin := commonmw.HeaderBool(r, "X-User-Is-Admin")
|
||||||
deptHead := r.Header.Get("X-User-Is-Department-Head") == "1"
|
deptHead := commonmw.HeaderBool(r, "X-User-Is-Department-Head")
|
||||||
canManage := r.Header.Get("X-Monitoring-TG-Can-Manage") == "1"
|
canManage := commonmw.HeaderBool(r, "X-Monitoring-TG-Can-Manage")
|
||||||
canAuth := r.Header.Get("X-Monitoring-TG-Can-Auth") == "1"
|
canAuth := commonmw.HeaderBool(r, "X-Monitoring-TG-Can-Auth")
|
||||||
deptID := strings.TrimSpace(r.Header.Get("X-User-Department-Id"))
|
deptID := strings.TrimSpace(r.Header.Get("X-User-Department-Id"))
|
||||||
deptIDs := parseCSVHeader(r.Header.Get("X-User-Department-Ids"))
|
deptIDs := commonmw.HeaderCSV(r, "X-User-Department-Ids")
|
||||||
if deptID != "" {
|
if deptID != "" {
|
||||||
deptIDs = appendUniqueString(deptIDs, deptID)
|
deptIDs = appendUniqueString(deptIDs, deptID)
|
||||||
}
|
}
|
||||||
@@ -1533,19 +1534,6 @@ func readAccess(r *http.Request) accessScope {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseCSVHeader(raw string) []string {
|
|
||||||
raw = strings.TrimSpace(raw)
|
|
||||||
if raw == "" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
parts := strings.Split(raw, ",")
|
|
||||||
out := make([]string, 0, len(parts))
|
|
||||||
for _, part := range parts {
|
|
||||||
out = appendUniqueString(out, strings.TrimSpace(part))
|
|
||||||
}
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
func appendUniqueString(items []string, value string) []string {
|
func appendUniqueString(items []string, value string) []string {
|
||||||
value = strings.TrimSpace(value)
|
value = strings.TrimSpace(value)
|
||||||
if value == "" {
|
if value == "" {
|
||||||
|
|||||||
1
go.mod
1
go.mod
@@ -3,6 +3,7 @@ module monitoring-tg
|
|||||||
go 1.25.7
|
go 1.25.7
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
gitea.estateliga.work/admin/portal-common v0.3.0
|
||||||
github.com/jackc/pgx/v5 v5.9.1
|
github.com/jackc/pgx/v5 v5.9.1
|
||||||
github.com/minio/minio-go/v7 v7.2.0
|
github.com/minio/minio-go/v7 v7.2.0
|
||||||
)
|
)
|
||||||
|
|||||||
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/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||||
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||||
|
|||||||
Reference in New Issue
Block a user