Skip to content

Commit

Permalink
Make permission and role ids unique (#5051)
Browse files Browse the repository at this point in the history
* make permission ids unique

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>

* deduplicate roleids after listing permissions

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
  • Loading branch information
butonic authored Nov 15, 2022
1 parent 4971330 commit 7443a9a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions services/settings/pkg/service/v0/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,14 @@ func (g Service) hasStaticPermission(ctx context.Context, permissionID string) b
return false
}

roleIDs = make([]string, 0, len(assignments))
// deduplicate roleids
uniqueRoleIds := make(map[string]struct{})
for _, a := range assignments {
roleIDs = append(roleIDs, a.GetRoleId())
uniqueRoleIds[a.GetRoleId()] = struct{}{}
}
roleIDs = make([]string, 0, len(uniqueRoleIds))
for a := range uniqueRoleIds {
roleIDs = append(roleIDs, a)
}
}
p, err := g.manager.ReadPermissionByID(permissionID, roleIDs)
Expand Down
2 changes: 1 addition & 1 deletion services/settings/pkg/service/v0/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (
RoleManagementPermissionName string = "role-management"

// SettingsManagementPermissionID is the hardcoded setting UUID for the settings management permission
SettingsManagementPermissionID string = "79e13b30-3e22-11eb-bc51-0b9f0bad9a58"
SettingsManagementPermissionID string = "3d58f441-4a05-42f8-9411-ef5874528ae1"
// SettingsManagementPermissionName is the hardcoded setting name for the settings management permission
SettingsManagementPermissionName string = "settings-management"

Expand Down
2 changes: 1 addition & 1 deletion services/settings/pkg/store/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (
RoleManagementPermissionName string = "role-management"

// SettingsManagementPermissionID is the hardcoded setting UUID for the settings management permission
SettingsManagementPermissionID string = "79e13b30-3e22-11eb-bc51-0b9f0bad9a58"
SettingsManagementPermissionID string = "3d58f441-4a05-42f8-9411-ef5874528ae1"
// SettingsManagementPermissionName is the hardcoded setting name for the settings management permission
SettingsManagementPermissionName string = "settings-management"

Expand Down

0 comments on commit 7443a9a

Please sign in to comment.