Skip to content

Commit

Permalink
preserver platfrom user admin role (#3187)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishek9686 authored Nov 8, 2024
1 parent 4a92c90 commit b796331
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
21 changes: 19 additions & 2 deletions pro/logic/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import (

func MigrateUserRoleAndGroups(user models.User) {
var err error
if user.PlatformRoleID == models.AdminRole || user.PlatformRoleID == models.SuperAdminRole {
return
}
if len(user.RemoteGwIDs) > 0 {
// define user roles for network
// assign relevant network role to user
Expand All @@ -31,13 +34,27 @@ func MigrateUserRoleAndGroups(user models.User) {
}
}
if len(user.NetworkRoles) > 0 {
for netID := range user.NetworkRoles {
for netID, netRoles := range user.NetworkRoles {
var g models.UserGroup
adminAccess := false
for netRoleID := range netRoles {
permTemplate, err := logic.GetRole(netRoleID)
if err == nil {
if permTemplate.FullAccess {
adminAccess = true
}
}
}

if user.PlatformRoleID == models.ServiceUser {
g, err = GetUserGroup(models.UserGroupID(fmt.Sprintf("%s-%s-grp", netID, models.NetworkUser)))
} else {
role := models.NetworkUser
if adminAccess {
role = models.NetworkAdmin
}
g, err = GetUserGroup(models.UserGroupID(fmt.Sprintf("%s-%s-grp",
netID, models.NetworkAdmin)))
netID, role)))
}
if err != nil {
continue
Expand Down
4 changes: 1 addition & 3 deletions pro/logic/user_mgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -1229,9 +1229,7 @@ func AddGlobalNetRolesToAdmins(u models.User) {
if u.PlatformRoleID != models.SuperAdminRole && u.PlatformRoleID != models.AdminRole {
return
}
if u.UserGroups == nil {
u.UserGroups = make(map[models.UserGroupID]struct{})
}
u.UserGroups = make(map[models.UserGroupID]struct{})
u.UserGroups[models.UserGroupID(fmt.Sprintf("global-%s-grp", models.NetworkAdmin))] = struct{}{}
logic.UpsertUser(u)
}

0 comments on commit b796331

Please sign in to comment.