Skip to content

Commit 13fa39e

Browse files
authored
Merge pull request #3 from wiegertschouten/add-super-role-and-group
Add `super` pseudo role and group
2 parents 61f73b8 + acd0d86 commit 13fa39e

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,10 @@ Use with a value in the format:
2727
### restrictRoles
2828

2929
Use with a value in the format:
30-
`restrictRoles:role_slug_1,role_slug_2`
30+
`restrictRoles:role_slug_1,role_slug_2`
31+
32+
### Including superadmins
33+
34+
You may pass `super` to the `restrictGroups` and `restrictRoles` condition methods in order to include superadmins.
35+
36+
Example: `restrictGroups:super,group_slug_1,group_slug_2`

resources/js/RestrictConditions.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ Statamic.$conditions.add('restrictUsers', function ({ target, params, store, sto
44
});
55

66
Statamic.$conditions.add('restrictGroups', function ({ target, params, store, storeName, values }) {
7-
return params.filter(value => Statamic.user.groups.includes(value)).length > 0;
7+
return (
8+
(params.includes('super') && Statamic.user.super) ||
9+
(params.filter(value => Statamic.user.groups.includes(value)).length > 0)
10+
);
811
});
912

1013
Statamic.$conditions.add('restrictRoles', function ({ target, params, store, storeName, values }) {
11-
return params.filter(value => Statamic.user.roles.includes(value)).length > 0;
12-
});
14+
return (
15+
(params.includes('super') && Statamic.user.super) ||
16+
(params.filter(value => Statamic.user.roles.includes(value)).length > 0)
17+
);
18+
});

0 commit comments

Comments
 (0)