Skip to content

Commit ceeca12

Browse files
authored
Merge pull request #11241 from 2403905/issue-11025
fixed the issue when the Share roles show a wrong translation after t…
2 parents 0f235e4 + 1e28b59 commit ceeca12

File tree

6 files changed

+128
-120
lines changed

6 files changed

+128
-120
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Bugfix: Fix Share roles translation
2+
3+
We fixed the issue when the Share roles show a wrong translation after the user location has changed back to English.
4+
5+
https://github.com/owncloud/ocis/pull/11241
6+
https://github.com/owncloud/ocis/issues/11025

services/graph/pkg/unifiedrole/conversion_test.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ func TestPermissionsToCS3ResourcePermissions(t *testing.T) {
1919
unifiedRoleDefinition *libregraph.UnifiedRoleDefinition
2020
match bool
2121
}{
22-
cs3Conversions.RoleViewer: {cs3Conversions.NewViewerRole(), unifiedrole.RoleViewer, true},
23-
cs3Conversions.RoleViewerListGrants: {cs3Conversions.NewViewerListGrantsRole(), unifiedrole.RoleViewerListGrants, true},
24-
cs3Conversions.RoleEditor: {cs3Conversions.NewEditorRole(), unifiedrole.RoleEditor, true},
25-
cs3Conversions.RoleEditorListGrants: {cs3Conversions.NewEditorListGrantsRole(), unifiedrole.RoleEditorListGrants, true},
26-
cs3Conversions.RoleFileEditor: {cs3Conversions.NewFileEditorRole(), unifiedrole.RoleFileEditor, true},
27-
cs3Conversions.RoleFileEditorListGrants: {cs3Conversions.NewFileEditorListGrantsRole(), unifiedrole.RoleFileEditorListGrants, true},
28-
cs3Conversions.RoleManager: {cs3Conversions.NewManagerRole(), unifiedrole.RoleManager, true},
29-
cs3Conversions.RoleSecureViewer: {cs3Conversions.NewSecureViewerRole(), unifiedrole.RoleSecureViewer, true},
30-
cs3Conversions.RoleDenied: {cs3Conversions.NewDeniedRole(), unifiedrole.RoleDenied, true},
31-
"no match": {cs3Conversions.NewFileEditorRole(), unifiedrole.RoleManager, false},
22+
cs3Conversions.RoleViewer: {cs3Conversions.NewViewerRole(), unifiedrole.RoleViewer(), true},
23+
cs3Conversions.RoleViewerListGrants: {cs3Conversions.NewViewerListGrantsRole(), unifiedrole.RoleViewerListGrants(), true},
24+
cs3Conversions.RoleEditor: {cs3Conversions.NewEditorRole(), unifiedrole.RoleEditor(), true},
25+
cs3Conversions.RoleEditorListGrants: {cs3Conversions.NewEditorListGrantsRole(), unifiedrole.RoleEditorListGrants(), true},
26+
cs3Conversions.RoleFileEditor: {cs3Conversions.NewFileEditorRole(), unifiedrole.RoleFileEditor(), true},
27+
cs3Conversions.RoleFileEditorListGrants: {cs3Conversions.NewFileEditorListGrantsRole(), unifiedrole.RoleFileEditorListGrants(), true},
28+
cs3Conversions.RoleManager: {cs3Conversions.NewManagerRole(), unifiedrole.RoleManager(), true},
29+
cs3Conversions.RoleSecureViewer: {cs3Conversions.NewSecureViewerRole(), unifiedrole.RoleSecureViewer(), true},
30+
cs3Conversions.RoleDenied: {cs3Conversions.NewDeniedRole(), unifiedrole.RoleDenied(), true},
31+
"no match": {cs3Conversions.NewFileEditorRole(), unifiedrole.RoleManager(), false},
3232
}
3333

3434
for name, tc := range tests {
@@ -58,23 +58,23 @@ func TestCS3ResourcePermissionsToRole(t *testing.T) {
5858
unifiedRoleDefinition *libregraph.UnifiedRoleDefinition
5959
constraints string
6060
}{
61-
cs3Conversions.RoleViewer + "1": {cs3Conversions.NewViewerRole().CS3ResourcePermissions(), unifiedrole.RoleViewer, unifiedrole.UnifiedRoleConditionFile},
62-
cs3Conversions.RoleViewer + "2": {cs3Conversions.NewViewerRole().CS3ResourcePermissions(), unifiedrole.RoleViewer, unifiedrole.UnifiedRoleConditionFolder},
63-
cs3Conversions.RoleEditor: {cs3Conversions.NewEditorRole().CS3ResourcePermissions(), unifiedrole.RoleEditor, unifiedrole.UnifiedRoleConditionFolder},
64-
cs3Conversions.RoleFileEditor: {cs3Conversions.NewFileEditorRole().CS3ResourcePermissions(), unifiedrole.RoleFileEditor, unifiedrole.UnifiedRoleConditionFile},
65-
cs3Conversions.RoleManager: {cs3Conversions.NewManagerRole().CS3ResourcePermissions(), unifiedrole.RoleManager, unifiedrole.UnifiedRoleConditionDrive},
66-
cs3Conversions.RoleSpaceViewer: {cs3Conversions.NewSpaceViewerRole().CS3ResourcePermissions(), unifiedrole.RoleSpaceViewer, unifiedrole.UnifiedRoleConditionDrive},
67-
cs3Conversions.RoleSpaceEditor: {cs3Conversions.NewSpaceEditorRole().CS3ResourcePermissions(), unifiedrole.RoleSpaceEditor, unifiedrole.UnifiedRoleConditionDrive},
68-
cs3Conversions.RoleSecureViewer + "1": {cs3Conversions.NewSecureViewerRole().CS3ResourcePermissions(), unifiedrole.RoleSecureViewer, unifiedrole.UnifiedRoleConditionFile},
69-
cs3Conversions.RoleSecureViewer + "2": {cs3Conversions.NewSecureViewerRole().CS3ResourcePermissions(), unifiedrole.RoleSecureViewer, unifiedrole.UnifiedRoleConditionFolder},
70-
cs3Conversions.RoleDenied: {cs3Conversions.NewDeniedRole().CS3ResourcePermissions(), unifiedrole.RoleDenied, unifiedrole.UnifiedRoleConditionFolder},
61+
cs3Conversions.RoleViewer + "1": {cs3Conversions.NewViewerRole().CS3ResourcePermissions(), unifiedrole.RoleViewer(), unifiedrole.UnifiedRoleConditionFile},
62+
cs3Conversions.RoleViewer + "2": {cs3Conversions.NewViewerRole().CS3ResourcePermissions(), unifiedrole.RoleViewer(), unifiedrole.UnifiedRoleConditionFolder},
63+
cs3Conversions.RoleEditor: {cs3Conversions.NewEditorRole().CS3ResourcePermissions(), unifiedrole.RoleEditor(), unifiedrole.UnifiedRoleConditionFolder},
64+
cs3Conversions.RoleFileEditor: {cs3Conversions.NewFileEditorRole().CS3ResourcePermissions(), unifiedrole.RoleFileEditor(), unifiedrole.UnifiedRoleConditionFile},
65+
cs3Conversions.RoleManager: {cs3Conversions.NewManagerRole().CS3ResourcePermissions(), unifiedrole.RoleManager(), unifiedrole.UnifiedRoleConditionDrive},
66+
cs3Conversions.RoleSpaceViewer: {cs3Conversions.NewSpaceViewerRole().CS3ResourcePermissions(), unifiedrole.RoleSpaceViewer(), unifiedrole.UnifiedRoleConditionDrive},
67+
cs3Conversions.RoleSpaceEditor: {cs3Conversions.NewSpaceEditorRole().CS3ResourcePermissions(), unifiedrole.RoleSpaceEditor(), unifiedrole.UnifiedRoleConditionDrive},
68+
cs3Conversions.RoleSecureViewer + "1": {cs3Conversions.NewSecureViewerRole().CS3ResourcePermissions(), unifiedrole.RoleSecureViewer(), unifiedrole.UnifiedRoleConditionFile},
69+
cs3Conversions.RoleSecureViewer + "2": {cs3Conversions.NewSecureViewerRole().CS3ResourcePermissions(), unifiedrole.RoleSecureViewer(), unifiedrole.UnifiedRoleConditionFolder},
70+
cs3Conversions.RoleDenied: {cs3Conversions.NewDeniedRole().CS3ResourcePermissions(), unifiedrole.RoleDenied(), unifiedrole.UnifiedRoleConditionFolder},
7171
"custom 1": {&provider.ResourcePermissions{GetPath: true}, nil, unifiedrole.UnifiedRoleConditionFolder},
7272
}
7373

7474
for name, tc := range tests {
7575
t.Run(name, func(t *testing.T) {
7676
NewWithT(t).Expect(
77-
unifiedrole.CS3ResourcePermissionsToRole(unifiedrole.BuildInRoles, tc.cs3ResourcePermissions, tc.constraints, false),
77+
unifiedrole.CS3ResourcePermissionsToRole(unifiedrole.BuildInRoles(), tc.cs3ResourcePermissions, tc.constraints, false),
7878
).To(Equal(tc.unifiedRoleDefinition))
7979
})
8080
}

services/graph/pkg/unifiedrole/filter.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,30 @@ func RoleFilterIDs(ids ...string) RoleFilter {
3535

3636
// filterRoles filters the provided roles by the provided filter
3737
func filterRoles(roles []*libregraph.UnifiedRoleDefinition, f RoleFilter) []*libregraph.UnifiedRoleDefinition {
38-
return slices.DeleteFunc(
39-
slices.Clone(roles),
38+
return slices.DeleteFunc(roles,
4039
func(r *libregraph.UnifiedRoleDefinition) bool {
4140
return !f(r)
4241
},
4342
)
4443
}
44+
45+
// buildInRoles contains the built-in roles.
46+
func buildInRoles() []*libregraph.UnifiedRoleDefinition {
47+
return []*libregraph.UnifiedRoleDefinition{
48+
roleViewer(),
49+
roleViewerListGrants(),
50+
roleSpaceViewer(),
51+
roleEditor(),
52+
roleEditorListGrants(),
53+
roleEditorListGrantsWithVersions(),
54+
roleSpaceEditor(),
55+
roleSpaceEditorWithoutVersions(),
56+
roleFileEditor(),
57+
roleFileEditorListGrants(),
58+
roleFileEditorListGrantsWithVersions(),
59+
roleEditorLite(),
60+
roleManager(),
61+
roleSecureViewer(),
62+
roleDenied(),
63+
}
64+
}

services/graph/pkg/unifiedrole/filter_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func TestRoleFilterIDs(t *testing.T) {
1414
unifiedrole.RoleFilterIDs(
1515
unifiedrole.UnifiedRoleEditorLiteID,
1616
unifiedrole.UnifiedRoleSpaceEditorID,
17-
)(unifiedrole.RoleEditorLite),
17+
)(unifiedrole.RoleEditorLite()),
1818
).To(BeTrue())
1919
}
2020

@@ -24,12 +24,12 @@ func TestRoleFilterInvert(t *testing.T) {
2424
func(_ *libregraph.UnifiedRoleDefinition) bool {
2525
return true
2626
},
27-
)(unifiedrole.RoleEditorLite),
27+
)(unifiedrole.RoleEditorLite()),
2828
).To(BeFalse())
2929
}
3030

3131
func TestRoleFilterAll(t *testing.T) {
3232
NewWithT(t).Expect(
33-
unifiedrole.RoleFilterAll()(unifiedrole.RoleEditorLite),
33+
unifiedrole.RoleFilterAll()(unifiedrole.RoleEditorLite()),
3434
).To(BeTrue())
3535
}

services/graph/pkg/unifiedrole/roles.go

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -200,25 +200,6 @@ var (
200200
UnifiedRoleSecureViewerID: conversions.RoleSecureViewer,
201201
}
202202

203-
// buildInRoles contains the built-in roles.
204-
buildInRoles = []*libregraph.UnifiedRoleDefinition{
205-
roleViewer,
206-
roleViewerListGrants,
207-
roleSpaceViewer,
208-
roleEditor,
209-
roleEditorListGrants,
210-
roleEditorListGrantsWithVersions,
211-
roleSpaceEditor,
212-
roleSpaceEditorWithoutVersions,
213-
roleFileEditor,
214-
roleFileEditorListGrants,
215-
roleFileEditorListGrantsWithVersions,
216-
roleEditorLite,
217-
roleManager,
218-
roleSecureViewer,
219-
roleDenied,
220-
}
221-
222203
// roleViewer creates a viewer role.
223204
roleViewer = func() *libregraph.UnifiedRoleDefinition {
224205
r := conversions.NewViewerRole()
@@ -246,7 +227,7 @@ var (
246227
},
247228
LibreGraphWeight: proto.Int32(0),
248229
}
249-
}()
230+
}
250231

251232
// roleViewerListGrants creates a viewer role.
252233
roleViewerListGrants = func() *libregraph.UnifiedRoleDefinition {
@@ -275,7 +256,7 @@ var (
275256
},
276257
LibreGraphWeight: proto.Int32(0),
277258
}
278-
}()
259+
}
279260

280261
// roleSpaceViewer creates a spaceviewer role
281262
roleSpaceViewer = func() *libregraph.UnifiedRoleDefinition {
@@ -292,7 +273,7 @@ var (
292273
},
293274
LibreGraphWeight: proto.Int32(0),
294275
}
295-
}()
276+
}
296277

297278
// roleEditor creates an editor role.
298279
roleEditor = func() *libregraph.UnifiedRoleDefinition {
@@ -313,7 +294,7 @@ var (
313294
},
314295
LibreGraphWeight: proto.Int32(0),
315296
}
316-
}()
297+
}
317298

318299
// roleEditorListGrants creates an editor role.
319300
roleEditorListGrants = func() *libregraph.UnifiedRoleDefinition {
@@ -334,7 +315,7 @@ var (
334315
},
335316
LibreGraphWeight: proto.Int32(0),
336317
}
337-
}()
318+
}
338319

339320
// roleEditorListGrantsWithVersions creates an editor-list-grants-with-versions role.
340321
roleEditorListGrantsWithVersions = func() *libregraph.UnifiedRoleDefinition {
@@ -357,7 +338,7 @@ var (
357338
},
358339
LibreGraphWeight: proto.Int32(0),
359340
}
360-
}()
341+
}
361342

362343
// roleSpaceEditor creates an editor role
363344
roleSpaceEditor = func() *libregraph.UnifiedRoleDefinition {
@@ -374,7 +355,7 @@ var (
374355
},
375356
LibreGraphWeight: proto.Int32(0),
376357
}
377-
}()
358+
}
378359

379360
// roleSpaceEditorWithoutVersions creates an editor without versions role
380361
roleSpaceEditorWithoutVersions = func() *libregraph.UnifiedRoleDefinition {
@@ -391,7 +372,7 @@ var (
391372
},
392373
LibreGraphWeight: proto.Int32(0),
393374
}
394-
}()
375+
}
395376

396377
// roleFileEditor creates a file-editor role
397378
roleFileEditor = func() *libregraph.UnifiedRoleDefinition {
@@ -412,7 +393,7 @@ var (
412393
},
413394
LibreGraphWeight: proto.Int32(0),
414395
}
415-
}()
396+
}
416397

417398
// roleFileEditorListGrants creates a file-editor role
418399
roleFileEditorListGrants = func() *libregraph.UnifiedRoleDefinition {
@@ -433,7 +414,7 @@ var (
433414
},
434415
LibreGraphWeight: proto.Int32(0),
435416
}
436-
}()
417+
}
437418

438419
// roleFileEditorListGrantsWithVersions creates a file-editor role
439420
roleFileEditorListGrantsWithVersions = func() *libregraph.UnifiedRoleDefinition {
@@ -456,7 +437,7 @@ var (
456437
},
457438
LibreGraphWeight: proto.Int32(0),
458439
}
459-
}()
440+
}
460441

461442
// roleEditorLite creates an editor-lite role
462443
roleEditorLite = func() *libregraph.UnifiedRoleDefinition {
@@ -473,7 +454,7 @@ var (
473454
},
474455
LibreGraphWeight: proto.Int32(0),
475456
}
476-
}()
457+
}
477458

478459
// roleManager creates a manager role
479460
roleManager = func() *libregraph.UnifiedRoleDefinition {
@@ -490,7 +471,7 @@ var (
490471
},
491472
LibreGraphWeight: proto.Int32(0),
492473
}
493-
}()
474+
}
494475

495476
// roleSecureViewer creates a secure viewer role
496477
roleSecureViewer = func() *libregraph.UnifiedRoleDefinition {
@@ -511,7 +492,8 @@ var (
511492
},
512493
LibreGraphWeight: proto.Int32(0),
513494
}
514-
}()
495+
}
496+
515497
// roleDenied creates a secure viewer role
516498
roleDenied = func() *libregraph.UnifiedRoleDefinition {
517499
r := conversions.NewDeniedRole()
@@ -527,17 +509,17 @@ var (
527509
},
528510
LibreGraphWeight: proto.Int32(0),
529511
}
530-
}()
512+
}
531513
)
532514

533515
// GetRoles returns a role filter that matches the provided resources
534516
func GetRoles(f RoleFilter) []*libregraph.UnifiedRoleDefinition {
535-
return filterRoles(buildInRoles, f)
517+
return filterRoles(buildInRoles(), f)
536518
}
537519

538520
// GetRole returns a role filter that matches the provided resources
539521
func GetRole(f RoleFilter) (*libregraph.UnifiedRoleDefinition, error) {
540-
roles := filterRoles(buildInRoles, f)
522+
roles := filterRoles(buildInRoles(), f)
541523
if len(roles) == 0 {
542524
return nil, ErrUnknownRole
543525
}

0 commit comments

Comments
 (0)