You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+108-4Lines changed: 108 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,19 +42,123 @@ In TrivialPermissions, a `permission` is a string that looks like the following:
42
42
43
43
This allows us to specify permissions on a per object basis. If you want to specify the permissions on an object from
44
44
the database, simply use that id as the object in the permission: `3dqZ7/somePerm`. Alternatively, you may wish to use
45
-
more generic object names, like, `'Accounting'`, or `'Posts'`, or something along those lines. TrivialPermissions does
46
-
not care, so long as you specify an object descriptor and a permission descriptor.
45
+
more generic object descriptors, like, `'Accounting'`, or `'Posts'`. TrivialPermissions does not care, so long as you
46
+
specify an object descriptor and a permission descriptor.
47
47
48
48
#### Glob Matching
49
49
50
50
TrivialPermissions has special support for `*`. It can be used as either an object descriptor, or a permission descriptor.
51
51
It matches any permissions passed in. If you want a user or group to have all permissions for all objects, specify
52
-
`'*/**'`.
52
+
`'*/*'`.
53
53
54
54
### Groups
55
55
56
+
Groups are small objects with a name and a list of permissions. TrivialPermissions requires you to define (or load) these
57
+
groups before you attempt to use them. This is generally considered part of the initial setup for TrivialPermissions. While
58
+
TrivialPermissions allows you to use your own objects for users, it requires you to pre-load your groups. Our assumption is
59
+
that you will not have more than 50 or so groups, and even if you do, loading under 1000 shouldn't be difficult for your
60
+
application.
61
+
62
+
#### Defining a Group
63
+
64
+
*`defineGroup({ name: '...', permissions: [...] })` - Returns the created group object.
65
+
66
+
Defining an individual group is very simple:
67
+
68
+
```javascript
69
+
var tp =require('../dist/trivialperms');
70
+
71
+
// Create an 'Admins' group
72
+
var admGroup =tp.defineGroup({ name:'Admins', permissions: ['*/*'] });
73
+
```
74
+
75
+
#### Loading Groups
76
+
77
+
*`loadGroups(listOrFunc)` - Returns a promise that resolves once all data has been loaded.
78
+
79
+
More usefully, you will want to load multiple groups at once. TrivialPermissions supports loading from either a list of groups, or a function that returns a promise that resolves to a list of groups. The loading function itself always returns a promise.
80
+
81
+
(Note: You _will_ need to wait until after the loading promise resolves before attempting to use the permissions system.)
82
+
83
+
```javascript
84
+
var tp =require('../dist/trivialperms');
85
+
86
+
// Load from a list
87
+
var loading =tp.loadGroups([
88
+
{
89
+
name:"Administrators",
90
+
permissions: [
91
+
"*/*"
92
+
]
93
+
},
94
+
{
95
+
name:"Authors",
96
+
permissions: [
97
+
"Posts/canView",
98
+
"Posts/canAdd",
99
+
"Posts/canEdit"
100
+
]
101
+
},
102
+
{
103
+
name:"Users",
104
+
permissions: [
105
+
"Posts/canView"
106
+
]
107
+
}
108
+
]);
109
+
110
+
loading.then(function()
111
+
{
112
+
// Do work here!
113
+
});
114
+
115
+
// Load from a function
116
+
var loading =tp.loadGroups(function()
117
+
{
118
+
returnPromise.resolve([
119
+
{
120
+
name:"Administrators",
121
+
permissions: [
122
+
"*/*"
123
+
]
124
+
},
125
+
{
126
+
name:"Authors",
127
+
permissions: [
128
+
"Posts/canView",
129
+
"Posts/canAdd",
130
+
"Posts/canEdit"
131
+
]
132
+
},
133
+
{
134
+
name:"Users",
135
+
permissions: [
136
+
"Posts/canView"
137
+
]
138
+
}
139
+
]);
140
+
});
141
+
142
+
loading.then(function()
143
+
{
144
+
// Do work here!
145
+
});
146
+
```
147
+
148
+
This should make it very easy to integrate with a database library, for example.
0 commit comments