Skip to content

Commit 5e1526f

Browse files
committed
More Readme Work.
1 parent effa9ae commit 5e1526f

File tree

1 file changed

+108
-4
lines changed

1 file changed

+108
-4
lines changed

README.md

Lines changed: 108 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,123 @@ In TrivialPermissions, a `permission` is a string that looks like the following:
4242

4343
This allows us to specify permissions on a per object basis. If you want to specify the permissions on an object from
4444
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.
4747

4848
#### Glob Matching
4949

5050
TrivialPermissions has special support for `*`. It can be used as either an object descriptor, or a permission descriptor.
5151
It matches any permissions passed in. If you want a user or group to have all permissions for all objects, specify
52-
`'*/**'`.
52+
`'*/*'`.
5353

5454
### Groups
5555

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+
return Promise.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.
149+
150+
### Users
151+
152+
TBD.
153+
154+
#### Setting Mapping
155+
156+
TBD.
157+
158+
#### Checking Permissions
159+
56160
TBD.
57161

58-
### Checking Permissions
162+
### Checking Group membership
59163

60164
TBD.

0 commit comments

Comments
 (0)