diff --git a/changelog/unreleased/fix-roles-label.md b/changelog/unreleased/fix-roles-label.md new file mode 100644 index 00000000000..4578a924f5a --- /dev/null +++ b/changelog/unreleased/fix-roles-label.md @@ -0,0 +1,8 @@ +Bugfix: Clean up unified roles label + +Clean up the unified roles label + +https://github.com/owncloud/ocis/pull/11494 +https://github.com/owncloud/ocis/issues/11470 +https://github.com/owncloud/ocis/issues/11254 +https://github.com/owncloud/ocis/issues/10082 diff --git a/services/graph/pkg/command/unified_roles.go b/services/graph/pkg/command/unified_roles.go index ee31e5cb7f6..57ebe9fc588 100644 --- a/services/graph/pkg/command/unified_roles.go +++ b/services/graph/pkg/command/unified_roles.go @@ -14,23 +14,6 @@ import ( "github.com/owncloud/ocis/v2/services/graph/pkg/unifiedrole" ) -var ( - unifiedRolesNames = map[string]string{ - unifiedrole.UnifiedRoleViewerID: "Viewer", - unifiedrole.UnifiedRoleViewerListGrantsID: "ViewerListGrants", - unifiedrole.UnifiedRoleSpaceViewerID: "SpaceViewer", - unifiedrole.UnifiedRoleEditorID: "Editor", - unifiedrole.UnifiedRoleEditorListGrantsID: "EditorListGrants", - unifiedrole.UnifiedRoleSpaceEditorID: "SpaceEditor", - unifiedrole.UnifiedRoleSpaceEditorWithoutVersionsID: "SpaceEditorWithoutVersions", - unifiedrole.UnifiedRoleFileEditorID: "FileEditor", - unifiedrole.UnifiedRoleFileEditorListGrantsID: "FileEditorListGrants", - unifiedrole.UnifiedRoleEditorLiteID: "EditorLite", - unifiedrole.UnifiedRoleManagerID: "SpaceManager", - unifiedrole.UnifiedRoleSecureViewerID: "SecureViewer", - } -) - // UnifiedRoles bundles available commands for unified roles func UnifiedRoles(cfg *config.Config) cli.Commands { cmds := cli.Commands{ @@ -58,7 +41,7 @@ func listUnifiedRoles(cfg *config.Config) *cli.Command { tbl.SetRowLine(true) tbl.SetAutoMergeCellsByColumnIndex([]int{0}) // rowspan should only affect the first column - headers := []string{"Name", "UID", "Enabled", "Description", "Condition", "Allowed resource actions"} + headers := []string{"Label", "UID", "Enabled", "Description", "Condition", "Allowed resource actions"} tbl.SetHeader(headers) for _, definition := range unifiedrole.GetRoles(unifiedrole.RoleFilterAll()) { @@ -66,7 +49,7 @@ func listUnifiedRoles(cfg *config.Config) *cli.Command { const disabled = "disabled" rows := [][]string{ - {unifiedRolesNames[definition.GetId()], definition.GetId(), disabled, definition.GetDescription()}, + {unifiedrole.GetUnifiedRoleLabel(definition.GetId()), definition.GetId(), disabled, definition.GetDescription()}, } if slices.Contains(cfg.UnifiedRoles.AvailableRoles, definition.GetId()) { rows[0][2] = enabled diff --git a/services/graph/pkg/unifiedrole/roles.go b/services/graph/pkg/unifiedrole/roles.go index b403408b35c..9b645377b52 100644 --- a/services/graph/pkg/unifiedrole/roles.go +++ b/services/graph/pkg/unifiedrole/roles.go @@ -193,6 +193,26 @@ var ( // UnifiedRole FullDenial, Role DisplayName (resolves directly) _deniedUnifiedRoleDisplayName = l10n.Template("Cannot access") + // unifiedRoleLabel contains the mapping of unified role IDs to their labels. + unifiedRoleLabel = map[string]string{ + UnifiedRoleViewerID: "Viewer", + UnifiedRoleViewerListGrantsID: "ViewerListGrants", + UnifiedRoleSpaceViewerID: "SpaceViewer", + UnifiedRoleEditorID: "Editor", + UnifiedRoleEditorListGrantsID: "EditorListGrants", + UnifiedRoleEditorListGrantsWithVersionsID: "EditorListGrantsWithVersions", + UnifiedRoleSpaceEditorID: "SpaceEditor", + UnifiedRoleSpaceEditorWithoutVersionsID: "SpaceEditorWithoutVersions", + UnifiedRoleSpaceEditorWithoutTrashbinID: "SpaceEditorWithoutTrashbin", + UnifiedRoleFileEditorID: "FileEditor", + UnifiedRoleFileEditorListGrantsID: "FileEditorListGrants", + UnifiedRoleFileEditorListGrantsWithVersionsID: "FileEditorListGrantsWithVersions", + UnifiedRoleEditorLiteID: "EditorLite", + UnifiedRoleManagerID: "Manager", + UnifiedRoleSecureViewerID: "SecureViewer", + UnifiedRoleDeniedID: "Denied", + } + // legacyNames contains the legacy role names. legacyNames = map[string]string{ UnifiedRoleViewerID: conversions.RoleViewer, @@ -596,6 +616,11 @@ func GetRolesByPermissions(roleSet []*libregraph.UnifiedRoleDefinition, actions return weightRoles(roles, constraints, descending) } +// GetUnifiedRoleLabel returns the label for the provided unified role ID +func GetUnifiedRoleLabel(unifiedRoleId string) string { + return unifiedRoleLabel[unifiedRoleId] +} + // GetLegacyRoleName returns the legacy role name for the provided role func GetLegacyRoleName(role libregraph.UnifiedRoleDefinition) string { return legacyNames[role.GetId()] diff --git a/services/graph/pkg/unifiedrole/roles_test.go b/services/graph/pkg/unifiedrole/roles_test.go index dcc9a20c1e6..c1c9719d906 100644 --- a/services/graph/pkg/unifiedrole/roles_test.go +++ b/services/graph/pkg/unifiedrole/roles_test.go @@ -270,3 +270,32 @@ func TestGetAllowedResourceActions(t *testing.T) { }) } } + +func TestGetUnifiedRoleLabel(t *testing.T) { + type args struct { + unifiedRoleId string + } + tests := []struct { + name string + args args + want string + }{ + { + name: "Empty", + args: args{unifiedRoleId: ""}, + want: "", + }, + { + name: "Unknown", + args: args{unifiedRoleId: "unknown"}, + want: "", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := unifiedrole.GetUnifiedRoleLabel(tt.args.unifiedRoleId); got != tt.want { + t.Errorf("GetUnifiedRoleLabel() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/services/web/pkg/theme/service_test.go b/services/web/pkg/theme/service_test.go index 9b8efcc037d..de92a87c9c7 100644 --- a/services/web/pkg/theme/service_test.go +++ b/services/web/pkg/theme/service_test.go @@ -70,5 +70,5 @@ func TestService_Get(t *testing.T) { // brandingTheme assert.Equal(t, jsonData.Get("_branding").String(), "_branding") // themeDefaults - assert.Equal(t, jsonData.Get("common.shareRoles."+unifiedrole.UnifiedRoleViewerID+".name").String(), "UnifiedRoleViewer") + assert.Equal(t, jsonData.Get("common.shareRoles."+unifiedrole.UnifiedRoleViewerID+".label").String(), "Viewer") } diff --git a/services/web/pkg/theme/theme.go b/services/web/pkg/theme/theme.go index f4f6bcddcc0..01bad8b0781 100644 --- a/services/web/pkg/theme/theme.go +++ b/services/web/pkg/theme/theme.go @@ -18,67 +18,67 @@ var themeDefaults = KV{ "common": KV{ "shareRoles": KV{ unifiedrole.UnifiedRoleViewerID: KV{ - "name": "UnifiedRoleViewer", + "label": unifiedrole.GetUnifiedRoleLabel(unifiedrole.UnifiedRoleViewerID), "iconName": "eye", }, unifiedrole.UnifiedRoleViewerListGrantsID: KV{ - "name": "UnifiedRoleViewerListGrants", + "label": unifiedrole.GetUnifiedRoleLabel(unifiedrole.UnifiedRoleViewerListGrantsID), "iconName": "eye", }, unifiedrole.UnifiedRoleSpaceViewerID: KV{ - "label": "UnifiedRoleSpaceViewer", + "label": unifiedrole.GetUnifiedRoleLabel(unifiedrole.UnifiedRoleSpaceViewerID), "iconName": "eye", }, unifiedrole.UnifiedRoleFileEditorID: KV{ - "label": "UnifiedRoleFileEditor", + "label": unifiedrole.GetUnifiedRoleLabel(unifiedrole.UnifiedRoleFileEditorID), "iconName": "pencil", }, unifiedrole.UnifiedRoleFileEditorListGrantsID: KV{ - "label": "UnifiedRoleFileEditorListGrants", + "label": unifiedrole.GetUnifiedRoleLabel(unifiedrole.UnifiedRoleFileEditorListGrantsID), "iconName": "pencil", }, unifiedrole.UnifiedRoleFileEditorListGrantsWithVersionsID: KV{ - "label": "UnifiedRoleFileEditorListGrantsWithVersions", + "label": unifiedrole.GetUnifiedRoleLabel(unifiedrole.UnifiedRoleFileEditorListGrantsWithVersionsID), "iconName": "pencil", }, unifiedrole.UnifiedRoleEditorID: KV{ - "label": "UnifiedRoleEditor", + "label": unifiedrole.GetUnifiedRoleLabel(unifiedrole.UnifiedRoleEditorID), "iconName": "pencil", }, unifiedrole.UnifiedRoleEditorListGrantsID: KV{ - "label": "UnifiedRoleEditorListGrants", + "label": unifiedrole.GetUnifiedRoleLabel(unifiedrole.UnifiedRoleEditorListGrantsID), "iconName": "pencil", }, unifiedrole.UnifiedRoleEditorListGrantsWithVersionsID: KV{ - "label": "UnifiedRoleEditorListGrantsWithVersions", + "label": unifiedrole.GetUnifiedRoleLabel(unifiedrole.UnifiedRoleEditorListGrantsWithVersionsID), "iconName": "pencil", }, unifiedrole.UnifiedRoleSpaceEditorID: KV{ - "label": "UnifiedRoleSpaceEditor", + "label": unifiedrole.GetUnifiedRoleLabel(unifiedrole.UnifiedRoleSpaceEditorID), "iconName": "pencil", }, unifiedrole.UnifiedRoleSpaceEditorWithoutVersionsID: KV{ - "label": "UnifiedRoleSpaceEditorWithoutVersions", + "label": unifiedrole.GetUnifiedRoleLabel(unifiedrole.UnifiedRoleSpaceEditorWithoutVersionsID), "iconName": "pencil", }, unifiedrole.UnifiedRoleSpaceEditorWithoutTrashbinID: KV{ - "label": "UnifiedRoleSpaceEditorWithoutTrashbin", + "label": unifiedrole.GetUnifiedRoleLabel(unifiedrole.UnifiedRoleSpaceEditorWithoutTrashbinID), "iconName": "pencil", }, unifiedrole.UnifiedRoleManagerID: KV{ - "label": "UnifiedRoleManager", + "label": unifiedrole.GetUnifiedRoleLabel(unifiedrole.UnifiedRoleManagerID), "iconName": "user-star", }, unifiedrole.UnifiedRoleEditorLiteID: KV{ - "label": "UnifiedRoleEditorLite", + "label": unifiedrole.GetUnifiedRoleLabel(unifiedrole.UnifiedRoleEditorLiteID), "iconName": "upload", }, unifiedrole.UnifiedRoleSecureViewerID: KV{ - "label": "UnifiedRoleSecureView", + "label": unifiedrole.GetUnifiedRoleLabel(unifiedrole.UnifiedRoleSecureViewerID), "iconName": "shield", }, unifiedrole.UnifiedRoleDeniedID: KV{ - "label": "UnifiedRoleFullDenial", + "label": unifiedrole.GetUnifiedRoleLabel(unifiedrole.UnifiedRoleDeniedID), "iconName": "stop-circle", }, },