@nymphjs/tilmeld 1.0.0-beta.109 → 1.0.0-beta.110

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.
@@ -227,7 +227,7 @@ export function TilmeldTest(
227
227
 
228
228
  const bobsEntity = await TestModel.factory();
229
229
  bobsEntity.name = "Bob's Entity";
230
- bobsEntity.acRead = [alice];
230
+ bobsEntity.acRead = [alice.guid ?? ''];
231
231
  expect(await bobsEntity.$save()).toEqual(true);
232
232
 
233
233
  expect(bobsEntity.guid).not.toBeNull();
@@ -275,7 +275,7 @@ export function TilmeldTest(
275
275
 
276
276
  const bobsEntity = await TestModel.factory();
277
277
  bobsEntity.name = "Bob's Entity";
278
- bobsEntity.acWrite = [alice];
278
+ bobsEntity.acWrite = [alice.guid ?? ''];
279
279
  expect(await bobsEntity.$save()).toEqual(true);
280
280
 
281
281
  expect(bobsEntity.guid).not.toBeNull();
@@ -318,7 +318,7 @@ export function TilmeldTest(
318
318
 
319
319
  const bobsEntity = await TestModel.factory();
320
320
  bobsEntity.name = "Bob's Entity";
321
- bobsEntity.acWrite = [alice];
321
+ bobsEntity.acWrite = [alice.guid ?? ''];
322
322
  expect(await bobsEntity.$save()).toEqual(true);
323
323
 
324
324
  expect(bobsEntity.guid).not.toBeNull();
@@ -365,7 +365,7 @@ export function TilmeldTest(
365
365
 
366
366
  const bobsEntity = await TestModel.factory();
367
367
  bobsEntity.name = "Bob's Entity";
368
- bobsEntity.acFull = [alice];
368
+ bobsEntity.acFull = [alice.guid ?? ''];
369
369
  expect(await bobsEntity.$save()).toEqual(true);
370
370
 
371
371
  expect(bobsEntity.guid).not.toBeNull();
@@ -409,7 +409,7 @@ export function TilmeldTest(
409
409
 
410
410
  const bobsEntity = await TestModel.factory();
411
411
  bobsEntity.name = "Bob's Entity";
412
- bobsEntity.acRead = [abgroup];
412
+ bobsEntity.acRead = [abgroup.guid ?? ''];
413
413
  expect(await bobsEntity.$save()).toEqual(true);
414
414
 
415
415
  expect(bobsEntity.guid).not.toBeNull();
@@ -442,7 +442,7 @@ export function TilmeldTest(
442
442
 
443
443
  const bobsEntity = await TestModel.factory();
444
444
  bobsEntity.name = "Bob's Entity";
445
- bobsEntity.acRead = [abgroup];
445
+ bobsEntity.acRead = [abgroup.guid ?? ''];
446
446
  expect(await bobsEntity.$save()).toEqual(true);
447
447
 
448
448
  expect(bobsEntity.guid).not.toBeNull();
@@ -490,7 +490,7 @@ export function TilmeldTest(
490
490
 
491
491
  const bobsEntity = await TestModel.factory();
492
492
  bobsEntity.name = "Bob's Entity";
493
- bobsEntity.acWrite = [abgroup];
493
+ bobsEntity.acWrite = [abgroup.guid ?? ''];
494
494
  expect(await bobsEntity.$save()).toEqual(true);
495
495
 
496
496
  expect(bobsEntity.guid).not.toBeNull();
@@ -533,7 +533,7 @@ export function TilmeldTest(
533
533
 
534
534
  const bobsEntity = await TestModel.factory();
535
535
  bobsEntity.name = "Bob's Entity";
536
- bobsEntity.acWrite = [abgroup];
536
+ bobsEntity.acWrite = [abgroup.guid ?? ''];
537
537
  expect(await bobsEntity.$save()).toEqual(true);
538
538
 
539
539
  expect(bobsEntity.guid).not.toBeNull();
@@ -580,7 +580,7 @@ export function TilmeldTest(
580
580
 
581
581
  const bobsEntity = await TestModel.factory();
582
582
  bobsEntity.name = "Bob's Entity";
583
- bobsEntity.acFull = [abgroup];
583
+ bobsEntity.acFull = [abgroup.guid ?? ''];
584
584
  expect(await bobsEntity.$save()).toEqual(true);
585
585
 
586
586
  expect(bobsEntity.guid).not.toBeNull();
@@ -1103,4 +1103,383 @@ export function TilmeldTest(
1103
1103
  expect(await entity.$deleteSkipAC()).toEqual(true);
1104
1104
  }
1105
1105
  });
1106
+
1107
+ it('entity can be retrieved by queries on ac properties', async () => {
1108
+ const { bob, alice } = await makeUsers();
1109
+
1110
+ await tilmeld.fillSession(bob);
1111
+
1112
+ const bobsEntity = await TestModel.factory();
1113
+ bobsEntity.name = "Bob's Entity";
1114
+ bobsEntity.acRead = [
1115
+ alice.guid ?? '',
1116
+ bob.guid ?? '',
1117
+ ...(bob.group ? [bob.group.guid ?? ''] : []),
1118
+ ];
1119
+ bobsEntity.acWrite = [alice.guid ?? '', bob.guid ?? ''];
1120
+ bobsEntity.acFull = [bob.guid ?? ''];
1121
+ expect(await bobsEntity.$save()).toEqual(true);
1122
+
1123
+ expect(bobsEntity.guid).not.toBeNull();
1124
+ expect(bob.$is(bobsEntity.user)).toEqual(true);
1125
+
1126
+ const testEntityBob = await nymph.getEntity(
1127
+ { class: TestModel },
1128
+ { type: '&', guid: bobsEntity.guid || '' },
1129
+ );
1130
+
1131
+ expect(testEntityBob).not.toBeNull();
1132
+ expect(testEntityBob?.guid).toEqual(bobsEntity.guid);
1133
+
1134
+ tilmeld.clearSession();
1135
+ await tilmeld.fillSession(alice);
1136
+
1137
+ // Equals queries.
1138
+
1139
+ let testEntityAlice = await nymph.getEntity(
1140
+ { class: TestModel },
1141
+ {
1142
+ type: '&',
1143
+ guid: bobsEntity.guid || '',
1144
+ equal: ['user', bob.guid],
1145
+ },
1146
+ );
1147
+
1148
+ expect(testEntityAlice).not.toBeNull();
1149
+ expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
1150
+
1151
+ testEntityAlice = await nymph.getEntity(
1152
+ { class: TestModel },
1153
+ {
1154
+ type: '&',
1155
+ guid: bobsEntity.guid || '',
1156
+ equal: ['user', '000000000000000000000000'],
1157
+ },
1158
+ );
1159
+
1160
+ expect(testEntityAlice).toBeNull();
1161
+
1162
+ testEntityAlice = await nymph.getEntity(
1163
+ { class: TestModel },
1164
+ {
1165
+ type: '&',
1166
+ guid: bobsEntity.guid || '',
1167
+ equal: ['group', bob.group?.guid],
1168
+ },
1169
+ );
1170
+
1171
+ expect(testEntityAlice).not.toBeNull();
1172
+ expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
1173
+
1174
+ testEntityAlice = await nymph.getEntity(
1175
+ { class: TestModel },
1176
+ {
1177
+ type: '&',
1178
+ guid: bobsEntity.guid || '',
1179
+ equal: ['group', '000000000000000000000000'],
1180
+ },
1181
+ );
1182
+
1183
+ expect(testEntityAlice).toBeNull();
1184
+
1185
+ // Contains queries.
1186
+
1187
+ testEntityAlice = await nymph.getEntity(
1188
+ { class: TestModel },
1189
+ {
1190
+ type: '&',
1191
+ guid: bobsEntity.guid || '',
1192
+ contain: ['user', bob.guid],
1193
+ },
1194
+ );
1195
+
1196
+ expect(testEntityAlice).not.toBeNull();
1197
+ expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
1198
+
1199
+ testEntityAlice = await nymph.getEntity(
1200
+ { class: TestModel },
1201
+ {
1202
+ type: '&',
1203
+ guid: bobsEntity.guid || '',
1204
+ contain: ['user', '000000000000000000000000'],
1205
+ },
1206
+ );
1207
+
1208
+ expect(testEntityAlice).toBeNull();
1209
+
1210
+ testEntityAlice = await nymph.getEntity(
1211
+ { class: TestModel },
1212
+ {
1213
+ type: '&',
1214
+ guid: bobsEntity.guid || '',
1215
+ contain: ['group', bob.group?.guid],
1216
+ },
1217
+ );
1218
+
1219
+ expect(testEntityAlice).not.toBeNull();
1220
+ expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
1221
+
1222
+ testEntityAlice = await nymph.getEntity(
1223
+ { class: TestModel },
1224
+ {
1225
+ type: '&',
1226
+ guid: bobsEntity.guid || '',
1227
+ contain: ['group', '000000000000000000000000'],
1228
+ },
1229
+ );
1230
+
1231
+ expect(testEntityAlice).toBeNull();
1232
+
1233
+ testEntityAlice = await nymph.getEntity(
1234
+ { class: TestModel },
1235
+ {
1236
+ type: '&',
1237
+ guid: bobsEntity.guid || '',
1238
+ contain: ['acRead', alice.guid],
1239
+ },
1240
+ );
1241
+
1242
+ expect(testEntityAlice).not.toBeNull();
1243
+ expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
1244
+
1245
+ testEntityAlice = await nymph.getEntity(
1246
+ { class: TestModel },
1247
+ {
1248
+ type: '&',
1249
+ guid: bobsEntity.guid || '',
1250
+ contain: ['acRead', '000000000000000000000000'],
1251
+ },
1252
+ );
1253
+
1254
+ expect(testEntityAlice).toBeNull();
1255
+
1256
+ testEntityAlice = await nymph.getEntity(
1257
+ { class: TestModel },
1258
+ {
1259
+ type: '&',
1260
+ guid: bobsEntity.guid || '',
1261
+ contain: ['acWrite', bob.guid],
1262
+ },
1263
+ );
1264
+
1265
+ expect(testEntityAlice).not.toBeNull();
1266
+ expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
1267
+
1268
+ testEntityAlice = await nymph.getEntity(
1269
+ { class: TestModel },
1270
+ {
1271
+ type: '&',
1272
+ guid: bobsEntity.guid || '',
1273
+ contain: ['acWrite', '000000000000000000000000'],
1274
+ },
1275
+ );
1276
+
1277
+ expect(testEntityAlice).toBeNull();
1278
+
1279
+ testEntityAlice = await nymph.getEntity(
1280
+ { class: TestModel },
1281
+ {
1282
+ type: '&',
1283
+ guid: bobsEntity.guid || '',
1284
+ contain: ['acFull', bob.guid],
1285
+ },
1286
+ );
1287
+
1288
+ expect(testEntityAlice).not.toBeNull();
1289
+ expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
1290
+
1291
+ testEntityAlice = await nymph.getEntity(
1292
+ { class: TestModel },
1293
+ {
1294
+ type: '&',
1295
+ guid: bobsEntity.guid || '',
1296
+ contain: ['acFull', '000000000000000000000000'],
1297
+ },
1298
+ );
1299
+
1300
+ expect(testEntityAlice).toBeNull();
1301
+
1302
+ // Ref queries.
1303
+
1304
+ testEntityAlice = await nymph.getEntity(
1305
+ { class: TestModel },
1306
+ {
1307
+ type: '&',
1308
+ guid: bobsEntity.guid || '',
1309
+ ref: ['user', bob],
1310
+ },
1311
+ );
1312
+
1313
+ expect(testEntityAlice).not.toBeNull();
1314
+ expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
1315
+
1316
+ testEntityAlice = await nymph.getEntity(
1317
+ { class: TestModel },
1318
+ {
1319
+ type: '&',
1320
+ guid: bobsEntity.guid || '',
1321
+ ref: ['user', '000000000000000000000000'],
1322
+ },
1323
+ );
1324
+
1325
+ expect(testEntityAlice).toBeNull();
1326
+
1327
+ testEntityAlice = await nymph.getEntity(
1328
+ { class: TestModel },
1329
+ {
1330
+ type: '&',
1331
+ guid: bobsEntity.guid || '',
1332
+ ref: ['group', bob.group ?? ''],
1333
+ },
1334
+ );
1335
+
1336
+ expect(testEntityAlice).not.toBeNull();
1337
+ expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
1338
+
1339
+ testEntityAlice = await nymph.getEntity(
1340
+ { class: TestModel },
1341
+ {
1342
+ type: '&',
1343
+ guid: bobsEntity.guid || '',
1344
+ ref: ['group', '000000000000000000000000'],
1345
+ },
1346
+ );
1347
+
1348
+ expect(testEntityAlice).toBeNull();
1349
+
1350
+ testEntityAlice = await nymph.getEntity(
1351
+ { class: TestModel },
1352
+ {
1353
+ type: '&',
1354
+ guid: bobsEntity.guid || '',
1355
+ ref: ['acRead', alice],
1356
+ },
1357
+ );
1358
+
1359
+ expect(testEntityAlice).not.toBeNull();
1360
+ expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
1361
+
1362
+ testEntityAlice = await nymph.getEntity(
1363
+ { class: TestModel },
1364
+ {
1365
+ type: '&',
1366
+ guid: bobsEntity.guid || '',
1367
+ ref: ['acRead', '000000000000000000000000'],
1368
+ },
1369
+ );
1370
+
1371
+ expect(testEntityAlice).toBeNull();
1372
+
1373
+ testEntityAlice = await nymph.getEntity(
1374
+ { class: TestModel },
1375
+ {
1376
+ type: '&',
1377
+ guid: bobsEntity.guid || '',
1378
+ ref: ['acWrite', bob],
1379
+ },
1380
+ );
1381
+
1382
+ expect(testEntityAlice).not.toBeNull();
1383
+ expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
1384
+
1385
+ testEntityAlice = await nymph.getEntity(
1386
+ { class: TestModel },
1387
+ {
1388
+ type: '&',
1389
+ guid: bobsEntity.guid || '',
1390
+ ref: ['acWrite', '000000000000000000000000'],
1391
+ },
1392
+ );
1393
+
1394
+ expect(testEntityAlice).toBeNull();
1395
+
1396
+ testEntityAlice = await nymph.getEntity(
1397
+ { class: TestModel },
1398
+ {
1399
+ type: '&',
1400
+ guid: bobsEntity.guid || '',
1401
+ ref: ['acFull', bob],
1402
+ },
1403
+ );
1404
+
1405
+ expect(testEntityAlice).not.toBeNull();
1406
+ expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
1407
+
1408
+ testEntityAlice = await nymph.getEntity(
1409
+ { class: TestModel },
1410
+ {
1411
+ type: '&',
1412
+ guid: bobsEntity.guid || '',
1413
+ ref: ['acFull', '000000000000000000000000'],
1414
+ },
1415
+ );
1416
+
1417
+ expect(testEntityAlice).toBeNull();
1418
+
1419
+ // QRef queries.
1420
+
1421
+ testEntityAlice = await nymph.getEntity(
1422
+ { class: TestModel },
1423
+ {
1424
+ type: '&',
1425
+ guid: bobsEntity.guid || '',
1426
+ qref: [
1427
+ 'user',
1428
+ [
1429
+ { class: User },
1430
+ { type: '&', equal: ['username', bob.username ?? ''] },
1431
+ ],
1432
+ ],
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
+ qref: [
1445
+ 'user',
1446
+ [{ class: User }, { type: '&', equal: ['username', 'pickle'] }],
1447
+ ],
1448
+ },
1449
+ );
1450
+
1451
+ expect(testEntityAlice).toBeNull();
1452
+
1453
+ testEntityAlice = await nymph.getEntity(
1454
+ { class: TestModel },
1455
+ {
1456
+ type: '&',
1457
+ guid: bobsEntity.guid || '',
1458
+ qref: [
1459
+ 'acRead',
1460
+ [
1461
+ { class: User },
1462
+ { type: '&', equal: ['username', alice.username ?? ''] },
1463
+ ],
1464
+ ],
1465
+ },
1466
+ );
1467
+
1468
+ expect(testEntityAlice).not.toBeNull();
1469
+ expect(testEntityAlice?.guid).toEqual(bobsEntity.guid);
1470
+
1471
+ testEntityAlice = await nymph.getEntity(
1472
+ { class: TestModel },
1473
+ {
1474
+ type: '&',
1475
+ guid: bobsEntity.guid || '',
1476
+ qref: [
1477
+ 'acRead',
1478
+ [{ class: User }, { type: '&', equal: ['username', 'pickle'] }],
1479
+ ],
1480
+ },
1481
+ );
1482
+
1483
+ expect(testEntityAlice).toBeNull();
1484
+ });
1106
1485
  }
@@ -25,22 +25,7 @@ export default {
25
25
  TilmeldAccessLevels.WRITE_ACCESS,
26
26
  TilmeldAccessLevels.FULL_ACCESS,
27
27
  ),
28
- acRead: Joi.array().items(
29
- Joi.alternatives().try(
30
- Joi.object().instance(User),
31
- Joi.object().instance(Group),
32
- ),
33
- ),
34
- acWrite: Joi.array().items(
35
- Joi.alternatives().try(
36
- Joi.object().instance(User),
37
- Joi.object().instance(Group),
38
- ),
39
- ),
40
- acFull: Joi.array().items(
41
- Joi.alternatives().try(
42
- Joi.object().instance(User),
43
- Joi.object().instance(Group),
44
- ),
45
- ),
28
+ acRead: Joi.array().items(Joi.string().pattern(/^[0-9a-f]{24}$/i, 'GUID')),
29
+ acWrite: Joi.array().items(Joi.string().pattern(/^[0-9a-f]{24}$/i, 'GUID')),
30
+ acFull: Joi.array().items(Joi.string().pattern(/^[0-9a-f]{24}$/i, 'GUID')),
46
31
  };