Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make permission and role ids unique #5051

Merged
merged 2 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this deduplication is mainly needed because of #3432 ?

I am fine merging this. But it seems to paper over a couple of issues:

  1. AFAIK for now we wanted to have a restriction so that every user can only have a single role assigned. This does not seem to be enforced anywhere.
  2. It is possible to create the same assignment multiple times. The server will happily create that over and over again.

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