@nymphjs/tilmeld 1.0.0-beta.120 → 1.0.0-beta.122
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/README.md +6 -3
- package/dist/Group.d.ts +5 -6
- package/dist/Group.js +83 -50
- package/dist/Group.js.map +1 -1
- package/dist/Group.testArtifacts.d.ts +3 -0
- package/dist/Group.testArtifacts.js +120 -0
- package/dist/Group.testArtifacts.js.map +1 -0
- package/dist/User.d.ts +5 -6
- package/dist/User.js +86 -84
- package/dist/User.js.map +1 -1
- package/dist/User.testArtifacts.d.ts +3 -0
- package/dist/User.testArtifacts.js +175 -0
- package/dist/User.testArtifacts.js.map +1 -0
- package/dist/decorators/index.d.ts +2 -0
- package/dist/decorators/index.js +3 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/requireAbility.d.ts +10 -0
- package/dist/decorators/requireAbility.js +21 -0
- package/dist/decorators/requireAbility.js.map +1 -0
- package/dist/decorators/requireAuthentication.d.ts +8 -0
- package/dist/decorators/requireAuthentication.js +16 -0
- package/dist/decorators/requireAuthentication.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/testArtifacts.d.ts +6 -2
- package/dist/testArtifacts.js +1254 -1101
- package/dist/testArtifacts.js.map +1 -1
- package/package.json +13 -7
- package/src/Group.testArtifacts.ts +159 -0
- package/src/Group.ts +93 -68
- package/src/User.testArtifacts.ts +226 -0
- package/src/User.ts +97 -95
- package/src/decorators/index.ts +2 -0
- package/src/decorators/requireAbility.ts +26 -0
- package/src/decorators/requireAuthentication.ts +19 -0
- package/src/index.ts +1 -0
- package/src/testArtifacts.ts +1640 -1508
- package/dist/Group.test.d.ts +0 -1
- package/dist/Group.test.js +0 -121
- package/dist/Group.test.js.map +0 -1
- package/dist/User.test.d.ts +0 -1
- package/dist/User.test.js +0 -171
- package/dist/User.test.js.map +0 -1
- package/src/Group.test.ts +0 -159
- package/src/User.test.ts +0 -217
package/src/testArtifacts.ts
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Entity,
|
|
3
3
|
Nymph,
|
|
4
|
+
HttpError,
|
|
4
5
|
TilmeldAccessLevels,
|
|
5
6
|
TilmeldAccessRequest,
|
|
6
7
|
} from '@nymphjs/nymph';
|
|
7
8
|
|
|
8
9
|
import Tilmeld from './Tilmeld.js';
|
|
10
|
+
import { requireAbility, requireAuthentication } from './decorators/index.js';
|
|
9
11
|
import { AccessControlError } from './errors/index.js';
|
|
10
12
|
import type { AccessControlData } from './Tilmeld.types.js';
|
|
11
13
|
import type UserClass from './User.js';
|
|
14
|
+
import { UserTest } from './User.testArtifacts.js';
|
|
12
15
|
import type GroupClass from './Group.js';
|
|
16
|
+
import { GroupTest } from './Group.testArtifacts.js';
|
|
13
17
|
|
|
14
18
|
export type TestModelData = {
|
|
15
19
|
name?: string;
|
|
@@ -26,6 +30,26 @@ export class TestModel extends Entity<TestModelData> {
|
|
|
26
30
|
*/
|
|
27
31
|
private $skipAcWhenDeleting = false;
|
|
28
32
|
|
|
33
|
+
@requireAuthentication
|
|
34
|
+
public $testRequireAuthenticationDecorator() {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@requireAuthentication
|
|
39
|
+
public async $testRequireAuthenticationDecoratorAsync() {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@requireAbility('test-ability')
|
|
44
|
+
public $testRequireAbilityDecorator() {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@requireAbility('test-ability')
|
|
49
|
+
public async $testRequireAbilityDecoratorAsync() {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
|
|
29
53
|
/*
|
|
30
54
|
* This should *never* be accessible on the client.
|
|
31
55
|
*/
|
|
@@ -47,6 +71,7 @@ const TestModelClass = TestModel;
|
|
|
47
71
|
|
|
48
72
|
export function TilmeldTest(
|
|
49
73
|
nymphBase: Nymph,
|
|
74
|
+
describe: (name: string, fn: () => void) => void,
|
|
50
75
|
it: (name: string, fn: () => void) => void,
|
|
51
76
|
) {
|
|
52
77
|
const tilmeld = new Tilmeld({
|
|
@@ -67,1900 +92,2007 @@ export function TilmeldTest(
|
|
|
67
92
|
});
|
|
68
93
|
const nymph = new Nymph(nymphBase.config, nymphBase.driver, tilmeld);
|
|
69
94
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
95
|
+
describe('Tilmeld', () => {
|
|
96
|
+
UserTest(nymph, tilmeld, describe, it);
|
|
97
|
+
GroupTest(nymph, tilmeld, describe, it);
|
|
98
|
+
|
|
99
|
+
const User = tilmeld.User;
|
|
100
|
+
const Group = tilmeld.Group;
|
|
101
|
+
const TestModel = nymph.addEntityClass(TestModelClass);
|
|
102
|
+
|
|
103
|
+
async function deleteTestData() {
|
|
104
|
+
let all: (TestModel | UserClass | GroupClass)[] = await nymph.getEntities(
|
|
105
|
+
{
|
|
106
|
+
class: TestModel,
|
|
107
|
+
},
|
|
108
|
+
);
|
|
109
|
+
expect(Array.isArray(all)).toEqual(true);
|
|
110
|
+
for (const cur of all) {
|
|
111
|
+
await cur.$deleteSkipAC();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
all = await nymph.getEntities({ class: TestModel });
|
|
115
|
+
expect(all.length).toEqual(0);
|
|
116
|
+
|
|
117
|
+
all = await nymph.getEntities({ class: User });
|
|
118
|
+
expect(Array.isArray(all)).toEqual(true);
|
|
119
|
+
for (const cur of all) {
|
|
120
|
+
await cur.$deleteSkipAC();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
all = await nymph.getEntities({ class: User });
|
|
124
|
+
expect(all.length).toEqual(0);
|
|
125
|
+
|
|
126
|
+
all = await nymph.getEntities({ class: Group });
|
|
127
|
+
expect(Array.isArray(all)).toEqual(true);
|
|
128
|
+
for (const cur of all) {
|
|
129
|
+
await cur.$deleteSkipAC();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
all = await nymph.getEntities({ class: Group });
|
|
133
|
+
expect(all.length).toEqual(0);
|
|
134
|
+
}
|
|
73
135
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
136
|
+
async function makeUsers() {
|
|
137
|
+
const admin = await User.factoryUsername('admin');
|
|
138
|
+
const bob = await User.factoryUsername('bob');
|
|
139
|
+
const alice = await User.factoryUsername('alice');
|
|
140
|
+
const abgroup = await Group.factoryGroupname('abgroup');
|
|
141
|
+
|
|
142
|
+
if (admin.guid == null) {
|
|
143
|
+
admin.username = 'admin';
|
|
144
|
+
admin.email = 'admin@localhost';
|
|
145
|
+
admin.nameFirst = 'Admin';
|
|
146
|
+
admin.nameLast = 'User';
|
|
147
|
+
admin.name = 'Admin User';
|
|
148
|
+
admin.$password('password');
|
|
149
|
+
admin.$grant('system/admin');
|
|
150
|
+
await admin.$saveSkipAC();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (abgroup.guid == null) {
|
|
154
|
+
abgroup.groupname = 'abgroup';
|
|
155
|
+
abgroup.email = 'abgroup@localhost';
|
|
156
|
+
abgroup.name = 'AB Group';
|
|
157
|
+
await abgroup.$saveSkipAC();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (bob.guid == null) {
|
|
161
|
+
bob.username = 'bob';
|
|
162
|
+
bob.email = 'bob@localhost';
|
|
163
|
+
bob.nameFirst = 'Bob';
|
|
164
|
+
bob.nameLast = 'User';
|
|
165
|
+
bob.name = 'Bob User';
|
|
166
|
+
bob.$password('password');
|
|
167
|
+
bob.$addGroup(abgroup);
|
|
168
|
+
await bob.$saveSkipAC();
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (alice.guid == null) {
|
|
172
|
+
alice.username = 'alice';
|
|
173
|
+
alice.email = 'alice@localhost';
|
|
174
|
+
alice.nameFirst = 'Alice';
|
|
175
|
+
alice.nameLast = 'User';
|
|
176
|
+
alice.name = 'Alice User';
|
|
177
|
+
alice.$password('password');
|
|
178
|
+
alice.$addGroup(abgroup);
|
|
179
|
+
await alice.$saveSkipAC();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return { admin, bob, alice, abgroup };
|
|
81
183
|
}
|
|
82
184
|
|
|
83
|
-
|
|
84
|
-
|
|
185
|
+
it('delete old test data', async () => {
|
|
186
|
+
await deleteTestData();
|
|
187
|
+
});
|
|
85
188
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
for (const cur of all) {
|
|
89
|
-
expect(await cur.$deleteSkipAC()).toEqual(true);
|
|
90
|
-
}
|
|
189
|
+
it('users can log in', async () => {
|
|
190
|
+
const { admin, bob, alice } = await makeUsers();
|
|
91
191
|
|
|
92
|
-
|
|
93
|
-
|
|
192
|
+
let result = await admin.$login({
|
|
193
|
+
username: 'admin',
|
|
194
|
+
password: 'password',
|
|
195
|
+
});
|
|
94
196
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
for (const cur of all) {
|
|
98
|
-
expect(await cur.$deleteSkipAC()).toEqual(true);
|
|
99
|
-
}
|
|
197
|
+
expect(result.result).toEqual(true);
|
|
198
|
+
expect(admin.$is(User.current())).toEqual(true);
|
|
100
199
|
|
|
101
|
-
|
|
102
|
-
expect(all.length).toEqual(0);
|
|
103
|
-
}
|
|
200
|
+
result = await admin.$logout();
|
|
104
201
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const bob = await User.factoryUsername('bob');
|
|
108
|
-
const alice = await User.factoryUsername('alice');
|
|
109
|
-
const abgroup = await Group.factoryGroupname('abgroup');
|
|
110
|
-
|
|
111
|
-
if (admin.guid == null) {
|
|
112
|
-
admin.username = 'admin';
|
|
113
|
-
admin.email = 'admin@localhost';
|
|
114
|
-
admin.nameFirst = 'Admin';
|
|
115
|
-
admin.nameLast = 'User';
|
|
116
|
-
admin.name = 'Admin User';
|
|
117
|
-
admin.$password('password');
|
|
118
|
-
admin.$grant('system/admin');
|
|
119
|
-
await admin.$saveSkipAC();
|
|
120
|
-
}
|
|
202
|
+
expect(result.result).toEqual(true);
|
|
203
|
+
expect(User.current()).toBeNull();
|
|
121
204
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
await abgroup.$saveSkipAC();
|
|
127
|
-
}
|
|
205
|
+
result = await bob.$login({
|
|
206
|
+
username: 'bob',
|
|
207
|
+
password: 'password',
|
|
208
|
+
});
|
|
128
209
|
|
|
129
|
-
|
|
130
|
-
bob.
|
|
131
|
-
bob.email = 'bob@localhost';
|
|
132
|
-
bob.nameFirst = 'Bob';
|
|
133
|
-
bob.nameLast = 'User';
|
|
134
|
-
bob.name = 'Bob User';
|
|
135
|
-
bob.$password('password');
|
|
136
|
-
bob.$addGroup(abgroup);
|
|
137
|
-
await bob.$saveSkipAC();
|
|
138
|
-
}
|
|
210
|
+
expect(result.result).toEqual(true);
|
|
211
|
+
expect(bob.$is(User.current())).toEqual(true);
|
|
139
212
|
|
|
140
|
-
|
|
141
|
-
alice.username = 'alice';
|
|
142
|
-
alice.email = 'alice@localhost';
|
|
143
|
-
alice.nameFirst = 'Alice';
|
|
144
|
-
alice.nameLast = 'User';
|
|
145
|
-
alice.name = 'Alice User';
|
|
146
|
-
alice.$password('password');
|
|
147
|
-
alice.$addGroup(abgroup);
|
|
148
|
-
await alice.$saveSkipAC();
|
|
149
|
-
}
|
|
213
|
+
result = await bob.$logout();
|
|
150
214
|
|
|
151
|
-
|
|
152
|
-
|
|
215
|
+
expect(result.result).toEqual(true);
|
|
216
|
+
expect(User.current()).toBeNull();
|
|
153
217
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
218
|
+
result = await alice.$login({
|
|
219
|
+
username: 'alice',
|
|
220
|
+
password: 'password',
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
expect(result.result).toEqual(true);
|
|
224
|
+
expect(alice.$is(User.current())).toEqual(true);
|
|
157
225
|
|
|
158
|
-
|
|
159
|
-
const { admin, bob, alice } = await makeUsers();
|
|
226
|
+
result = await alice.$logout();
|
|
160
227
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
password: 'password',
|
|
228
|
+
expect(result.result).toEqual(true);
|
|
229
|
+
expect(User.current()).toBeNull();
|
|
164
230
|
});
|
|
165
231
|
|
|
166
|
-
|
|
167
|
-
|
|
232
|
+
it('creates tables for test model', async () => {
|
|
233
|
+
const testEntity = await nymph.getEntity({ class: TestModel });
|
|
234
|
+
expect(testEntity).toBeNull();
|
|
235
|
+
});
|
|
168
236
|
|
|
169
|
-
|
|
237
|
+
it('user ownership, group ownership, and access controls are added on entities', async () => {
|
|
238
|
+
const { bob } = await makeUsers();
|
|
239
|
+
|
|
240
|
+
await tilmeld.fillSession(bob);
|
|
241
|
+
|
|
242
|
+
const bobsEntity = await TestModel.factory();
|
|
243
|
+
bobsEntity.name = "Bob's Entity";
|
|
244
|
+
await bobsEntity.$save();
|
|
245
|
+
|
|
246
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
247
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
248
|
+
|
|
249
|
+
const testEntityBob = await nymph.getEntity(
|
|
250
|
+
{ class: TestModel },
|
|
251
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
expect(testEntityBob).not.toBeNull();
|
|
255
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
256
|
+
expect(testEntityBob?.user?.$is(bob)).toEqual(true);
|
|
257
|
+
expect(testEntityBob?.group?.$is(bob.group)).toEqual(true);
|
|
258
|
+
expect(testEntityBob?.acUser).toEqual(TilmeldAccessLevels.FULL_ACCESS);
|
|
259
|
+
expect(testEntityBob?.acGroup).toEqual(TilmeldAccessLevels.READ_ACCESS);
|
|
260
|
+
expect(testEntityBob?.acOther).toEqual(TilmeldAccessLevels.NO_ACCESS);
|
|
261
|
+
expect(testEntityBob?.acRead).toEqual([]);
|
|
262
|
+
expect(testEntityBob?.acWrite).toEqual([]);
|
|
263
|
+
expect(testEntityBob?.acFull).toEqual([]);
|
|
264
|
+
});
|
|
170
265
|
|
|
171
|
-
|
|
172
|
-
|
|
266
|
+
it('require authentication decorator', async () => {
|
|
267
|
+
const { bob } = await makeUsers();
|
|
173
268
|
|
|
174
|
-
|
|
175
|
-
username: 'bob',
|
|
176
|
-
password: 'password',
|
|
177
|
-
});
|
|
269
|
+
await tilmeld.fillSession(bob);
|
|
178
270
|
|
|
179
|
-
|
|
180
|
-
|
|
271
|
+
const bobsEntity = await TestModel.factory();
|
|
272
|
+
bobsEntity.name = "Bob's Entity";
|
|
273
|
+
await bobsEntity.$save();
|
|
181
274
|
|
|
182
|
-
|
|
275
|
+
expect(bobsEntity.$testRequireAuthenticationDecorator()).toEqual(true);
|
|
276
|
+
expect(
|
|
277
|
+
await bobsEntity.$testRequireAuthenticationDecoratorAsync(),
|
|
278
|
+
).toEqual(true);
|
|
183
279
|
|
|
184
|
-
|
|
185
|
-
expect(User.current()).toBeNull();
|
|
280
|
+
tilmeld.clearSession();
|
|
186
281
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
282
|
+
try {
|
|
283
|
+
bobsEntity.$testRequireAuthenticationDecorator();
|
|
284
|
+
|
|
285
|
+
throw new Error('Should have thrown.');
|
|
286
|
+
} catch (e: any) {
|
|
287
|
+
expect(e).toBeInstanceOf(HttpError);
|
|
288
|
+
expect(e.status).toEqual(403);
|
|
289
|
+
expect(e.message).toEqual('Forbidden');
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
try {
|
|
293
|
+
await bobsEntity.$testRequireAuthenticationDecoratorAsync();
|
|
294
|
+
|
|
295
|
+
throw new Error('Should have thrown.');
|
|
296
|
+
} catch (e: any) {
|
|
297
|
+
expect(e).toBeInstanceOf(HttpError);
|
|
298
|
+
expect(e.status).toEqual(403);
|
|
299
|
+
expect(e.message).toEqual('Forbidden');
|
|
300
|
+
}
|
|
190
301
|
});
|
|
191
302
|
|
|
192
|
-
|
|
193
|
-
|
|
303
|
+
it('require ability decorator', async () => {
|
|
304
|
+
const { bob } = await makeUsers();
|
|
194
305
|
|
|
195
|
-
|
|
306
|
+
await tilmeld.fillSession(bob);
|
|
196
307
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
308
|
+
const bobsEntity = await TestModel.factory();
|
|
309
|
+
bobsEntity.name = "Bob's Entity";
|
|
310
|
+
await bobsEntity.$save();
|
|
200
311
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
expect(testEntity).toBeNull();
|
|
204
|
-
});
|
|
312
|
+
try {
|
|
313
|
+
bobsEntity.$testRequireAbilityDecorator();
|
|
205
314
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
bobsEntity.name = "Bob's Entity";
|
|
213
|
-
expect(await bobsEntity.$save()).toEqual(true);
|
|
214
|
-
|
|
215
|
-
expect(bobsEntity.guid).not.toBeNull();
|
|
216
|
-
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
217
|
-
|
|
218
|
-
const testEntityBob = await nymph.getEntity(
|
|
219
|
-
{ class: TestModel },
|
|
220
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
221
|
-
);
|
|
222
|
-
|
|
223
|
-
expect(testEntityBob).not.toBeNull();
|
|
224
|
-
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
225
|
-
expect(testEntityBob?.user?.$is(bob)).toEqual(true);
|
|
226
|
-
expect(testEntityBob?.group?.$is(bob.group)).toEqual(true);
|
|
227
|
-
expect(testEntityBob?.acUser).toEqual(TilmeldAccessLevels.FULL_ACCESS);
|
|
228
|
-
expect(testEntityBob?.acGroup).toEqual(TilmeldAccessLevels.READ_ACCESS);
|
|
229
|
-
expect(testEntityBob?.acOther).toEqual(TilmeldAccessLevels.NO_ACCESS);
|
|
230
|
-
expect(testEntityBob?.acRead).toEqual([]);
|
|
231
|
-
expect(testEntityBob?.acWrite).toEqual([]);
|
|
232
|
-
expect(testEntityBob?.acFull).toEqual([]);
|
|
233
|
-
});
|
|
315
|
+
throw new Error('Should have thrown.');
|
|
316
|
+
} catch (e: any) {
|
|
317
|
+
expect(e).toBeInstanceOf(HttpError);
|
|
318
|
+
expect(e.status).toEqual(403);
|
|
319
|
+
expect(e.message).toEqual('Forbidden');
|
|
320
|
+
}
|
|
234
321
|
|
|
235
|
-
|
|
236
|
-
|
|
322
|
+
try {
|
|
323
|
+
await bobsEntity.$testRequireAbilityDecoratorAsync();
|
|
237
324
|
|
|
238
|
-
|
|
325
|
+
throw new Error('Should have thrown.');
|
|
326
|
+
} catch (e: any) {
|
|
327
|
+
expect(e).toBeInstanceOf(HttpError);
|
|
328
|
+
expect(e.status).toEqual(403);
|
|
329
|
+
expect(e.message).toEqual('Forbidden');
|
|
330
|
+
}
|
|
239
331
|
|
|
240
|
-
|
|
241
|
-
bobsEntity.name = "Bob's Entity";
|
|
242
|
-
expect(await bobsEntity.$save()).toEqual(true);
|
|
332
|
+
tilmeld.clearSession();
|
|
243
333
|
|
|
244
|
-
|
|
245
|
-
|
|
334
|
+
try {
|
|
335
|
+
bobsEntity.$testRequireAbilityDecorator();
|
|
246
336
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
337
|
+
throw new Error('Should have thrown.');
|
|
338
|
+
} catch (e: any) {
|
|
339
|
+
expect(e).toBeInstanceOf(HttpError);
|
|
340
|
+
expect(e.status).toEqual(403);
|
|
341
|
+
expect(e.message).toEqual('Forbidden');
|
|
342
|
+
}
|
|
251
343
|
|
|
252
|
-
|
|
253
|
-
|
|
344
|
+
try {
|
|
345
|
+
await bobsEntity.$testRequireAbilityDecoratorAsync();
|
|
254
346
|
|
|
255
|
-
|
|
256
|
-
|
|
347
|
+
throw new Error('Should have thrown.');
|
|
348
|
+
} catch (e: any) {
|
|
349
|
+
expect(e).toBeInstanceOf(HttpError);
|
|
350
|
+
expect(e.status).toEqual(403);
|
|
351
|
+
expect(e.message).toEqual('Forbidden');
|
|
352
|
+
}
|
|
257
353
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
261
|
-
);
|
|
354
|
+
bob.$grant('test-ability');
|
|
355
|
+
await tilmeld.fillSession(bob);
|
|
262
356
|
|
|
263
|
-
|
|
264
|
-
|
|
357
|
+
expect(bobsEntity.$testRequireAbilityDecorator()).toEqual(true);
|
|
358
|
+
expect(await bobsEntity.$testRequireAbilityDecoratorAsync()).toEqual(
|
|
359
|
+
true,
|
|
360
|
+
);
|
|
361
|
+
});
|
|
265
362
|
|
|
266
|
-
|
|
267
|
-
|
|
363
|
+
it("alice can't access an entity owned by bob", async () => {
|
|
364
|
+
const { bob, alice } = await makeUsers();
|
|
268
365
|
|
|
269
|
-
|
|
366
|
+
await tilmeld.fillSession(bob);
|
|
270
367
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
expect(await bobsEntity.$save()).toEqual(true);
|
|
368
|
+
const bobsEntity = await TestModel.factory();
|
|
369
|
+
bobsEntity.name = "Bob's Entity";
|
|
370
|
+
await bobsEntity.$save();
|
|
275
371
|
|
|
276
|
-
|
|
277
|
-
|
|
372
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
373
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
278
374
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
375
|
+
const testEntityBob = await nymph.getEntity(
|
|
376
|
+
{ class: TestModel },
|
|
377
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
378
|
+
);
|
|
283
379
|
|
|
284
|
-
|
|
285
|
-
|
|
380
|
+
expect(testEntityBob).not.toBeNull();
|
|
381
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
286
382
|
|
|
287
|
-
|
|
288
|
-
|
|
383
|
+
tilmeld.clearSession();
|
|
384
|
+
await tilmeld.fillSession(alice);
|
|
289
385
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
386
|
+
const testEntityAlice = await nymph.getEntity(
|
|
387
|
+
{ class: TestModel },
|
|
388
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
389
|
+
);
|
|
294
390
|
|
|
295
|
-
|
|
296
|
-
|
|
391
|
+
expect(testEntityAlice).toBeNull();
|
|
392
|
+
});
|
|
297
393
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
394
|
+
it("alice can't write to an entity she doesn't have write permission for", async () => {
|
|
395
|
+
const { bob, alice } = await makeUsers();
|
|
301
396
|
|
|
302
|
-
|
|
303
|
-
try {
|
|
304
|
-
await testEntityAlice.$save();
|
|
305
|
-
throw new Error('It should have thrown AccessControlError.');
|
|
306
|
-
} catch (e: any) {
|
|
307
|
-
expect(e).toBeInstanceOf(AccessControlError);
|
|
308
|
-
}
|
|
397
|
+
await tilmeld.fillSession(bob);
|
|
309
398
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
399
|
+
const bobsEntity = await TestModel.factory();
|
|
400
|
+
bobsEntity.name = "Bob's Entity";
|
|
401
|
+
bobsEntity.acRead = [alice.guid ?? ''];
|
|
402
|
+
await bobsEntity.$save();
|
|
313
403
|
|
|
314
|
-
|
|
315
|
-
|
|
404
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
405
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
316
406
|
|
|
317
|
-
|
|
407
|
+
const testEntityBob = await nymph.getEntity(
|
|
408
|
+
{ class: TestModel },
|
|
409
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
410
|
+
);
|
|
318
411
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
bobsEntity.acWrite = [alice.guid ?? ''];
|
|
322
|
-
expect(await bobsEntity.$save()).toEqual(true);
|
|
412
|
+
expect(testEntityBob).not.toBeNull();
|
|
413
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
323
414
|
|
|
324
|
-
|
|
325
|
-
|
|
415
|
+
tilmeld.clearSession();
|
|
416
|
+
await tilmeld.fillSession(alice);
|
|
326
417
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
418
|
+
const testEntityAlice = await nymph.getEntity(
|
|
419
|
+
{ class: TestModel },
|
|
420
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
421
|
+
);
|
|
331
422
|
|
|
332
|
-
|
|
333
|
-
|
|
423
|
+
expect(testEntityAlice).not.toBeNull();
|
|
424
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
334
425
|
|
|
335
|
-
|
|
336
|
-
|
|
426
|
+
if (testEntityAlice == null) {
|
|
427
|
+
throw new Error();
|
|
428
|
+
}
|
|
337
429
|
|
|
338
|
-
|
|
339
|
-
{
|
|
340
|
-
|
|
341
|
-
|
|
430
|
+
testEntityAlice.name = "Haha! It's mine now!";
|
|
431
|
+
try {
|
|
432
|
+
await testEntityAlice.$save();
|
|
433
|
+
throw new Error('It should have thrown AccessControlError.');
|
|
434
|
+
} catch (e: any) {
|
|
435
|
+
expect(e).toBeInstanceOf(AccessControlError);
|
|
436
|
+
}
|
|
342
437
|
|
|
343
|
-
|
|
344
|
-
|
|
438
|
+
expect(await testEntityAlice.$refresh()).toEqual(true);
|
|
439
|
+
expect(testEntityAlice.name).toEqual("Bob's Entity");
|
|
440
|
+
});
|
|
345
441
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
}
|
|
442
|
+
it('alice can write to an entity she has write permission for', async () => {
|
|
443
|
+
const { bob, alice } = await makeUsers();
|
|
349
444
|
|
|
350
|
-
|
|
351
|
-
expect(await testEntityAlice.$save()).toEqual(true);
|
|
445
|
+
await tilmeld.fillSession(bob);
|
|
352
446
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
447
|
+
const bobsEntity = await TestModel.factory();
|
|
448
|
+
bobsEntity.name = "Bob's Entity";
|
|
449
|
+
bobsEntity.acWrite = [alice.guid ?? ''];
|
|
450
|
+
await bobsEntity.$save();
|
|
356
451
|
|
|
357
|
-
|
|
358
|
-
|
|
452
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
453
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
359
454
|
|
|
360
|
-
|
|
455
|
+
const testEntityBob = await nymph.getEntity(
|
|
456
|
+
{ class: TestModel },
|
|
457
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
458
|
+
);
|
|
361
459
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
bobsEntity.acWrite = [alice.guid ?? ''];
|
|
365
|
-
expect(await bobsEntity.$save()).toEqual(true);
|
|
460
|
+
expect(testEntityBob).not.toBeNull();
|
|
461
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
366
462
|
|
|
367
|
-
|
|
368
|
-
|
|
463
|
+
tilmeld.clearSession();
|
|
464
|
+
await tilmeld.fillSession(alice);
|
|
369
465
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
466
|
+
const testEntityAlice = await nymph.getEntity(
|
|
467
|
+
{ class: TestModel },
|
|
468
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
469
|
+
);
|
|
374
470
|
|
|
375
|
-
|
|
376
|
-
|
|
471
|
+
expect(testEntityAlice).not.toBeNull();
|
|
472
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
377
473
|
|
|
378
|
-
|
|
379
|
-
|
|
474
|
+
if (testEntityAlice == null) {
|
|
475
|
+
throw new Error();
|
|
476
|
+
}
|
|
380
477
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
384
|
-
);
|
|
478
|
+
testEntityAlice.name = "Haha! It's mine now!";
|
|
479
|
+
await testEntityAlice.$save();
|
|
385
480
|
|
|
386
|
-
|
|
387
|
-
|
|
481
|
+
expect(await testEntityAlice.$refresh()).toEqual(true);
|
|
482
|
+
expect(testEntityAlice.name).toEqual("Haha! It's mine now!");
|
|
483
|
+
});
|
|
388
484
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
}
|
|
485
|
+
it("alice can't delete an entity she doesn't have full permission for", async () => {
|
|
486
|
+
const { bob, alice } = await makeUsers();
|
|
392
487
|
|
|
393
|
-
|
|
394
|
-
await testEntityAlice.$delete();
|
|
395
|
-
throw new Error('It should have thrown AccessControlError.');
|
|
396
|
-
} catch (e: any) {
|
|
397
|
-
expect(e).toBeInstanceOf(AccessControlError);
|
|
398
|
-
}
|
|
488
|
+
await tilmeld.fillSession(bob);
|
|
399
489
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
490
|
+
const bobsEntity = await TestModel.factory();
|
|
491
|
+
bobsEntity.name = "Bob's Entity";
|
|
492
|
+
bobsEntity.acWrite = [alice.guid ?? ''];
|
|
493
|
+
await bobsEntity.$save();
|
|
403
494
|
|
|
404
|
-
|
|
405
|
-
|
|
495
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
496
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
406
497
|
|
|
407
|
-
|
|
498
|
+
const testEntityBob = await nymph.getEntity(
|
|
499
|
+
{ class: TestModel },
|
|
500
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
501
|
+
);
|
|
408
502
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
bobsEntity.acFull = [alice.guid ?? ''];
|
|
412
|
-
expect(await bobsEntity.$save()).toEqual(true);
|
|
503
|
+
expect(testEntityBob).not.toBeNull();
|
|
504
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
413
505
|
|
|
414
|
-
|
|
415
|
-
|
|
506
|
+
tilmeld.clearSession();
|
|
507
|
+
await tilmeld.fillSession(alice);
|
|
416
508
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
509
|
+
const testEntityAlice = await nymph.getEntity(
|
|
510
|
+
{ class: TestModel },
|
|
511
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
512
|
+
);
|
|
421
513
|
|
|
422
|
-
|
|
423
|
-
|
|
514
|
+
expect(testEntityAlice).not.toBeNull();
|
|
515
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
424
516
|
|
|
425
|
-
|
|
426
|
-
|
|
517
|
+
if (testEntityAlice == null) {
|
|
518
|
+
throw new Error();
|
|
519
|
+
}
|
|
427
520
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
521
|
+
try {
|
|
522
|
+
await testEntityAlice.$delete();
|
|
523
|
+
throw new Error('It should have thrown AccessControlError.');
|
|
524
|
+
} catch (e: any) {
|
|
525
|
+
expect(e).toBeInstanceOf(AccessControlError);
|
|
526
|
+
}
|
|
432
527
|
|
|
433
|
-
|
|
434
|
-
|
|
528
|
+
expect(await testEntityAlice.$refresh()).toEqual(true);
|
|
529
|
+
expect(testEntityAlice.guid).toEqual(bobsEntity.guid);
|
|
530
|
+
});
|
|
435
531
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
}
|
|
532
|
+
it('alice can delete an entity she has full permission for', async () => {
|
|
533
|
+
const { bob, alice } = await makeUsers();
|
|
439
534
|
|
|
440
|
-
|
|
441
|
-
const verifyEntityAlice = await nymph.getEntity(
|
|
442
|
-
{ class: TestModel },
|
|
443
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
444
|
-
);
|
|
445
|
-
expect(verifyEntityAlice).toBeNull();
|
|
446
|
-
});
|
|
535
|
+
await tilmeld.fillSession(bob);
|
|
447
536
|
|
|
448
|
-
|
|
449
|
-
|
|
537
|
+
const bobsEntity = await TestModel.factory();
|
|
538
|
+
bobsEntity.name = "Bob's Entity";
|
|
539
|
+
bobsEntity.acFull = [alice.guid ?? ''];
|
|
540
|
+
await bobsEntity.$save();
|
|
450
541
|
|
|
451
|
-
|
|
542
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
543
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
452
544
|
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
545
|
+
const testEntityBob = await nymph.getEntity(
|
|
546
|
+
{ class: TestModel },
|
|
547
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
548
|
+
);
|
|
457
549
|
|
|
458
|
-
|
|
459
|
-
|
|
550
|
+
expect(testEntityBob).not.toBeNull();
|
|
551
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
460
552
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
464
|
-
);
|
|
553
|
+
tilmeld.clearSession();
|
|
554
|
+
await tilmeld.fillSession(alice);
|
|
465
555
|
|
|
466
|
-
|
|
467
|
-
|
|
556
|
+
const testEntityAlice = await nymph.getEntity(
|
|
557
|
+
{ class: TestModel },
|
|
558
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
559
|
+
);
|
|
468
560
|
|
|
469
|
-
|
|
470
|
-
|
|
561
|
+
expect(testEntityAlice).not.toBeNull();
|
|
562
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
471
563
|
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
);
|
|
564
|
+
if (testEntityAlice == null) {
|
|
565
|
+
throw new Error();
|
|
566
|
+
}
|
|
476
567
|
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
568
|
+
await testEntityAlice.$delete();
|
|
569
|
+
const verifyEntityAlice = await nymph.getEntity(
|
|
570
|
+
{ class: TestModel },
|
|
571
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
572
|
+
);
|
|
573
|
+
expect(verifyEntityAlice).toBeNull();
|
|
574
|
+
});
|
|
480
575
|
|
|
481
|
-
|
|
482
|
-
|
|
576
|
+
it('alice can access an entity her group has permission for', async () => {
|
|
577
|
+
const { bob, alice, abgroup } = await makeUsers();
|
|
483
578
|
|
|
484
|
-
|
|
579
|
+
await tilmeld.fillSession(bob);
|
|
485
580
|
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
581
|
+
const bobsEntity = await TestModel.factory();
|
|
582
|
+
bobsEntity.name = "Bob's Entity";
|
|
583
|
+
bobsEntity.acRead = [abgroup.guid ?? ''];
|
|
584
|
+
await bobsEntity.$save();
|
|
490
585
|
|
|
491
|
-
|
|
492
|
-
|
|
586
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
587
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
493
588
|
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
589
|
+
const testEntityBob = await nymph.getEntity(
|
|
590
|
+
{ class: TestModel },
|
|
591
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
592
|
+
);
|
|
498
593
|
|
|
499
|
-
|
|
500
|
-
|
|
594
|
+
expect(testEntityBob).not.toBeNull();
|
|
595
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
501
596
|
|
|
502
|
-
|
|
503
|
-
|
|
597
|
+
tilmeld.clearSession();
|
|
598
|
+
await tilmeld.fillSession(alice);
|
|
504
599
|
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
600
|
+
const testEntityAlice = await nymph.getEntity(
|
|
601
|
+
{ class: TestModel },
|
|
602
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
603
|
+
);
|
|
509
604
|
|
|
510
|
-
|
|
511
|
-
|
|
605
|
+
expect(testEntityAlice).not.toBeNull();
|
|
606
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
607
|
+
});
|
|
512
608
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
}
|
|
609
|
+
it("alice can't write to an entity her group doesn't have write permission for", async () => {
|
|
610
|
+
const { bob, alice, abgroup } = await makeUsers();
|
|
516
611
|
|
|
517
|
-
|
|
518
|
-
try {
|
|
519
|
-
await testEntityAlice.$save();
|
|
520
|
-
throw new Error('It should have thrown AccessControlError.');
|
|
521
|
-
} catch (e: any) {
|
|
522
|
-
expect(e).toBeInstanceOf(AccessControlError);
|
|
523
|
-
}
|
|
612
|
+
await tilmeld.fillSession(bob);
|
|
524
613
|
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
614
|
+
const bobsEntity = await TestModel.factory();
|
|
615
|
+
bobsEntity.name = "Bob's Entity";
|
|
616
|
+
bobsEntity.acRead = [abgroup.guid ?? ''];
|
|
617
|
+
await bobsEntity.$save();
|
|
528
618
|
|
|
529
|
-
|
|
530
|
-
|
|
619
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
620
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
531
621
|
|
|
532
|
-
|
|
622
|
+
const testEntityBob = await nymph.getEntity(
|
|
623
|
+
{ class: TestModel },
|
|
624
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
625
|
+
);
|
|
533
626
|
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
bobsEntity.acWrite = [abgroup.guid ?? ''];
|
|
537
|
-
expect(await bobsEntity.$save()).toEqual(true);
|
|
627
|
+
expect(testEntityBob).not.toBeNull();
|
|
628
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
538
629
|
|
|
539
|
-
|
|
540
|
-
|
|
630
|
+
tilmeld.clearSession();
|
|
631
|
+
await tilmeld.fillSession(alice);
|
|
541
632
|
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
633
|
+
const testEntityAlice = await nymph.getEntity(
|
|
634
|
+
{ class: TestModel },
|
|
635
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
636
|
+
);
|
|
546
637
|
|
|
547
|
-
|
|
548
|
-
|
|
638
|
+
expect(testEntityAlice).not.toBeNull();
|
|
639
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
549
640
|
|
|
550
|
-
|
|
551
|
-
|
|
641
|
+
if (testEntityAlice == null) {
|
|
642
|
+
throw new Error();
|
|
643
|
+
}
|
|
552
644
|
|
|
553
|
-
|
|
554
|
-
{
|
|
555
|
-
|
|
556
|
-
|
|
645
|
+
testEntityAlice.name = "Haha! It's mine now!";
|
|
646
|
+
try {
|
|
647
|
+
await testEntityAlice.$save();
|
|
648
|
+
throw new Error('It should have thrown AccessControlError.');
|
|
649
|
+
} catch (e: any) {
|
|
650
|
+
expect(e).toBeInstanceOf(AccessControlError);
|
|
651
|
+
}
|
|
557
652
|
|
|
558
|
-
|
|
559
|
-
|
|
653
|
+
expect(await testEntityAlice.$refresh()).toEqual(true);
|
|
654
|
+
expect(testEntityAlice.name).toEqual("Bob's Entity");
|
|
655
|
+
});
|
|
560
656
|
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
}
|
|
657
|
+
it('alice can write to an entity her group has write permission for', async () => {
|
|
658
|
+
const { bob, alice, abgroup } = await makeUsers();
|
|
564
659
|
|
|
565
|
-
|
|
566
|
-
expect(await testEntityAlice.$save()).toEqual(true);
|
|
660
|
+
await tilmeld.fillSession(bob);
|
|
567
661
|
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
662
|
+
const bobsEntity = await TestModel.factory();
|
|
663
|
+
bobsEntity.name = "Bob's Entity";
|
|
664
|
+
bobsEntity.acWrite = [abgroup.guid ?? ''];
|
|
665
|
+
await bobsEntity.$save();
|
|
571
666
|
|
|
572
|
-
|
|
573
|
-
|
|
667
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
668
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
574
669
|
|
|
575
|
-
|
|
670
|
+
const testEntityBob = await nymph.getEntity(
|
|
671
|
+
{ class: TestModel },
|
|
672
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
673
|
+
);
|
|
576
674
|
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
bobsEntity.acWrite = [abgroup.guid ?? ''];
|
|
580
|
-
expect(await bobsEntity.$save()).toEqual(true);
|
|
675
|
+
expect(testEntityBob).not.toBeNull();
|
|
676
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
581
677
|
|
|
582
|
-
|
|
583
|
-
|
|
678
|
+
tilmeld.clearSession();
|
|
679
|
+
await tilmeld.fillSession(alice);
|
|
584
680
|
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
681
|
+
const testEntityAlice = await nymph.getEntity(
|
|
682
|
+
{ class: TestModel },
|
|
683
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
684
|
+
);
|
|
589
685
|
|
|
590
|
-
|
|
591
|
-
|
|
686
|
+
expect(testEntityAlice).not.toBeNull();
|
|
687
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
592
688
|
|
|
593
|
-
|
|
594
|
-
|
|
689
|
+
if (testEntityAlice == null) {
|
|
690
|
+
throw new Error();
|
|
691
|
+
}
|
|
595
692
|
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
599
|
-
);
|
|
693
|
+
testEntityAlice.name = "Haha! It's mine now!";
|
|
694
|
+
await testEntityAlice.$save();
|
|
600
695
|
|
|
601
|
-
|
|
602
|
-
|
|
696
|
+
expect(await testEntityAlice.$refresh()).toEqual(true);
|
|
697
|
+
expect(testEntityAlice.name).toEqual("Haha! It's mine now!");
|
|
698
|
+
});
|
|
603
699
|
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
}
|
|
700
|
+
it("alice can't delete an entity her group doesn't have full permission for", async () => {
|
|
701
|
+
const { bob, alice, abgroup } = await makeUsers();
|
|
607
702
|
|
|
608
|
-
|
|
609
|
-
await testEntityAlice.$delete();
|
|
610
|
-
throw new Error('It should have thrown AccessControlError.');
|
|
611
|
-
} catch (e: any) {
|
|
612
|
-
expect(e).toBeInstanceOf(AccessControlError);
|
|
613
|
-
}
|
|
703
|
+
await tilmeld.fillSession(bob);
|
|
614
704
|
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
705
|
+
const bobsEntity = await TestModel.factory();
|
|
706
|
+
bobsEntity.name = "Bob's Entity";
|
|
707
|
+
bobsEntity.acWrite = [abgroup.guid ?? ''];
|
|
708
|
+
await bobsEntity.$save();
|
|
618
709
|
|
|
619
|
-
|
|
620
|
-
|
|
710
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
711
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
621
712
|
|
|
622
|
-
|
|
713
|
+
const testEntityBob = await nymph.getEntity(
|
|
714
|
+
{ class: TestModel },
|
|
715
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
716
|
+
);
|
|
623
717
|
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
bobsEntity.acFull = [abgroup.guid ?? ''];
|
|
627
|
-
expect(await bobsEntity.$save()).toEqual(true);
|
|
718
|
+
expect(testEntityBob).not.toBeNull();
|
|
719
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
628
720
|
|
|
629
|
-
|
|
630
|
-
|
|
721
|
+
tilmeld.clearSession();
|
|
722
|
+
await tilmeld.fillSession(alice);
|
|
631
723
|
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
724
|
+
const testEntityAlice = await nymph.getEntity(
|
|
725
|
+
{ class: TestModel },
|
|
726
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
727
|
+
);
|
|
636
728
|
|
|
637
|
-
|
|
638
|
-
|
|
729
|
+
expect(testEntityAlice).not.toBeNull();
|
|
730
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
639
731
|
|
|
640
|
-
|
|
641
|
-
|
|
732
|
+
if (testEntityAlice == null) {
|
|
733
|
+
throw new Error();
|
|
734
|
+
}
|
|
642
735
|
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
736
|
+
try {
|
|
737
|
+
await testEntityAlice.$delete();
|
|
738
|
+
throw new Error('It should have thrown AccessControlError.');
|
|
739
|
+
} catch (e: any) {
|
|
740
|
+
expect(e).toBeInstanceOf(AccessControlError);
|
|
741
|
+
}
|
|
647
742
|
|
|
648
|
-
|
|
649
|
-
|
|
743
|
+
expect(await testEntityAlice.$refresh()).toEqual(true);
|
|
744
|
+
expect(testEntityAlice.guid).toEqual(bobsEntity.guid);
|
|
745
|
+
});
|
|
650
746
|
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
}
|
|
747
|
+
it('alice can delete an entity her group has full permission for', async () => {
|
|
748
|
+
const { bob, alice, abgroup } = await makeUsers();
|
|
654
749
|
|
|
655
|
-
|
|
656
|
-
const verifyEntityAlice = await nymph.getEntity(
|
|
657
|
-
{ class: TestModel },
|
|
658
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
659
|
-
);
|
|
660
|
-
expect(verifyEntityAlice).toBeNull();
|
|
661
|
-
});
|
|
750
|
+
await tilmeld.fillSession(bob);
|
|
662
751
|
|
|
663
|
-
|
|
664
|
-
|
|
752
|
+
const bobsEntity = await TestModel.factory();
|
|
753
|
+
bobsEntity.name = "Bob's Entity";
|
|
754
|
+
bobsEntity.acFull = [abgroup.guid ?? ''];
|
|
755
|
+
await bobsEntity.$save();
|
|
665
756
|
|
|
666
|
-
|
|
757
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
758
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
667
759
|
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
760
|
+
const testEntityBob = await nymph.getEntity(
|
|
761
|
+
{ class: TestModel },
|
|
762
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
763
|
+
);
|
|
672
764
|
|
|
673
|
-
|
|
674
|
-
|
|
765
|
+
expect(testEntityBob).not.toBeNull();
|
|
766
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
675
767
|
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
679
|
-
);
|
|
768
|
+
tilmeld.clearSession();
|
|
769
|
+
await tilmeld.fillSession(alice);
|
|
680
770
|
|
|
681
|
-
|
|
682
|
-
|
|
771
|
+
const testEntityAlice = await nymph.getEntity(
|
|
772
|
+
{ class: TestModel },
|
|
773
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
774
|
+
);
|
|
683
775
|
|
|
684
|
-
|
|
685
|
-
|
|
776
|
+
expect(testEntityAlice).not.toBeNull();
|
|
777
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
686
778
|
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
);
|
|
779
|
+
if (testEntityAlice == null) {
|
|
780
|
+
throw new Error();
|
|
781
|
+
}
|
|
691
782
|
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
783
|
+
await testEntityAlice.$delete();
|
|
784
|
+
const verifyEntityAlice = await nymph.getEntity(
|
|
785
|
+
{ class: TestModel },
|
|
786
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
787
|
+
);
|
|
788
|
+
expect(verifyEntityAlice).toBeNull();
|
|
789
|
+
});
|
|
695
790
|
|
|
696
|
-
|
|
697
|
-
|
|
791
|
+
it('alice can access an entity her primary group has permission for', async () => {
|
|
792
|
+
const { bob, alice } = await makeUsers();
|
|
698
793
|
|
|
699
|
-
|
|
794
|
+
await tilmeld.fillSession(bob);
|
|
700
795
|
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
796
|
+
const bobsEntity = await TestModel.factory();
|
|
797
|
+
bobsEntity.name = "Bob's Entity";
|
|
798
|
+
bobsEntity.group = alice.group;
|
|
799
|
+
await bobsEntity.$save();
|
|
705
800
|
|
|
706
|
-
|
|
707
|
-
|
|
801
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
802
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
708
803
|
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
804
|
+
const testEntityBob = await nymph.getEntity(
|
|
805
|
+
{ class: TestModel },
|
|
806
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
807
|
+
);
|
|
713
808
|
|
|
714
|
-
|
|
715
|
-
|
|
809
|
+
expect(testEntityBob).not.toBeNull();
|
|
810
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
716
811
|
|
|
717
|
-
|
|
718
|
-
|
|
812
|
+
tilmeld.clearSession();
|
|
813
|
+
await tilmeld.fillSession(alice);
|
|
719
814
|
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
815
|
+
const testEntityAlice = await nymph.getEntity(
|
|
816
|
+
{ class: TestModel },
|
|
817
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
818
|
+
);
|
|
724
819
|
|
|
725
|
-
|
|
726
|
-
|
|
820
|
+
expect(testEntityAlice).not.toBeNull();
|
|
821
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
822
|
+
});
|
|
727
823
|
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
}
|
|
824
|
+
it("alice can't write to an entity her primary group doesn't have write permission for", async () => {
|
|
825
|
+
const { bob, alice } = await makeUsers();
|
|
731
826
|
|
|
732
|
-
|
|
733
|
-
try {
|
|
734
|
-
await testEntityAlice.$save();
|
|
735
|
-
throw new Error('It should have thrown AccessControlError.');
|
|
736
|
-
} catch (e: any) {
|
|
737
|
-
expect(e).toBeInstanceOf(AccessControlError);
|
|
738
|
-
}
|
|
827
|
+
await tilmeld.fillSession(bob);
|
|
739
828
|
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
829
|
+
const bobsEntity = await TestModel.factory();
|
|
830
|
+
bobsEntity.name = "Bob's Entity";
|
|
831
|
+
bobsEntity.group = alice.group;
|
|
832
|
+
await bobsEntity.$save();
|
|
743
833
|
|
|
744
|
-
|
|
745
|
-
|
|
834
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
835
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
746
836
|
|
|
747
|
-
|
|
837
|
+
const testEntityBob = await nymph.getEntity(
|
|
838
|
+
{ class: TestModel },
|
|
839
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
840
|
+
);
|
|
748
841
|
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
bobsEntity.group = alice.group;
|
|
752
|
-
bobsEntity.acGroup = TilmeldAccessLevels.WRITE_ACCESS;
|
|
753
|
-
expect(await bobsEntity.$save()).toEqual(true);
|
|
842
|
+
expect(testEntityBob).not.toBeNull();
|
|
843
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
754
844
|
|
|
755
|
-
|
|
756
|
-
|
|
845
|
+
tilmeld.clearSession();
|
|
846
|
+
await tilmeld.fillSession(alice);
|
|
757
847
|
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
848
|
+
const testEntityAlice = await nymph.getEntity(
|
|
849
|
+
{ class: TestModel },
|
|
850
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
851
|
+
);
|
|
762
852
|
|
|
763
|
-
|
|
764
|
-
|
|
853
|
+
expect(testEntityAlice).not.toBeNull();
|
|
854
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
765
855
|
|
|
766
|
-
|
|
767
|
-
|
|
856
|
+
if (testEntityAlice == null) {
|
|
857
|
+
throw new Error();
|
|
858
|
+
}
|
|
768
859
|
|
|
769
|
-
|
|
770
|
-
{
|
|
771
|
-
|
|
772
|
-
|
|
860
|
+
testEntityAlice.name = "Haha! It's mine now!";
|
|
861
|
+
try {
|
|
862
|
+
await testEntityAlice.$save();
|
|
863
|
+
throw new Error('It should have thrown AccessControlError.');
|
|
864
|
+
} catch (e: any) {
|
|
865
|
+
expect(e).toBeInstanceOf(AccessControlError);
|
|
866
|
+
}
|
|
773
867
|
|
|
774
|
-
|
|
775
|
-
|
|
868
|
+
expect(await testEntityAlice.$refresh()).toEqual(true);
|
|
869
|
+
expect(testEntityAlice.name).toEqual("Bob's Entity");
|
|
870
|
+
});
|
|
776
871
|
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
}
|
|
872
|
+
it('alice can write to an entity her primary group has write permission for', async () => {
|
|
873
|
+
const { bob, alice } = await makeUsers();
|
|
780
874
|
|
|
781
|
-
|
|
782
|
-
expect(await testEntityAlice.$save()).toEqual(true);
|
|
875
|
+
await tilmeld.fillSession(bob);
|
|
783
876
|
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
877
|
+
const bobsEntity = await TestModel.factory();
|
|
878
|
+
bobsEntity.name = "Bob's Entity";
|
|
879
|
+
bobsEntity.group = alice.group;
|
|
880
|
+
bobsEntity.acGroup = TilmeldAccessLevels.WRITE_ACCESS;
|
|
881
|
+
await bobsEntity.$save();
|
|
787
882
|
|
|
788
|
-
|
|
789
|
-
|
|
883
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
884
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
790
885
|
|
|
791
|
-
|
|
886
|
+
const testEntityBob = await nymph.getEntity(
|
|
887
|
+
{ class: TestModel },
|
|
888
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
889
|
+
);
|
|
792
890
|
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
bobsEntity.group = alice.group;
|
|
796
|
-
bobsEntity.acGroup = TilmeldAccessLevels.WRITE_ACCESS;
|
|
797
|
-
expect(await bobsEntity.$save()).toEqual(true);
|
|
891
|
+
expect(testEntityBob).not.toBeNull();
|
|
892
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
798
893
|
|
|
799
|
-
|
|
800
|
-
|
|
894
|
+
tilmeld.clearSession();
|
|
895
|
+
await tilmeld.fillSession(alice);
|
|
801
896
|
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
897
|
+
const testEntityAlice = await nymph.getEntity(
|
|
898
|
+
{ class: TestModel },
|
|
899
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
900
|
+
);
|
|
806
901
|
|
|
807
|
-
|
|
808
|
-
|
|
902
|
+
expect(testEntityAlice).not.toBeNull();
|
|
903
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
809
904
|
|
|
810
|
-
|
|
811
|
-
|
|
905
|
+
if (testEntityAlice == null) {
|
|
906
|
+
throw new Error();
|
|
907
|
+
}
|
|
812
908
|
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
816
|
-
);
|
|
909
|
+
testEntityAlice.name = "Haha! It's mine now!";
|
|
910
|
+
await testEntityAlice.$save();
|
|
817
911
|
|
|
818
|
-
|
|
819
|
-
|
|
912
|
+
expect(await testEntityAlice.$refresh()).toEqual(true);
|
|
913
|
+
expect(testEntityAlice.name).toEqual("Haha! It's mine now!");
|
|
914
|
+
});
|
|
820
915
|
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
}
|
|
916
|
+
it("alice can't delete an entity her primary group doesn't have full permission for", async () => {
|
|
917
|
+
const { bob, alice } = await makeUsers();
|
|
824
918
|
|
|
825
|
-
|
|
826
|
-
await testEntityAlice.$delete();
|
|
827
|
-
throw new Error('It should have thrown AccessControlError.');
|
|
828
|
-
} catch (e: any) {
|
|
829
|
-
expect(e).toBeInstanceOf(AccessControlError);
|
|
830
|
-
}
|
|
919
|
+
await tilmeld.fillSession(bob);
|
|
831
920
|
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
921
|
+
const bobsEntity = await TestModel.factory();
|
|
922
|
+
bobsEntity.name = "Bob's Entity";
|
|
923
|
+
bobsEntity.group = alice.group;
|
|
924
|
+
bobsEntity.acGroup = TilmeldAccessLevels.WRITE_ACCESS;
|
|
925
|
+
await bobsEntity.$save();
|
|
835
926
|
|
|
836
|
-
|
|
837
|
-
|
|
927
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
928
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
838
929
|
|
|
839
|
-
|
|
930
|
+
const testEntityBob = await nymph.getEntity(
|
|
931
|
+
{ class: TestModel },
|
|
932
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
933
|
+
);
|
|
840
934
|
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
bobsEntity.group = alice.group;
|
|
844
|
-
bobsEntity.acGroup = TilmeldAccessLevels.FULL_ACCESS;
|
|
845
|
-
expect(await bobsEntity.$save()).toEqual(true);
|
|
935
|
+
expect(testEntityBob).not.toBeNull();
|
|
936
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
846
937
|
|
|
847
|
-
|
|
848
|
-
|
|
938
|
+
tilmeld.clearSession();
|
|
939
|
+
await tilmeld.fillSession(alice);
|
|
849
940
|
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
941
|
+
const testEntityAlice = await nymph.getEntity(
|
|
942
|
+
{ class: TestModel },
|
|
943
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
944
|
+
);
|
|
854
945
|
|
|
855
|
-
|
|
856
|
-
|
|
946
|
+
expect(testEntityAlice).not.toBeNull();
|
|
947
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
857
948
|
|
|
858
|
-
|
|
859
|
-
|
|
949
|
+
if (testEntityAlice == null) {
|
|
950
|
+
throw new Error();
|
|
951
|
+
}
|
|
860
952
|
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
953
|
+
try {
|
|
954
|
+
await testEntityAlice.$delete();
|
|
955
|
+
throw new Error('It should have thrown AccessControlError.');
|
|
956
|
+
} catch (e: any) {
|
|
957
|
+
expect(e).toBeInstanceOf(AccessControlError);
|
|
958
|
+
}
|
|
865
959
|
|
|
866
|
-
|
|
867
|
-
|
|
960
|
+
expect(await testEntityAlice.$refresh()).toEqual(true);
|
|
961
|
+
expect(testEntityAlice.guid).toEqual(bobsEntity.guid);
|
|
962
|
+
});
|
|
868
963
|
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
}
|
|
964
|
+
it('alice can delete an entity her primary group has full permission for', async () => {
|
|
965
|
+
const { bob, alice } = await makeUsers();
|
|
872
966
|
|
|
873
|
-
|
|
874
|
-
const verifyEntityAlice = await nymph.getEntity(
|
|
875
|
-
{ class: TestModel },
|
|
876
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
877
|
-
);
|
|
878
|
-
expect(verifyEntityAlice).toBeNull();
|
|
879
|
-
});
|
|
967
|
+
await tilmeld.fillSession(bob);
|
|
880
968
|
|
|
881
|
-
|
|
882
|
-
|
|
969
|
+
const bobsEntity = await TestModel.factory();
|
|
970
|
+
bobsEntity.name = "Bob's Entity";
|
|
971
|
+
bobsEntity.group = alice.group;
|
|
972
|
+
bobsEntity.acGroup = TilmeldAccessLevels.FULL_ACCESS;
|
|
973
|
+
await bobsEntity.$save();
|
|
883
974
|
|
|
884
|
-
|
|
975
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
976
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
885
977
|
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
978
|
+
const testEntityBob = await nymph.getEntity(
|
|
979
|
+
{ class: TestModel },
|
|
980
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
981
|
+
);
|
|
890
982
|
|
|
891
|
-
|
|
892
|
-
|
|
983
|
+
expect(testEntityBob).not.toBeNull();
|
|
984
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
893
985
|
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
897
|
-
);
|
|
986
|
+
tilmeld.clearSession();
|
|
987
|
+
await tilmeld.fillSession(alice);
|
|
898
988
|
|
|
899
|
-
|
|
900
|
-
|
|
989
|
+
const testEntityAlice = await nymph.getEntity(
|
|
990
|
+
{ class: TestModel },
|
|
991
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
992
|
+
);
|
|
901
993
|
|
|
902
|
-
|
|
903
|
-
|
|
994
|
+
expect(testEntityAlice).not.toBeNull();
|
|
995
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
904
996
|
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
);
|
|
997
|
+
if (testEntityAlice == null) {
|
|
998
|
+
throw new Error();
|
|
999
|
+
}
|
|
909
1000
|
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
1001
|
+
await testEntityAlice.$delete();
|
|
1002
|
+
const verifyEntityAlice = await nymph.getEntity(
|
|
1003
|
+
{ class: TestModel },
|
|
1004
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1005
|
+
);
|
|
1006
|
+
expect(verifyEntityAlice).toBeNull();
|
|
1007
|
+
});
|
|
913
1008
|
|
|
914
|
-
|
|
915
|
-
|
|
1009
|
+
it('alice can access an entity everyone has permission for', async () => {
|
|
1010
|
+
const { bob, alice } = await makeUsers();
|
|
916
1011
|
|
|
917
|
-
|
|
1012
|
+
await tilmeld.fillSession(bob);
|
|
918
1013
|
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
1014
|
+
const bobsEntity = await TestModel.factory();
|
|
1015
|
+
bobsEntity.name = "Bob's Entity";
|
|
1016
|
+
bobsEntity.acOther = TilmeldAccessLevels.READ_ACCESS;
|
|
1017
|
+
await bobsEntity.$save();
|
|
923
1018
|
|
|
924
|
-
|
|
925
|
-
|
|
1019
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
1020
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
926
1021
|
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
1022
|
+
const testEntityBob = await nymph.getEntity(
|
|
1023
|
+
{ class: TestModel },
|
|
1024
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1025
|
+
);
|
|
931
1026
|
|
|
932
|
-
|
|
933
|
-
|
|
1027
|
+
expect(testEntityBob).not.toBeNull();
|
|
1028
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
934
1029
|
|
|
935
|
-
|
|
936
|
-
|
|
1030
|
+
tilmeld.clearSession();
|
|
1031
|
+
await tilmeld.fillSession(alice);
|
|
937
1032
|
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
1033
|
+
const testEntityAlice = await nymph.getEntity(
|
|
1034
|
+
{ class: TestModel },
|
|
1035
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1036
|
+
);
|
|
942
1037
|
|
|
943
|
-
|
|
944
|
-
|
|
1038
|
+
expect(testEntityAlice).not.toBeNull();
|
|
1039
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
1040
|
+
});
|
|
945
1041
|
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
}
|
|
1042
|
+
it("alice can't write to an entity everyone doesn't have write permission for", async () => {
|
|
1043
|
+
const { bob, alice } = await makeUsers();
|
|
949
1044
|
|
|
950
|
-
|
|
951
|
-
try {
|
|
952
|
-
await testEntityAlice.$save();
|
|
953
|
-
throw new Error('It should have thrown AccessControlError.');
|
|
954
|
-
} catch (e: any) {
|
|
955
|
-
expect(e).toBeInstanceOf(AccessControlError);
|
|
956
|
-
}
|
|
1045
|
+
await tilmeld.fillSession(bob);
|
|
957
1046
|
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
1047
|
+
const bobsEntity = await TestModel.factory();
|
|
1048
|
+
bobsEntity.name = "Bob's Entity";
|
|
1049
|
+
bobsEntity.acOther = TilmeldAccessLevels.READ_ACCESS;
|
|
1050
|
+
await bobsEntity.$save();
|
|
961
1051
|
|
|
962
|
-
|
|
963
|
-
|
|
1052
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
1053
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
964
1054
|
|
|
965
|
-
|
|
1055
|
+
const testEntityBob = await nymph.getEntity(
|
|
1056
|
+
{ class: TestModel },
|
|
1057
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1058
|
+
);
|
|
966
1059
|
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
bobsEntity.acOther = TilmeldAccessLevels.WRITE_ACCESS;
|
|
970
|
-
expect(await bobsEntity.$save()).toEqual(true);
|
|
1060
|
+
expect(testEntityBob).not.toBeNull();
|
|
1061
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
971
1062
|
|
|
972
|
-
|
|
973
|
-
|
|
1063
|
+
tilmeld.clearSession();
|
|
1064
|
+
await tilmeld.fillSession(alice);
|
|
974
1065
|
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
1066
|
+
const testEntityAlice = await nymph.getEntity(
|
|
1067
|
+
{ class: TestModel },
|
|
1068
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1069
|
+
);
|
|
979
1070
|
|
|
980
|
-
|
|
981
|
-
|
|
1071
|
+
expect(testEntityAlice).not.toBeNull();
|
|
1072
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
982
1073
|
|
|
983
|
-
|
|
984
|
-
|
|
1074
|
+
if (testEntityAlice == null) {
|
|
1075
|
+
throw new Error();
|
|
1076
|
+
}
|
|
985
1077
|
|
|
986
|
-
|
|
987
|
-
{
|
|
988
|
-
|
|
989
|
-
|
|
1078
|
+
testEntityAlice.name = "Haha! It's mine now!";
|
|
1079
|
+
try {
|
|
1080
|
+
await testEntityAlice.$save();
|
|
1081
|
+
throw new Error('It should have thrown AccessControlError.');
|
|
1082
|
+
} catch (e: any) {
|
|
1083
|
+
expect(e).toBeInstanceOf(AccessControlError);
|
|
1084
|
+
}
|
|
990
1085
|
|
|
991
|
-
|
|
992
|
-
|
|
1086
|
+
expect(await testEntityAlice.$refresh()).toEqual(true);
|
|
1087
|
+
expect(testEntityAlice.name).toEqual("Bob's Entity");
|
|
1088
|
+
});
|
|
993
1089
|
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
}
|
|
1090
|
+
it('alice can write to an entity everyone has write permission for', async () => {
|
|
1091
|
+
const { bob, alice } = await makeUsers();
|
|
997
1092
|
|
|
998
|
-
|
|
999
|
-
expect(await testEntityAlice.$save()).toEqual(true);
|
|
1093
|
+
await tilmeld.fillSession(bob);
|
|
1000
1094
|
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1095
|
+
const bobsEntity = await TestModel.factory();
|
|
1096
|
+
bobsEntity.name = "Bob's Entity";
|
|
1097
|
+
bobsEntity.acOther = TilmeldAccessLevels.WRITE_ACCESS;
|
|
1098
|
+
await bobsEntity.$save();
|
|
1004
1099
|
|
|
1005
|
-
|
|
1006
|
-
|
|
1100
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
1101
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
1007
1102
|
|
|
1008
|
-
|
|
1103
|
+
const testEntityBob = await nymph.getEntity(
|
|
1104
|
+
{ class: TestModel },
|
|
1105
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1106
|
+
);
|
|
1009
1107
|
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
bobsEntity.acOther = TilmeldAccessLevels.WRITE_ACCESS;
|
|
1013
|
-
expect(await bobsEntity.$save()).toEqual(true);
|
|
1108
|
+
expect(testEntityBob).not.toBeNull();
|
|
1109
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
1014
1110
|
|
|
1015
|
-
|
|
1016
|
-
|
|
1111
|
+
tilmeld.clearSession();
|
|
1112
|
+
await tilmeld.fillSession(alice);
|
|
1017
1113
|
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1114
|
+
const testEntityAlice = await nymph.getEntity(
|
|
1115
|
+
{ class: TestModel },
|
|
1116
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1117
|
+
);
|
|
1022
1118
|
|
|
1023
|
-
|
|
1024
|
-
|
|
1119
|
+
expect(testEntityAlice).not.toBeNull();
|
|
1120
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
1025
1121
|
|
|
1026
|
-
|
|
1027
|
-
|
|
1122
|
+
if (testEntityAlice == null) {
|
|
1123
|
+
throw new Error();
|
|
1124
|
+
}
|
|
1028
1125
|
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1032
|
-
);
|
|
1126
|
+
testEntityAlice.name = "Haha! It's mine now!";
|
|
1127
|
+
await testEntityAlice.$save();
|
|
1033
1128
|
|
|
1034
|
-
|
|
1035
|
-
|
|
1129
|
+
expect(await testEntityAlice.$refresh()).toEqual(true);
|
|
1130
|
+
expect(testEntityAlice.name).toEqual("Haha! It's mine now!");
|
|
1131
|
+
});
|
|
1036
1132
|
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
}
|
|
1133
|
+
it("alice can't delete an entity everyone doesn't have full permission for", async () => {
|
|
1134
|
+
const { bob, alice } = await makeUsers();
|
|
1040
1135
|
|
|
1041
|
-
|
|
1042
|
-
await testEntityAlice.$delete();
|
|
1043
|
-
throw new Error('It should have thrown AccessControlError.');
|
|
1044
|
-
} catch (e: any) {
|
|
1045
|
-
expect(e).toBeInstanceOf(AccessControlError);
|
|
1046
|
-
}
|
|
1136
|
+
await tilmeld.fillSession(bob);
|
|
1047
1137
|
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1138
|
+
const bobsEntity = await TestModel.factory();
|
|
1139
|
+
bobsEntity.name = "Bob's Entity";
|
|
1140
|
+
bobsEntity.acOther = TilmeldAccessLevels.WRITE_ACCESS;
|
|
1141
|
+
await bobsEntity.$save();
|
|
1051
1142
|
|
|
1052
|
-
|
|
1053
|
-
|
|
1143
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
1144
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
1054
1145
|
|
|
1055
|
-
|
|
1146
|
+
const testEntityBob = await nymph.getEntity(
|
|
1147
|
+
{ class: TestModel },
|
|
1148
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1149
|
+
);
|
|
1056
1150
|
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
bobsEntity.acOther = TilmeldAccessLevels.FULL_ACCESS;
|
|
1060
|
-
expect(await bobsEntity.$save()).toEqual(true);
|
|
1151
|
+
expect(testEntityBob).not.toBeNull();
|
|
1152
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
1061
1153
|
|
|
1062
|
-
|
|
1063
|
-
|
|
1154
|
+
tilmeld.clearSession();
|
|
1155
|
+
await tilmeld.fillSession(alice);
|
|
1064
1156
|
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1157
|
+
const testEntityAlice = await nymph.getEntity(
|
|
1158
|
+
{ class: TestModel },
|
|
1159
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1160
|
+
);
|
|
1069
1161
|
|
|
1070
|
-
|
|
1071
|
-
|
|
1162
|
+
expect(testEntityAlice).not.toBeNull();
|
|
1163
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
1072
1164
|
|
|
1073
|
-
|
|
1074
|
-
|
|
1165
|
+
if (testEntityAlice == null) {
|
|
1166
|
+
throw new Error();
|
|
1167
|
+
}
|
|
1075
1168
|
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1169
|
+
try {
|
|
1170
|
+
await testEntityAlice.$delete();
|
|
1171
|
+
throw new Error('It should have thrown AccessControlError.');
|
|
1172
|
+
} catch (e: any) {
|
|
1173
|
+
expect(e).toBeInstanceOf(AccessControlError);
|
|
1174
|
+
}
|
|
1080
1175
|
|
|
1081
|
-
|
|
1082
|
-
|
|
1176
|
+
expect(await testEntityAlice.$refresh()).toEqual(true);
|
|
1177
|
+
expect(testEntityAlice.guid).toEqual(bobsEntity.guid);
|
|
1178
|
+
});
|
|
1083
1179
|
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
}
|
|
1180
|
+
it('alice can delete an entity everyone has full permission for', async () => {
|
|
1181
|
+
const { bob, alice } = await makeUsers();
|
|
1087
1182
|
|
|
1088
|
-
|
|
1089
|
-
const verifyEntityAlice = await nymph.getEntity(
|
|
1090
|
-
{ class: TestModel },
|
|
1091
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1092
|
-
);
|
|
1093
|
-
expect(verifyEntityAlice).toBeNull();
|
|
1094
|
-
});
|
|
1183
|
+
await tilmeld.fillSession(bob);
|
|
1095
1184
|
|
|
1096
|
-
|
|
1097
|
-
|
|
1185
|
+
const bobsEntity = await TestModel.factory();
|
|
1186
|
+
bobsEntity.name = "Bob's Entity";
|
|
1187
|
+
bobsEntity.acOther = TilmeldAccessLevels.FULL_ACCESS;
|
|
1188
|
+
await bobsEntity.$save();
|
|
1098
1189
|
|
|
1099
|
-
|
|
1190
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
1191
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
1100
1192
|
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1193
|
+
const testEntityBob = await nymph.getEntity(
|
|
1194
|
+
{ class: TestModel },
|
|
1195
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1196
|
+
);
|
|
1105
1197
|
|
|
1106
|
-
|
|
1107
|
-
|
|
1198
|
+
expect(testEntityBob).not.toBeNull();
|
|
1199
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
1108
1200
|
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1112
|
-
);
|
|
1201
|
+
tilmeld.clearSession();
|
|
1202
|
+
await tilmeld.fillSession(alice);
|
|
1113
1203
|
|
|
1114
|
-
|
|
1115
|
-
|
|
1204
|
+
const testEntityAlice = await nymph.getEntity(
|
|
1205
|
+
{ class: TestModel },
|
|
1206
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1207
|
+
);
|
|
1116
1208
|
|
|
1117
|
-
|
|
1209
|
+
expect(testEntityAlice).not.toBeNull();
|
|
1210
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
1118
1211
|
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
);
|
|
1212
|
+
if (testEntityAlice == null) {
|
|
1213
|
+
throw new Error();
|
|
1214
|
+
}
|
|
1123
1215
|
|
|
1124
|
-
|
|
1125
|
-
|
|
1216
|
+
await testEntityAlice.$delete();
|
|
1217
|
+
const verifyEntityAlice = await nymph.getEntity(
|
|
1218
|
+
{ class: TestModel },
|
|
1219
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1220
|
+
);
|
|
1221
|
+
expect(verifyEntityAlice).toBeNull();
|
|
1222
|
+
});
|
|
1126
1223
|
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
}
|
|
1224
|
+
it('a clear session can delete an entity everyone has full permission for', async () => {
|
|
1225
|
+
const { bob } = await makeUsers();
|
|
1130
1226
|
|
|
1131
|
-
|
|
1132
|
-
const verifyEntityNobody = await nymph.getEntity(
|
|
1133
|
-
{ class: TestModel },
|
|
1134
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1135
|
-
);
|
|
1136
|
-
expect(verifyEntityNobody).toBeNull();
|
|
1137
|
-
});
|
|
1227
|
+
await tilmeld.fillSession(bob);
|
|
1138
1228
|
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1229
|
+
const bobsEntity = await TestModel.factory();
|
|
1230
|
+
bobsEntity.name = "Bob's Entity";
|
|
1231
|
+
bobsEntity.acOther = TilmeldAccessLevels.FULL_ACCESS;
|
|
1232
|
+
await bobsEntity.$save();
|
|
1233
|
+
|
|
1234
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
1235
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
1236
|
+
|
|
1237
|
+
const testEntityBob = await nymph.getEntity(
|
|
1238
|
+
{ class: TestModel },
|
|
1239
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1240
|
+
);
|
|
1241
|
+
|
|
1242
|
+
expect(testEntityBob).not.toBeNull();
|
|
1243
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
1244
|
+
|
|
1245
|
+
tilmeld.clearSession();
|
|
1246
|
+
|
|
1247
|
+
const testEntityNobody = await nymph.getEntity(
|
|
1248
|
+
{ class: TestModel },
|
|
1249
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1250
|
+
);
|
|
1251
|
+
|
|
1252
|
+
expect(testEntityNobody).not.toBeNull();
|
|
1253
|
+
expect(testEntityNobody?.guid).toEqual(bobsEntity.guid);
|
|
1254
|
+
|
|
1255
|
+
if (testEntityNobody == null) {
|
|
1256
|
+
throw new Error();
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
await testEntityNobody.$delete();
|
|
1260
|
+
const verifyEntityNobody = await nymph.getEntity(
|
|
1261
|
+
{ class: TestModel },
|
|
1262
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1263
|
+
);
|
|
1264
|
+
expect(verifyEntityNobody).toBeNull();
|
|
1265
|
+
});
|
|
1149
1266
|
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1267
|
+
it('allows skip ac deletions', async () => {
|
|
1268
|
+
const allEntities = [
|
|
1269
|
+
...(await nymph.getEntities({ class: TestModel, skipAc: true })),
|
|
1270
|
+
...(await nymph.getEntities({ class: User, skipAc: true })),
|
|
1271
|
+
...(await nymph.getEntities({ class: Group, skipAc: true })),
|
|
1272
|
+
];
|
|
1273
|
+
for (let entity of allEntities) {
|
|
1274
|
+
await entity.$deleteSkipAC();
|
|
1275
|
+
}
|
|
1276
|
+
});
|
|
1277
|
+
|
|
1278
|
+
it('entity can be retrieved by queries on ac properties', async () => {
|
|
1279
|
+
const { bob, alice } = await makeUsers();
|
|
1280
|
+
|
|
1281
|
+
await tilmeld.fillSession(bob);
|
|
1282
|
+
|
|
1283
|
+
const bobsEntity = await TestModel.factory();
|
|
1284
|
+
bobsEntity.name = "Bob's Entity";
|
|
1285
|
+
bobsEntity.acRead = [
|
|
1286
|
+
alice.guid ?? '',
|
|
1287
|
+
bob.guid ?? '',
|
|
1288
|
+
...(bob.group ? [bob.group.guid ?? ''] : []),
|
|
1289
|
+
];
|
|
1290
|
+
bobsEntity.acWrite = [alice.guid ?? '', bob.guid ?? ''];
|
|
1291
|
+
bobsEntity.acFull = [bob.guid ?? ''];
|
|
1292
|
+
await bobsEntity.$save();
|
|
1293
|
+
|
|
1294
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
1295
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
1296
|
+
|
|
1297
|
+
const testEntityBob = await nymph.getEntity(
|
|
1298
|
+
{ class: TestModel },
|
|
1299
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1300
|
+
);
|
|
1301
|
+
|
|
1302
|
+
expect(testEntityBob).not.toBeNull();
|
|
1303
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
1304
|
+
|
|
1305
|
+
tilmeld.clearSession();
|
|
1306
|
+
await tilmeld.fillSession(alice);
|
|
1307
|
+
|
|
1308
|
+
// Equals queries.
|
|
1309
|
+
|
|
1310
|
+
let testEntityAlice = await nymph.getEntity(
|
|
1311
|
+
{ class: TestModel },
|
|
1312
|
+
{
|
|
1313
|
+
type: '&',
|
|
1314
|
+
guid: bobsEntity.guid || '',
|
|
1315
|
+
equal: ['user', bob.guid],
|
|
1316
|
+
},
|
|
1317
|
+
);
|
|
1318
|
+
|
|
1319
|
+
expect(testEntityAlice).not.toBeNull();
|
|
1320
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
1321
|
+
|
|
1322
|
+
testEntityAlice = await nymph.getEntity(
|
|
1323
|
+
{ class: TestModel },
|
|
1324
|
+
{
|
|
1325
|
+
type: '&',
|
|
1326
|
+
guid: bobsEntity.guid || '',
|
|
1327
|
+
equal: ['user', '000000000000000000000000'],
|
|
1328
|
+
},
|
|
1329
|
+
);
|
|
1330
|
+
|
|
1331
|
+
expect(testEntityAlice).toBeNull();
|
|
1332
|
+
|
|
1333
|
+
testEntityAlice = await nymph.getEntity(
|
|
1334
|
+
{ class: TestModel },
|
|
1335
|
+
{
|
|
1336
|
+
type: '&',
|
|
1337
|
+
guid: bobsEntity.guid || '',
|
|
1338
|
+
equal: ['group', bob.group?.guid],
|
|
1339
|
+
},
|
|
1340
|
+
);
|
|
1341
|
+
|
|
1342
|
+
expect(testEntityAlice).not.toBeNull();
|
|
1343
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
1344
|
+
|
|
1345
|
+
testEntityAlice = await nymph.getEntity(
|
|
1346
|
+
{ class: TestModel },
|
|
1347
|
+
{
|
|
1348
|
+
type: '&',
|
|
1349
|
+
guid: bobsEntity.guid || '',
|
|
1350
|
+
equal: ['group', '000000000000000000000000'],
|
|
1351
|
+
},
|
|
1352
|
+
);
|
|
1353
|
+
|
|
1354
|
+
expect(testEntityAlice).toBeNull();
|
|
1355
|
+
|
|
1356
|
+
// Contains queries.
|
|
1357
|
+
|
|
1358
|
+
testEntityAlice = await nymph.getEntity(
|
|
1359
|
+
{ class: TestModel },
|
|
1360
|
+
{
|
|
1361
|
+
type: '&',
|
|
1362
|
+
guid: bobsEntity.guid || '',
|
|
1363
|
+
contain: ['user', bob.guid],
|
|
1364
|
+
},
|
|
1365
|
+
);
|
|
1366
|
+
|
|
1367
|
+
expect(testEntityAlice).not.toBeNull();
|
|
1368
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
1369
|
+
|
|
1370
|
+
testEntityAlice = await nymph.getEntity(
|
|
1371
|
+
{ class: TestModel },
|
|
1372
|
+
{
|
|
1373
|
+
type: '&',
|
|
1374
|
+
guid: bobsEntity.guid || '',
|
|
1375
|
+
contain: ['user', '000000000000000000000000'],
|
|
1376
|
+
},
|
|
1377
|
+
);
|
|
1378
|
+
|
|
1379
|
+
expect(testEntityAlice).toBeNull();
|
|
1380
|
+
|
|
1381
|
+
testEntityAlice = await nymph.getEntity(
|
|
1382
|
+
{ class: TestModel },
|
|
1383
|
+
{
|
|
1384
|
+
type: '&',
|
|
1385
|
+
guid: bobsEntity.guid || '',
|
|
1386
|
+
contain: ['group', bob.group?.guid],
|
|
1387
|
+
},
|
|
1388
|
+
);
|
|
1389
|
+
|
|
1390
|
+
expect(testEntityAlice).not.toBeNull();
|
|
1391
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
1392
|
+
|
|
1393
|
+
testEntityAlice = await nymph.getEntity(
|
|
1394
|
+
{ class: TestModel },
|
|
1395
|
+
{
|
|
1396
|
+
type: '&',
|
|
1397
|
+
guid: bobsEntity.guid || '',
|
|
1398
|
+
contain: ['group', '000000000000000000000000'],
|
|
1399
|
+
},
|
|
1400
|
+
);
|
|
1401
|
+
|
|
1402
|
+
expect(testEntityAlice).toBeNull();
|
|
1403
|
+
|
|
1404
|
+
testEntityAlice = await nymph.getEntity(
|
|
1405
|
+
{ class: TestModel },
|
|
1406
|
+
{
|
|
1407
|
+
type: '&',
|
|
1408
|
+
guid: bobsEntity.guid || '',
|
|
1409
|
+
contain: ['acRead', alice.guid],
|
|
1410
|
+
},
|
|
1411
|
+
);
|
|
1412
|
+
|
|
1413
|
+
expect(testEntityAlice).not.toBeNull();
|
|
1414
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
1415
|
+
|
|
1416
|
+
testEntityAlice = await nymph.getEntity(
|
|
1417
|
+
{ class: TestModel },
|
|
1418
|
+
{
|
|
1419
|
+
type: '&',
|
|
1420
|
+
guid: bobsEntity.guid || '',
|
|
1421
|
+
contain: ['acRead', '000000000000000000000000'],
|
|
1422
|
+
},
|
|
1423
|
+
);
|
|
1424
|
+
|
|
1425
|
+
expect(testEntityAlice).toBeNull();
|
|
1426
|
+
|
|
1427
|
+
testEntityAlice = await nymph.getEntity(
|
|
1428
|
+
{ class: TestModel },
|
|
1429
|
+
{
|
|
1430
|
+
type: '&',
|
|
1431
|
+
guid: bobsEntity.guid || '',
|
|
1432
|
+
contain: ['acWrite', bob.guid],
|
|
1433
|
+
},
|
|
1434
|
+
);
|
|
1435
|
+
|
|
1436
|
+
expect(testEntityAlice).not.toBeNull();
|
|
1437
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
1438
|
+
|
|
1439
|
+
testEntityAlice = await nymph.getEntity(
|
|
1440
|
+
{ class: TestModel },
|
|
1441
|
+
{
|
|
1442
|
+
type: '&',
|
|
1443
|
+
guid: bobsEntity.guid || '',
|
|
1444
|
+
contain: ['acWrite', '000000000000000000000000'],
|
|
1445
|
+
},
|
|
1446
|
+
);
|
|
1447
|
+
|
|
1448
|
+
expect(testEntityAlice).toBeNull();
|
|
1449
|
+
|
|
1450
|
+
testEntityAlice = await nymph.getEntity(
|
|
1451
|
+
{ class: TestModel },
|
|
1452
|
+
{
|
|
1453
|
+
type: '&',
|
|
1454
|
+
guid: bobsEntity.guid || '',
|
|
1455
|
+
contain: ['acFull', bob.guid],
|
|
1456
|
+
},
|
|
1457
|
+
);
|
|
1458
|
+
|
|
1459
|
+
expect(testEntityAlice).not.toBeNull();
|
|
1460
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
1461
|
+
|
|
1462
|
+
testEntityAlice = await nymph.getEntity(
|
|
1463
|
+
{ class: TestModel },
|
|
1464
|
+
{
|
|
1465
|
+
type: '&',
|
|
1466
|
+
guid: bobsEntity.guid || '',
|
|
1467
|
+
contain: ['acFull', '000000000000000000000000'],
|
|
1468
|
+
},
|
|
1469
|
+
);
|
|
1470
|
+
|
|
1471
|
+
expect(testEntityAlice).toBeNull();
|
|
1472
|
+
|
|
1473
|
+
// Ref queries.
|
|
1474
|
+
|
|
1475
|
+
testEntityAlice = await nymph.getEntity(
|
|
1476
|
+
{ class: TestModel },
|
|
1477
|
+
{
|
|
1478
|
+
type: '&',
|
|
1479
|
+
guid: bobsEntity.guid || '',
|
|
1480
|
+
ref: ['user', bob],
|
|
1481
|
+
},
|
|
1482
|
+
);
|
|
1483
|
+
|
|
1484
|
+
expect(testEntityAlice).not.toBeNull();
|
|
1485
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
1486
|
+
|
|
1487
|
+
testEntityAlice = await nymph.getEntity(
|
|
1488
|
+
{ class: TestModel },
|
|
1489
|
+
{
|
|
1490
|
+
type: '&',
|
|
1491
|
+
guid: bobsEntity.guid || '',
|
|
1492
|
+
ref: ['user', '000000000000000000000000'],
|
|
1493
|
+
},
|
|
1494
|
+
);
|
|
1495
|
+
|
|
1496
|
+
expect(testEntityAlice).toBeNull();
|
|
1497
|
+
|
|
1498
|
+
testEntityAlice = await nymph.getEntity(
|
|
1499
|
+
{ class: TestModel },
|
|
1500
|
+
{
|
|
1501
|
+
type: '&',
|
|
1502
|
+
guid: bobsEntity.guid || '',
|
|
1503
|
+
ref: ['group', bob.group ?? ''],
|
|
1504
|
+
},
|
|
1505
|
+
);
|
|
1506
|
+
|
|
1507
|
+
expect(testEntityAlice).not.toBeNull();
|
|
1508
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
1509
|
+
|
|
1510
|
+
testEntityAlice = await nymph.getEntity(
|
|
1511
|
+
{ class: TestModel },
|
|
1512
|
+
{
|
|
1513
|
+
type: '&',
|
|
1514
|
+
guid: bobsEntity.guid || '',
|
|
1515
|
+
ref: ['group', '000000000000000000000000'],
|
|
1516
|
+
},
|
|
1517
|
+
);
|
|
1518
|
+
|
|
1519
|
+
expect(testEntityAlice).toBeNull();
|
|
1520
|
+
|
|
1521
|
+
testEntityAlice = await nymph.getEntity(
|
|
1522
|
+
{ class: TestModel },
|
|
1523
|
+
{
|
|
1524
|
+
type: '&',
|
|
1525
|
+
guid: bobsEntity.guid || '',
|
|
1526
|
+
ref: ['acRead', alice],
|
|
1527
|
+
},
|
|
1528
|
+
);
|
|
1529
|
+
|
|
1530
|
+
expect(testEntityAlice).not.toBeNull();
|
|
1531
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
1532
|
+
|
|
1533
|
+
testEntityAlice = await nymph.getEntity(
|
|
1534
|
+
{ class: TestModel },
|
|
1535
|
+
{
|
|
1536
|
+
type: '&',
|
|
1537
|
+
guid: bobsEntity.guid || '',
|
|
1538
|
+
ref: ['acRead', '000000000000000000000000'],
|
|
1539
|
+
},
|
|
1540
|
+
);
|
|
1541
|
+
|
|
1542
|
+
expect(testEntityAlice).toBeNull();
|
|
1543
|
+
|
|
1544
|
+
testEntityAlice = await nymph.getEntity(
|
|
1545
|
+
{ class: TestModel },
|
|
1546
|
+
{
|
|
1547
|
+
type: '&',
|
|
1548
|
+
guid: bobsEntity.guid || '',
|
|
1549
|
+
ref: ['acWrite', bob],
|
|
1550
|
+
},
|
|
1551
|
+
);
|
|
1552
|
+
|
|
1553
|
+
expect(testEntityAlice).not.toBeNull();
|
|
1554
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
1555
|
+
|
|
1556
|
+
testEntityAlice = await nymph.getEntity(
|
|
1557
|
+
{ class: TestModel },
|
|
1558
|
+
{
|
|
1559
|
+
type: '&',
|
|
1560
|
+
guid: bobsEntity.guid || '',
|
|
1561
|
+
ref: ['acWrite', '000000000000000000000000'],
|
|
1562
|
+
},
|
|
1563
|
+
);
|
|
1564
|
+
|
|
1565
|
+
expect(testEntityAlice).toBeNull();
|
|
1566
|
+
|
|
1567
|
+
testEntityAlice = await nymph.getEntity(
|
|
1568
|
+
{ class: TestModel },
|
|
1569
|
+
{
|
|
1570
|
+
type: '&',
|
|
1571
|
+
guid: bobsEntity.guid || '',
|
|
1572
|
+
ref: ['acFull', bob],
|
|
1573
|
+
},
|
|
1574
|
+
);
|
|
1575
|
+
|
|
1576
|
+
expect(testEntityAlice).not.toBeNull();
|
|
1577
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
1578
|
+
|
|
1579
|
+
testEntityAlice = await nymph.getEntity(
|
|
1580
|
+
{ class: TestModel },
|
|
1581
|
+
{
|
|
1582
|
+
type: '&',
|
|
1583
|
+
guid: bobsEntity.guid || '',
|
|
1584
|
+
ref: ['acFull', '000000000000000000000000'],
|
|
1585
|
+
},
|
|
1586
|
+
);
|
|
1587
|
+
|
|
1588
|
+
expect(testEntityAlice).toBeNull();
|
|
1589
|
+
|
|
1590
|
+
// QRef queries.
|
|
1591
|
+
|
|
1592
|
+
testEntityAlice = await nymph.getEntity(
|
|
1593
|
+
{ class: TestModel },
|
|
1594
|
+
{
|
|
1595
|
+
type: '&',
|
|
1596
|
+
guid: bobsEntity.guid || '',
|
|
1597
|
+
qref: [
|
|
1598
|
+
'user',
|
|
1599
|
+
[
|
|
1600
|
+
{ class: User },
|
|
1601
|
+
{ type: '&', equal: ['username', bob.username ?? ''] },
|
|
1602
|
+
],
|
|
1474
1603
|
],
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
[{ class: User }, { type: '&', equal: ['username', 'pickle'] }],
|
|
1490
|
-
],
|
|
1491
|
-
},
|
|
1492
|
-
);
|
|
1493
|
-
|
|
1494
|
-
expect(testEntityAlice).toBeNull();
|
|
1495
|
-
|
|
1496
|
-
testEntityAlice = await nymph.getEntity(
|
|
1497
|
-
{ class: TestModel },
|
|
1498
|
-
{
|
|
1499
|
-
type: '&',
|
|
1500
|
-
guid: bobsEntity.guid || '',
|
|
1501
|
-
qref: [
|
|
1502
|
-
'acRead',
|
|
1503
|
-
[
|
|
1504
|
-
{ class: User },
|
|
1505
|
-
{ type: '&', equal: ['username', alice.username ?? ''] },
|
|
1604
|
+
},
|
|
1605
|
+
);
|
|
1606
|
+
|
|
1607
|
+
expect(testEntityAlice).not.toBeNull();
|
|
1608
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
1609
|
+
|
|
1610
|
+
testEntityAlice = await nymph.getEntity(
|
|
1611
|
+
{ class: TestModel },
|
|
1612
|
+
{
|
|
1613
|
+
type: '&',
|
|
1614
|
+
guid: bobsEntity.guid || '',
|
|
1615
|
+
qref: [
|
|
1616
|
+
'user',
|
|
1617
|
+
[{ class: User }, { type: '&', equal: ['username', 'pickle'] }],
|
|
1506
1618
|
],
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1619
|
+
},
|
|
1620
|
+
);
|
|
1621
|
+
|
|
1622
|
+
expect(testEntityAlice).toBeNull();
|
|
1623
|
+
|
|
1624
|
+
testEntityAlice = await nymph.getEntity(
|
|
1625
|
+
{ class: TestModel },
|
|
1626
|
+
{
|
|
1627
|
+
type: '&',
|
|
1628
|
+
guid: bobsEntity.guid || '',
|
|
1629
|
+
qref: [
|
|
1630
|
+
'acRead',
|
|
1631
|
+
[
|
|
1632
|
+
{ class: User },
|
|
1633
|
+
{ type: '&', equal: ['username', alice.username ?? ''] },
|
|
1634
|
+
],
|
|
1635
|
+
],
|
|
1636
|
+
},
|
|
1637
|
+
);
|
|
1638
|
+
|
|
1639
|
+
expect(testEntityAlice).not.toBeNull();
|
|
1640
|
+
expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
|
|
1641
|
+
|
|
1642
|
+
testEntityAlice = await nymph.getEntity(
|
|
1643
|
+
{ class: TestModel },
|
|
1644
|
+
{
|
|
1645
|
+
type: '&',
|
|
1646
|
+
guid: bobsEntity.guid || '',
|
|
1647
|
+
qref: [
|
|
1648
|
+
'acRead',
|
|
1649
|
+
[{ class: User }, { type: '&', equal: ['username', 'pickle'] }],
|
|
1650
|
+
],
|
|
1651
|
+
},
|
|
1652
|
+
);
|
|
1528
1653
|
|
|
1529
|
-
|
|
1530
|
-
|
|
1654
|
+
expect(testEntityAlice).toBeNull();
|
|
1655
|
+
});
|
|
1531
1656
|
|
|
1532
|
-
|
|
1657
|
+
it('alice can access an entity with an access request', async () => {
|
|
1658
|
+
const { bob, alice } = await makeUsers();
|
|
1533
1659
|
|
|
1534
|
-
|
|
1535
|
-
alicesEntity.name = "Alice's Entity";
|
|
1536
|
-
expect(await alicesEntity.$save()).toEqual(true);
|
|
1660
|
+
await tilmeld.fillSession(alice);
|
|
1537
1661
|
|
|
1538
|
-
|
|
1539
|
-
|
|
1662
|
+
const alicesEntity = await TestModel.factory();
|
|
1663
|
+
alicesEntity.name = "Alice's Entity";
|
|
1664
|
+
await alicesEntity.$save();
|
|
1540
1665
|
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
{ type: '&', guid: alicesEntity.guid || '' },
|
|
1544
|
-
);
|
|
1666
|
+
expect(alicesEntity.guid).not.toBeNull();
|
|
1667
|
+
expect(alice.$is(alicesEntity.user)).toEqual(true);
|
|
1545
1668
|
|
|
1546
|
-
|
|
1547
|
-
|
|
1669
|
+
const testEntityAlice = await nymph.getEntity(
|
|
1670
|
+
{ class: TestModel, acRequest: TilmeldAccessRequest.USER_OWNED },
|
|
1671
|
+
{ type: '&', guid: alicesEntity.guid || '' },
|
|
1672
|
+
);
|
|
1548
1673
|
|
|
1549
|
-
|
|
1550
|
-
|
|
1674
|
+
expect(testEntityAlice).not.toBeNull();
|
|
1675
|
+
expect(testEntityAlice?.guid).toEqual(alicesEntity.guid);
|
|
1551
1676
|
|
|
1552
|
-
|
|
1553
|
-
|
|
1677
|
+
tilmeld.clearSession();
|
|
1678
|
+
});
|
|
1554
1679
|
|
|
1555
|
-
|
|
1680
|
+
it("access request for user owned doesn't return group owned entity", async () => {
|
|
1681
|
+
const { bob, alice } = await makeUsers();
|
|
1556
1682
|
|
|
1557
|
-
|
|
1558
|
-
bobsEntity.name = "Bob's Entity";
|
|
1559
|
-
bobsEntity.group = alice.group;
|
|
1560
|
-
expect(await bobsEntity.$save()).toEqual(true);
|
|
1683
|
+
await tilmeld.fillSession(bob);
|
|
1561
1684
|
|
|
1562
|
-
|
|
1563
|
-
|
|
1685
|
+
const bobsEntity = await TestModel.factory();
|
|
1686
|
+
bobsEntity.name = "Bob's Entity";
|
|
1687
|
+
bobsEntity.group = alice.group;
|
|
1688
|
+
await bobsEntity.$save();
|
|
1564
1689
|
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1568
|
-
);
|
|
1690
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
1691
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
1569
1692
|
|
|
1570
|
-
|
|
1571
|
-
|
|
1693
|
+
const testEntityBob = await nymph.getEntity(
|
|
1694
|
+
{ class: TestModel },
|
|
1695
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1696
|
+
);
|
|
1572
1697
|
|
|
1573
|
-
|
|
1574
|
-
|
|
1698
|
+
expect(testEntityBob).not.toBeNull();
|
|
1699
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
1575
1700
|
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1579
|
-
);
|
|
1701
|
+
tilmeld.clearSession();
|
|
1702
|
+
await tilmeld.fillSession(alice);
|
|
1580
1703
|
|
|
1581
|
-
|
|
1704
|
+
const testEntityAlice = await nymph.getEntity(
|
|
1705
|
+
{ class: TestModel },
|
|
1706
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1707
|
+
);
|
|
1582
1708
|
|
|
1583
|
-
|
|
1584
|
-
{ class: TestModel, acRequest: TilmeldAccessRequest.USER_OWNED },
|
|
1585
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1586
|
-
);
|
|
1709
|
+
expect(testEntityAlice).not.toBeNull();
|
|
1587
1710
|
|
|
1588
|
-
|
|
1711
|
+
const testFailureEntityAlice = await nymph.getEntity(
|
|
1712
|
+
{ class: TestModel, acRequest: TilmeldAccessRequest.USER_OWNED },
|
|
1713
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1714
|
+
);
|
|
1589
1715
|
|
|
1590
|
-
|
|
1591
|
-
{ class: TestModel, acRequest: TilmeldAccessRequest.PRIMARY_GROUP_OWNED },
|
|
1592
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1593
|
-
);
|
|
1716
|
+
expect(testFailureEntityAlice).toBeNull();
|
|
1594
1717
|
|
|
1595
|
-
|
|
1596
|
-
|
|
1718
|
+
const testSuccessEntityAlice = await nymph.getEntity(
|
|
1719
|
+
{
|
|
1720
|
+
class: TestModel,
|
|
1721
|
+
acRequest: TilmeldAccessRequest.PRIMARY_GROUP_OWNED,
|
|
1722
|
+
},
|
|
1723
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1724
|
+
);
|
|
1597
1725
|
|
|
1598
|
-
|
|
1599
|
-
|
|
1726
|
+
expect(testSuccessEntityAlice).not.toBeNull();
|
|
1727
|
+
});
|
|
1600
1728
|
|
|
1601
|
-
|
|
1729
|
+
it("access request for user owned doesn't return acOther accessible entity", async () => {
|
|
1730
|
+
const { bob, alice } = await makeUsers();
|
|
1602
1731
|
|
|
1603
|
-
|
|
1604
|
-
bobsEntity.name = "Bob's Entity";
|
|
1605
|
-
bobsEntity.acOther = TilmeldAccessLevels.READ_ACCESS;
|
|
1606
|
-
expect(await bobsEntity.$save()).toEqual(true);
|
|
1732
|
+
await tilmeld.fillSession(bob);
|
|
1607
1733
|
|
|
1608
|
-
|
|
1609
|
-
|
|
1734
|
+
const bobsEntity = await TestModel.factory();
|
|
1735
|
+
bobsEntity.name = "Bob's Entity";
|
|
1736
|
+
bobsEntity.acOther = TilmeldAccessLevels.READ_ACCESS;
|
|
1737
|
+
await bobsEntity.$save();
|
|
1610
1738
|
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1614
|
-
);
|
|
1739
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
1740
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
1615
1741
|
|
|
1616
|
-
|
|
1617
|
-
|
|
1742
|
+
const testEntityBob = await nymph.getEntity(
|
|
1743
|
+
{ class: TestModel },
|
|
1744
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1745
|
+
);
|
|
1618
1746
|
|
|
1619
|
-
|
|
1620
|
-
|
|
1747
|
+
expect(testEntityBob).not.toBeNull();
|
|
1748
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
1621
1749
|
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1625
|
-
);
|
|
1750
|
+
tilmeld.clearSession();
|
|
1751
|
+
await tilmeld.fillSession(alice);
|
|
1626
1752
|
|
|
1627
|
-
|
|
1753
|
+
const testEntityAlice = await nymph.getEntity(
|
|
1754
|
+
{ class: TestModel },
|
|
1755
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1756
|
+
);
|
|
1628
1757
|
|
|
1629
|
-
|
|
1630
|
-
{ class: TestModel, acRequest: TilmeldAccessRequest.USER_OWNED },
|
|
1631
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1632
|
-
);
|
|
1758
|
+
expect(testEntityAlice).not.toBeNull();
|
|
1633
1759
|
|
|
1634
|
-
|
|
1760
|
+
const testFailureEntityAlice = await nymph.getEntity(
|
|
1761
|
+
{ class: TestModel, acRequest: TilmeldAccessRequest.USER_OWNED },
|
|
1762
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1763
|
+
);
|
|
1635
1764
|
|
|
1636
|
-
|
|
1637
|
-
{ class: TestModel, acRequest: TilmeldAccessRequest.OTHER_ACCESSIBLE },
|
|
1638
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1639
|
-
);
|
|
1765
|
+
expect(testFailureEntityAlice).toBeNull();
|
|
1640
1766
|
|
|
1641
|
-
|
|
1642
|
-
|
|
1767
|
+
const testSuccessEntityAlice = await nymph.getEntity(
|
|
1768
|
+
{ class: TestModel, acRequest: TilmeldAccessRequest.OTHER_ACCESSIBLE },
|
|
1769
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1770
|
+
);
|
|
1643
1771
|
|
|
1644
|
-
|
|
1645
|
-
|
|
1772
|
+
expect(testSuccessEntityAlice).not.toBeNull();
|
|
1773
|
+
});
|
|
1646
1774
|
|
|
1647
|
-
|
|
1775
|
+
it("access request for user owned doesn't return user acRead accessible entity", async () => {
|
|
1776
|
+
const { bob, alice } = await makeUsers();
|
|
1648
1777
|
|
|
1649
|
-
|
|
1650
|
-
bobsEntity.name = "Bob's Entity";
|
|
1651
|
-
bobsEntity.acRead = [alice.guid ?? ''];
|
|
1652
|
-
expect(await bobsEntity.$save()).toEqual(true);
|
|
1778
|
+
await tilmeld.fillSession(bob);
|
|
1653
1779
|
|
|
1654
|
-
|
|
1655
|
-
|
|
1780
|
+
const bobsEntity = await TestModel.factory();
|
|
1781
|
+
bobsEntity.name = "Bob's Entity";
|
|
1782
|
+
bobsEntity.acRead = [alice.guid ?? ''];
|
|
1783
|
+
await bobsEntity.$save();
|
|
1656
1784
|
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1660
|
-
);
|
|
1785
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
1786
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
1661
1787
|
|
|
1662
|
-
|
|
1663
|
-
|
|
1788
|
+
const testEntityBob = await nymph.getEntity(
|
|
1789
|
+
{ class: TestModel },
|
|
1790
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1791
|
+
);
|
|
1664
1792
|
|
|
1665
|
-
|
|
1666
|
-
|
|
1793
|
+
expect(testEntityBob).not.toBeNull();
|
|
1794
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
1667
1795
|
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1671
|
-
);
|
|
1796
|
+
tilmeld.clearSession();
|
|
1797
|
+
await tilmeld.fillSession(alice);
|
|
1672
1798
|
|
|
1673
|
-
|
|
1799
|
+
const testEntityAlice = await nymph.getEntity(
|
|
1800
|
+
{ class: TestModel },
|
|
1801
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1802
|
+
);
|
|
1674
1803
|
|
|
1675
|
-
|
|
1676
|
-
{ class: TestModel, acRequest: TilmeldAccessRequest.USER_OWNED },
|
|
1677
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1678
|
-
);
|
|
1804
|
+
expect(testEntityAlice).not.toBeNull();
|
|
1679
1805
|
|
|
1680
|
-
|
|
1806
|
+
const testFailureEntityAlice = await nymph.getEntity(
|
|
1807
|
+
{ class: TestModel, acRequest: TilmeldAccessRequest.USER_OWNED },
|
|
1808
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1809
|
+
);
|
|
1681
1810
|
|
|
1682
|
-
|
|
1683
|
-
{ class: TestModel, acRequest: TilmeldAccessRequest.USER_ACCESSIBLE },
|
|
1684
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1685
|
-
);
|
|
1811
|
+
expect(testFailureEntityAlice).toBeNull();
|
|
1686
1812
|
|
|
1687
|
-
|
|
1688
|
-
|
|
1813
|
+
const testSuccessEntityAlice = await nymph.getEntity(
|
|
1814
|
+
{ class: TestModel, acRequest: TilmeldAccessRequest.USER_ACCESSIBLE },
|
|
1815
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1816
|
+
);
|
|
1689
1817
|
|
|
1690
|
-
|
|
1691
|
-
|
|
1818
|
+
expect(testSuccessEntityAlice).not.toBeNull();
|
|
1819
|
+
});
|
|
1692
1820
|
|
|
1693
|
-
|
|
1821
|
+
it("access request for user owned doesn't return group acRead accessible entity", async () => {
|
|
1822
|
+
const { bob, alice } = await makeUsers();
|
|
1694
1823
|
|
|
1695
|
-
|
|
1696
|
-
bobsEntity.name = "Bob's Entity";
|
|
1697
|
-
bobsEntity.acWrite = [alice.group?.guid ?? ''];
|
|
1698
|
-
expect(await bobsEntity.$save()).toEqual(true);
|
|
1824
|
+
await tilmeld.fillSession(bob);
|
|
1699
1825
|
|
|
1700
|
-
|
|
1701
|
-
|
|
1826
|
+
const bobsEntity = await TestModel.factory();
|
|
1827
|
+
bobsEntity.name = "Bob's Entity";
|
|
1828
|
+
bobsEntity.acWrite = [alice.group?.guid ?? ''];
|
|
1829
|
+
await bobsEntity.$save();
|
|
1702
1830
|
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1706
|
-
);
|
|
1831
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
1832
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
1707
1833
|
|
|
1708
|
-
|
|
1709
|
-
|
|
1834
|
+
const testEntityBob = await nymph.getEntity(
|
|
1835
|
+
{ class: TestModel },
|
|
1836
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1837
|
+
);
|
|
1710
1838
|
|
|
1711
|
-
|
|
1712
|
-
|
|
1839
|
+
expect(testEntityBob).not.toBeNull();
|
|
1840
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
1713
1841
|
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1717
|
-
);
|
|
1842
|
+
tilmeld.clearSession();
|
|
1843
|
+
await tilmeld.fillSession(alice);
|
|
1718
1844
|
|
|
1719
|
-
|
|
1845
|
+
const testEntityAlice = await nymph.getEntity(
|
|
1846
|
+
{ class: TestModel },
|
|
1847
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1848
|
+
);
|
|
1720
1849
|
|
|
1721
|
-
|
|
1722
|
-
{ class: TestModel, acRequest: TilmeldAccessRequest.USER_OWNED },
|
|
1723
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1724
|
-
);
|
|
1850
|
+
expect(testEntityAlice).not.toBeNull();
|
|
1725
1851
|
|
|
1726
|
-
|
|
1852
|
+
const testFailureEntityAlice = await nymph.getEntity(
|
|
1853
|
+
{ class: TestModel, acRequest: TilmeldAccessRequest.USER_OWNED },
|
|
1854
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1855
|
+
);
|
|
1727
1856
|
|
|
1728
|
-
|
|
1729
|
-
{
|
|
1730
|
-
class: TestModel,
|
|
1731
|
-
acRequest: TilmeldAccessRequest.PRIMARY_GROUP_ACCESSIBLE,
|
|
1732
|
-
},
|
|
1733
|
-
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1734
|
-
);
|
|
1857
|
+
expect(testFailureEntityAlice).toBeNull();
|
|
1735
1858
|
|
|
1736
|
-
|
|
1737
|
-
|
|
1859
|
+
const testSuccessEntityAlice = await nymph.getEntity(
|
|
1860
|
+
{
|
|
1861
|
+
class: TestModel,
|
|
1862
|
+
acRequest: TilmeldAccessRequest.PRIMARY_GROUP_ACCESSIBLE,
|
|
1863
|
+
},
|
|
1864
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1865
|
+
);
|
|
1866
|
+
|
|
1867
|
+
expect(testSuccessEntityAlice).not.toBeNull();
|
|
1868
|
+
});
|
|
1738
1869
|
|
|
1739
|
-
|
|
1740
|
-
|
|
1870
|
+
it("access request for user owned doesn't return secondary group owned entity", async () => {
|
|
1871
|
+
const { bob, alice, abgroup } = await makeUsers();
|
|
1741
1872
|
|
|
1742
|
-
|
|
1873
|
+
await tilmeld.fillSession(bob);
|
|
1743
1874
|
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1875
|
+
const bobsEntity = await TestModel.factory();
|
|
1876
|
+
bobsEntity.name = "Bob's Entity";
|
|
1877
|
+
bobsEntity.group = abgroup;
|
|
1878
|
+
await bobsEntity.$save();
|
|
1748
1879
|
|
|
1749
|
-
|
|
1750
|
-
|
|
1880
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
1881
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
1751
1882
|
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1883
|
+
const testEntityBob = await nymph.getEntity(
|
|
1884
|
+
{ class: TestModel },
|
|
1885
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1886
|
+
);
|
|
1756
1887
|
|
|
1757
|
-
|
|
1758
|
-
|
|
1888
|
+
expect(testEntityBob).not.toBeNull();
|
|
1889
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
1759
1890
|
|
|
1760
|
-
|
|
1761
|
-
|
|
1891
|
+
tilmeld.clearSession();
|
|
1892
|
+
await tilmeld.fillSession(alice);
|
|
1762
1893
|
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1894
|
+
const testEntityAlice = await nymph.getEntity(
|
|
1895
|
+
{ class: TestModel },
|
|
1896
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1897
|
+
);
|
|
1767
1898
|
|
|
1768
|
-
|
|
1899
|
+
expect(testEntityAlice).not.toBeNull();
|
|
1769
1900
|
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1901
|
+
const testFailureEntityAlice = await nymph.getEntity(
|
|
1902
|
+
{ class: TestModel, acRequest: TilmeldAccessRequest.USER_OWNED },
|
|
1903
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1904
|
+
);
|
|
1774
1905
|
|
|
1775
|
-
|
|
1906
|
+
expect(testFailureEntityAlice).toBeNull();
|
|
1776
1907
|
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1908
|
+
const testSuccessEntityAlice = await nymph.getEntity(
|
|
1909
|
+
{
|
|
1910
|
+
class: TestModel,
|
|
1911
|
+
acRequest: TilmeldAccessRequest.SECONDARY_GROUP_OWNED,
|
|
1912
|
+
},
|
|
1913
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1914
|
+
);
|
|
1784
1915
|
|
|
1785
|
-
|
|
1786
|
-
|
|
1916
|
+
expect(testSuccessEntityAlice).not.toBeNull();
|
|
1917
|
+
});
|
|
1787
1918
|
|
|
1788
|
-
|
|
1789
|
-
|
|
1919
|
+
it("access request for user owned doesn't return secondary group accessible entity", async () => {
|
|
1920
|
+
const { bob, alice, abgroup } = await makeUsers();
|
|
1790
1921
|
|
|
1791
|
-
|
|
1922
|
+
await tilmeld.fillSession(bob);
|
|
1792
1923
|
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1924
|
+
const bobsEntity = await TestModel.factory();
|
|
1925
|
+
bobsEntity.name = "Bob's Entity";
|
|
1926
|
+
bobsEntity.acFull = [abgroup.guid ?? ''];
|
|
1927
|
+
await bobsEntity.$save();
|
|
1797
1928
|
|
|
1798
|
-
|
|
1799
|
-
|
|
1929
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
1930
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
1800
1931
|
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1932
|
+
const testEntityBob = await nymph.getEntity(
|
|
1933
|
+
{ class: TestModel },
|
|
1934
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1935
|
+
);
|
|
1805
1936
|
|
|
1806
|
-
|
|
1807
|
-
|
|
1937
|
+
expect(testEntityBob).not.toBeNull();
|
|
1938
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
1808
1939
|
|
|
1809
|
-
|
|
1810
|
-
|
|
1940
|
+
tilmeld.clearSession();
|
|
1941
|
+
await tilmeld.fillSession(alice);
|
|
1811
1942
|
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1943
|
+
const testEntityAlice = await nymph.getEntity(
|
|
1944
|
+
{ class: TestModel },
|
|
1945
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1946
|
+
);
|
|
1816
1947
|
|
|
1817
|
-
|
|
1948
|
+
expect(testEntityAlice).not.toBeNull();
|
|
1818
1949
|
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1950
|
+
const testFailureEntityAlice = await nymph.getEntity(
|
|
1951
|
+
{ class: TestModel, acRequest: TilmeldAccessRequest.USER_OWNED },
|
|
1952
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1953
|
+
);
|
|
1823
1954
|
|
|
1824
|
-
|
|
1955
|
+
expect(testFailureEntityAlice).toBeNull();
|
|
1825
1956
|
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1957
|
+
const testSuccessEntityAlice = await nymph.getEntity(
|
|
1958
|
+
{
|
|
1959
|
+
class: TestModel,
|
|
1960
|
+
acRequest: TilmeldAccessRequest.SECONDARY_GROUP_ACCESSIBLE,
|
|
1961
|
+
},
|
|
1962
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1963
|
+
);
|
|
1833
1964
|
|
|
1834
|
-
|
|
1965
|
+
expect(testSuccessEntityAlice).not.toBeNull();
|
|
1835
1966
|
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1967
|
+
// Test or-ing two levels together.
|
|
1968
|
+
const testSuccessEntityAlice2 = await nymph.getEntity(
|
|
1969
|
+
{
|
|
1970
|
+
class: TestModel,
|
|
1971
|
+
acRequest:
|
|
1972
|
+
TilmeldAccessRequest.SECONDARY_GROUP_ACCESSIBLE |
|
|
1973
|
+
TilmeldAccessRequest.PRIMARY_GROUP_ACCESSIBLE,
|
|
1974
|
+
},
|
|
1975
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1976
|
+
);
|
|
1846
1977
|
|
|
1847
|
-
|
|
1848
|
-
|
|
1978
|
+
expect(testSuccessEntityAlice2).not.toBeNull();
|
|
1979
|
+
});
|
|
1849
1980
|
|
|
1850
|
-
|
|
1851
|
-
|
|
1981
|
+
it('access request for entity still works when filtering user owned entities manually', async () => {
|
|
1982
|
+
const { bob, alice } = await makeUsers();
|
|
1852
1983
|
|
|
1853
|
-
|
|
1984
|
+
await tilmeld.fillSession(bob);
|
|
1854
1985
|
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1986
|
+
const bobsEntity = await TestModel.factory();
|
|
1987
|
+
bobsEntity.name = "Bob's Entity";
|
|
1988
|
+
bobsEntity.acFull = [alice.guid ?? ''];
|
|
1989
|
+
await bobsEntity.$save();
|
|
1859
1990
|
|
|
1860
|
-
|
|
1861
|
-
|
|
1991
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
1992
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
1862
1993
|
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1994
|
+
const testEntityBob = await nymph.getEntity(
|
|
1995
|
+
{ class: TestModel },
|
|
1996
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
1997
|
+
);
|
|
1867
1998
|
|
|
1868
|
-
|
|
1869
|
-
|
|
1999
|
+
expect(testEntityBob).not.toBeNull();
|
|
2000
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
1870
2001
|
|
|
1871
|
-
|
|
1872
|
-
|
|
2002
|
+
tilmeld.clearSession();
|
|
2003
|
+
await tilmeld.fillSession(alice);
|
|
1873
2004
|
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
2005
|
+
const alicesEntity = await TestModel.factory();
|
|
2006
|
+
alicesEntity.name = "Alice's Entity";
|
|
2007
|
+
await alicesEntity.$save();
|
|
1877
2008
|
|
|
1878
|
-
|
|
1879
|
-
|
|
2009
|
+
expect(alicesEntity.guid).not.toBeNull();
|
|
2010
|
+
expect(alice.$is(alicesEntity.user)).toEqual(true);
|
|
1880
2011
|
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
2012
|
+
const testEntityAlice = await nymph.getEntity(
|
|
2013
|
+
{ class: TestModel },
|
|
2014
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
2015
|
+
);
|
|
1885
2016
|
|
|
1886
|
-
|
|
2017
|
+
expect(testEntityAlice).not.toBeNull();
|
|
1887
2018
|
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
2019
|
+
const testWithoutFiltering = await nymph.getEntities(
|
|
2020
|
+
{ class: TestModel, acRequest: TilmeldAccessRequest.USER_OWNED },
|
|
2021
|
+
{ type: '|', guid: [alicesEntity.guid || '', bobsEntity.guid || ''] },
|
|
2022
|
+
);
|
|
1892
2023
|
|
|
1893
|
-
|
|
1894
|
-
|
|
2024
|
+
expect(testWithoutFiltering.length).toEqual(1);
|
|
2025
|
+
expect(testWithoutFiltering[0].guid).toEqual(alicesEntity?.guid || '');
|
|
1895
2026
|
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
2027
|
+
const testWithFiltering = await nymph.getEntities(
|
|
2028
|
+
{
|
|
2029
|
+
class: TestModel,
|
|
2030
|
+
acRequest: TilmeldAccessRequest.USER_OWNED,
|
|
2031
|
+
},
|
|
2032
|
+
{ type: '|', guid: [alicesEntity.guid || '', bobsEntity.guid || ''] },
|
|
2033
|
+
{ type: '!&', ref: ['user', alice] },
|
|
2034
|
+
);
|
|
1904
2035
|
|
|
1905
|
-
|
|
2036
|
+
expect(testWithFiltering.length).toEqual(0);
|
|
1906
2037
|
|
|
1907
|
-
|
|
2038
|
+
const testInclusive = await nymph.getEntities({ class: TestModel });
|
|
1908
2039
|
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
2040
|
+
const testInclusiveWithFiltering = await nymph.getEntities(
|
|
2041
|
+
{ class: TestModel },
|
|
2042
|
+
{ type: '!&', ref: ['user', alice] },
|
|
2043
|
+
);
|
|
1913
2044
|
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
2045
|
+
expect(testInclusiveWithFiltering.length).toBeGreaterThanOrEqual(1);
|
|
2046
|
+
const guids = testInclusiveWithFiltering.map((entity) => entity.guid);
|
|
2047
|
+
expect(guids).not.toContain(alicesEntity?.guid || '');
|
|
2048
|
+
expect(guids).toContain(bobsEntity?.guid || '');
|
|
1918
2049
|
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
2050
|
+
const allDefaultGuids = testInclusive.map((entity) => entity.guid);
|
|
2051
|
+
for (let guid of guids) {
|
|
2052
|
+
expect(allDefaultGuids).toContain(guid);
|
|
2053
|
+
}
|
|
2054
|
+
});
|
|
1924
2055
|
|
|
1925
|
-
|
|
1926
|
-
|
|
2056
|
+
it("access request for invalid access control doesn't return any inaccessible entities", async () => {
|
|
2057
|
+
const { bob, alice, abgroup } = await makeUsers();
|
|
1927
2058
|
|
|
1928
|
-
|
|
2059
|
+
await tilmeld.fillSession(bob);
|
|
1929
2060
|
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
2061
|
+
const bobsEntity = await TestModel.factory();
|
|
2062
|
+
bobsEntity.name = "Bob's Entity";
|
|
2063
|
+
await bobsEntity.$save();
|
|
1933
2064
|
|
|
1934
|
-
|
|
1935
|
-
|
|
2065
|
+
expect(bobsEntity.guid).not.toBeNull();
|
|
2066
|
+
expect(bob.$is(bobsEntity.user)).toEqual(true);
|
|
1936
2067
|
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
2068
|
+
const testEntityBob = await nymph.getEntity(
|
|
2069
|
+
{ class: TestModel },
|
|
2070
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
2071
|
+
);
|
|
1941
2072
|
|
|
1942
|
-
|
|
1943
|
-
|
|
2073
|
+
expect(testEntityBob).not.toBeNull();
|
|
2074
|
+
expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
|
|
1944
2075
|
|
|
1945
|
-
|
|
1946
|
-
|
|
2076
|
+
tilmeld.clearSession();
|
|
2077
|
+
await tilmeld.fillSession(alice);
|
|
1947
2078
|
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
2079
|
+
const testEntityAlice = await nymph.getEntity(
|
|
2080
|
+
{ class: TestModel },
|
|
2081
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
2082
|
+
);
|
|
1952
2083
|
|
|
1953
|
-
|
|
2084
|
+
expect(testEntityAlice).toBeNull();
|
|
1954
2085
|
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
2086
|
+
const testFailureEntityAlice = await nymph.getEntity(
|
|
2087
|
+
{ class: TestModel, acRequest: TilmeldAccessRequest.UNOWNED * 2 },
|
|
2088
|
+
{ type: '&', guid: bobsEntity.guid || '' },
|
|
2089
|
+
);
|
|
1959
2090
|
|
|
1960
|
-
|
|
1961
|
-
|
|
2091
|
+
expect(testFailureEntityAlice).toBeNull();
|
|
2092
|
+
});
|
|
1962
2093
|
|
|
1963
|
-
|
|
1964
|
-
|
|
2094
|
+
it('delete test data again', async () => {
|
|
2095
|
+
await deleteTestData();
|
|
2096
|
+
});
|
|
1965
2097
|
});
|
|
1966
2098
|
}
|