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