ch some
This commit is contained in:
1 parent
28509eb4ca
commit
d1a6fcaadc
102 files changed
+2089
-1957
No files matched your search
@@ -0,0 +1,37 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"online-back/internal/identity/permission"
|
||||
)
|
||||
|
||||
func GroupProfileModules(perms []ProfilePermissionDTO) []ProfileModuleDTO {
|
||||
buckets := make(map[string][]ProfilePermissionDTO)
|
||||
seen := make(map[string]struct{})
|
||||
for _, p := range perms {
|
||||
module := p.Module
|
||||
buckets[module] = append(buckets[module], p)
|
||||
seen[module] = struct{}{}
|
||||
}
|
||||
|
||||
modules := make([]ProfileModuleDTO, 0, len(seen))
|
||||
for _, name := range permission.ModuleOrder() {
|
||||
ps, ok := buckets[name]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
modules = append(modules, ProfileModuleDTO{Module: name, Permissions: ps})
|
||||
delete(seen, name)
|
||||
}
|
||||
|
||||
var extra []string
|
||||
for name := range seen {
|
||||
extra = append(extra, name)
|
||||
}
|
||||
sort.Strings(extra)
|
||||
for _, name := range extra {
|
||||
modules = append(modules, ProfileModuleDTO{Module: name, Permissions: buckets[name]})
|
||||
}
|
||||
return modules
|
||||
}
|
||||
Reference in new issue
Block a user