UNPKG

1.07 kBJavaScriptView Raw
1const pluginTest = require('./utils/plugin-test')
2const RoleAcl = require('role-acl-4')
3
4// these are some sample grants that you might use for your app in regards to user rights
5const anonymous = {
6 grants: [
7 {
8 resource: 'User',
9 action: 'read',
10 attributes: ['*', '!email', '!secrethiddenfield']
11 },
12 {
13 resource: 'User',
14 action: 'create',
15 attributes: ['*', '!id']
16 }
17 ]
18}
19
20const user = {
21 grants: [
22 {
23 resource: 'User',
24 action: 'read',
25 attributes: ['*', '!email', '!secrethiddenfield']
26 },
27 {
28 resource: 'User',
29 action: 'read',
30 attributes: ['email'],
31 condition: { Fn: 'EQUALS', args: { id: '$.req.user.id' } }
32 },
33 {
34 resource: 'User',
35 action: 'update',
36 attributes: ['*', '!id'],
37 condition: { Fn: 'EQUALS', args: { id: '$.req.user.id' } }
38 },
39 {
40 resource: 'User',
41 action: 'delete',
42 condition: { Fn: 'EQUALS', args: { id: '$.req.user.id' } }
43 }
44 ]
45}
46
47pluginTest(new RoleAcl({ user, anonymous }), 'role-acl@4')