mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-20 09:16:40 +00:00
get role permissions for all modules
This commit is contained in:
@@ -287,35 +287,20 @@ func (h *handler) getCurrentUser(w http.ResponseWriter, r *http.Request) {
|
||||
func toUserWithPermissionsResponse(user *users.UserInfoWithPermissions, userID string) *api.User {
|
||||
response := toUserResponse(user.UserInfo, userID)
|
||||
|
||||
permissions := api.UserPermissions{
|
||||
// stringify modules and operations keys
|
||||
modules := make(map[string]map[string]bool)
|
||||
for module, operations := range user.Permissions {
|
||||
modules[string(module)] = make(map[string]bool)
|
||||
for op, val := range operations {
|
||||
modules[string(module)][string(op)] = val
|
||||
}
|
||||
}
|
||||
|
||||
response.Permissions = &api.UserPermissions{
|
||||
IsRestricted: user.Restricted,
|
||||
Modules: modules,
|
||||
}
|
||||
|
||||
if len(user.Permissions.AutoAllowNew) > 0 {
|
||||
permissions.Default = make(map[string]bool)
|
||||
for k, v := range user.Permissions.AutoAllowNew {
|
||||
permissions.Default[string(k)] = v
|
||||
}
|
||||
}
|
||||
|
||||
if len(user.Permissions.Permissions) > 0 {
|
||||
modules := make(map[string]map[string]bool)
|
||||
for module, operations := range user.Permissions.Permissions {
|
||||
if len(operations) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
access := make(map[string]bool)
|
||||
for k, v := range operations {
|
||||
access[string(k)] = v
|
||||
}
|
||||
modules[string(module)] = access
|
||||
}
|
||||
permissions.Modules = &modules
|
||||
}
|
||||
|
||||
response.Permissions = &permissions
|
||||
|
||||
return response
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user