mirror of
https://github.com/owncloud/ocis
synced 2026-04-25 17:25:21 +02:00
chore: [OCISDEV-154] Clean up the unified roles label
This commit is contained in:
8
changelog/unreleased/fix-roles-label.md
Normal file
8
changelog/unreleased/fix-roles-label.md
Normal file
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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()]
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user