feat: more role backend and admin/writer roles additions and adjustments

This commit is contained in:
Florian Sylvain committed 2026-10-26 18:15:26 +01:00
1 parent 8c6c6456da
commit de142f6c5f
131 files changed
+2663 -435

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
package access
import (
"RenewCMS/api/pkg/apperr"
"RenewCMS/internal/domain/role"
"context"
"errors"
"net/http"
)
type grantsContextKey struct{}
func NewContext(ctx context.Context, grants role.GrantSet) context.Context {
return context.WithValue(ctx, grantsContextKey{}, grants)
}
func Grants(r *http.Request) role.GrantSet {
grants, _ := r.Context().Value(grantsContextKey{}).(role.GrantSet)
return grants
}
func WriteMissingPermission(w http.ResponseWriter, key string) {
w.Header().Set(apperr.MissingPermissionHeader, key)
http.Error(w, apperr.MissingPermissionErrorMessage, http.StatusForbidden)
}
func WriteIfMissingPermission(w http.ResponseWriter, err error) bool {
var missing role.MissingPermissionError
if !errors.As(err, &missing) {
return false
}
WriteMissingPermission(w, missing.Key)
return true
}