mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 21:41:55 +00:00
45 lines
984 B
Go
45 lines
984 B
Go
package capabilities
|
|
|
|
import (
|
|
"strings"
|
|
|
|
permission "gitlab.com/mbugroup/lti-api.git/internal/middleware"
|
|
)
|
|
|
|
// FromPermissions returns a filtered map of capabilities that the frontend can use
|
|
// to toggle features. Only permissions recognized by the application are exposed.
|
|
func FromPermissions(perms []string) map[string]bool {
|
|
if len(perms) == 0 {
|
|
return nil
|
|
}
|
|
|
|
out := make(map[string]bool)
|
|
for _, perm := range perms {
|
|
if key, ok := normalizeAndAllow(perm); ok {
|
|
out[key] = true
|
|
}
|
|
}
|
|
if len(out) == 0 {
|
|
return nil
|
|
}
|
|
return out
|
|
}
|
|
|
|
func normalizeAndAllow(perm string) (string, bool) {
|
|
perm = strings.ToLower(strings.TrimSpace(perm))
|
|
if perm == "" {
|
|
return "", false
|
|
}
|
|
if _, ok := allowed[perm]; !ok {
|
|
return "", false
|
|
}
|
|
return perm, true
|
|
}
|
|
|
|
var allowed = map[string]struct{}{
|
|
permission.PermissionRecordingRead: {},
|
|
permission.PermissionRecordingCreate: {},
|
|
permission.PermissionRecordingUpdate: {},
|
|
permission.PermissionRecordingDelete: {},
|
|
}
|