@nymphjs/tilmeld 1.0.0-beta.46 → 1.0.0-beta.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/Group.ts CHANGED
@@ -119,7 +119,7 @@ export default class Group extends AbleObject<GroupData> {
119
119
  }
120
120
 
121
121
  static async factoryGroupname(
122
- groupname?: string
122
+ groupname?: string,
123
123
  ): Promise<Group & GroupData> {
124
124
  const entity = new this();
125
125
  if (groupname != null) {
@@ -130,7 +130,7 @@ export default class Group extends AbleObject<GroupData> {
130
130
  {
131
131
  type: '&',
132
132
  ilike: ['groupname', groupname.replace(/([\\%_])/g, (s) => `\\${s}`)],
133
- }
133
+ },
134
134
  );
135
135
  if (entity != null) {
136
136
  return entity;
@@ -161,7 +161,7 @@ export default class Group extends AbleObject<GroupData> {
161
161
  */
162
162
  public static async getPrimaryGroups(
163
163
  options?: Options,
164
- selectors?: Selector[]
164
+ selectors?: Selector[],
165
165
  ) {
166
166
  const tilmeld = enforceTilmeld(this);
167
167
  if (!tilmeld.gatekeeper('tilmeld/admin')) {
@@ -171,7 +171,7 @@ export default class Group extends AbleObject<GroupData> {
171
171
  return await this.getAssignableGroups(
172
172
  tilmeld.config.highestPrimary,
173
173
  { ...options, class: tilmeld.Group, return: 'entity' },
174
- [...(selectors ?? [])]
174
+ [...(selectors ?? [])],
175
175
  );
176
176
  }
177
177
 
@@ -184,7 +184,7 @@ export default class Group extends AbleObject<GroupData> {
184
184
  */
185
185
  public static async getSecondaryGroups(
186
186
  options?: Options,
187
- selectors?: Selector[]
187
+ selectors?: Selector[],
188
188
  ) {
189
189
  const tilmeld = enforceTilmeld(this);
190
190
  if (!tilmeld.gatekeeper('tilmeld/admin')) {
@@ -194,14 +194,14 @@ export default class Group extends AbleObject<GroupData> {
194
194
  return await this.getAssignableGroups(
195
195
  tilmeld.config.highestSecondary,
196
196
  { ...options, class: tilmeld.Group, return: 'entity' },
197
- [...(selectors ?? [])]
197
+ [...(selectors ?? [])],
198
198
  );
199
199
  }
200
200
 
201
201
  private static async getAssignableGroups(
202
202
  highestParent: string | boolean,
203
203
  options: Options<typeof Group>,
204
- selectors: Selector[]
204
+ selectors: Selector[],
205
205
  ) {
206
206
  const tilmeld = enforceTilmeld(this);
207
207
  let assignableGroups: (Group & GroupData)[] = [];
@@ -212,7 +212,7 @@ export default class Group extends AbleObject<GroupData> {
212
212
 
213
213
  assignableGroups = await this.nymph.getEntities(
214
214
  { ...options, class: tilmeld.Group },
215
- ...selectors
215
+ ...selectors,
216
216
  );
217
217
  if (highestParent !== true) {
218
218
  assignableGroups = (
@@ -230,7 +230,7 @@ export default class Group extends AbleObject<GroupData> {
230
230
  await parent?.$wake();
231
231
  }
232
232
  return null;
233
- })
233
+ }),
234
234
  )
235
235
  ).filter((group) => group != null) as (Group & GroupData)[];
236
236
  }
@@ -263,7 +263,7 @@ export default class Group extends AbleObject<GroupData> {
263
263
  !tilmeld.currentUser.abilities?.includes('system/admin'))
264
264
  ) {
265
265
  throw new BadDataError(
266
- "You don't have the authority to grant or revoke system/admin."
266
+ "You don't have the authority to grant or revoke system/admin.",
267
267
  );
268
268
  }
269
269
 
@@ -275,7 +275,7 @@ export default class Group extends AbleObject<GroupData> {
275
275
  !tilmeld.currentUser.abilities?.includes('system/admin'))
276
276
  ) {
277
277
  throw new BadDataError(
278
- "You don't have the authority to grant or revoke tilmeld/admin."
278
+ "You don't have the authority to grant or revoke tilmeld/admin.",
279
279
  );
280
280
  }
281
281
 
@@ -287,7 +287,7 @@ export default class Group extends AbleObject<GroupData> {
287
287
  !tilmeld.currentUser.abilities?.includes('system/admin'))
288
288
  ) {
289
289
  throw new BadDataError(
290
- "You don't have the authority to grant or revoke tilmeld/switch."
290
+ "You don't have the authority to grant or revoke tilmeld/switch.",
291
291
  );
292
292
  }
293
293
 
@@ -306,7 +306,7 @@ export default class Group extends AbleObject<GroupData> {
306
306
  !tilmeld.currentUser.abilities?.includes('system/admin'))
307
307
  ) {
308
308
  throw new BadDataError(
309
- "You don't have the authority to grant or revoke system/admin."
309
+ "You don't have the authority to grant or revoke system/admin.",
310
310
  );
311
311
  }
312
312
 
@@ -318,7 +318,7 @@ export default class Group extends AbleObject<GroupData> {
318
318
  !tilmeld.currentUser.abilities?.includes('system/admin'))
319
319
  ) {
320
320
  throw new BadDataError(
321
- "You don't have the authority to grant or revoke tilmeld/admin."
321
+ "You don't have the authority to grant or revoke tilmeld/admin.",
322
322
  );
323
323
  }
324
324
 
@@ -330,7 +330,7 @@ export default class Group extends AbleObject<GroupData> {
330
330
  !tilmeld.currentUser.abilities?.includes('system/admin'))
331
331
  ) {
332
332
  throw new BadDataError(
333
- "You don't have the authority to grant or revoke tilmeld/switch."
333
+ "You don't have the authority to grant or revoke tilmeld/switch.",
334
334
  );
335
335
  }
336
336
 
@@ -383,7 +383,7 @@ export default class Group extends AbleObject<GroupData> {
383
383
  * @returns True or false.
384
384
  */
385
385
  public async $isDescendant(
386
- givenGroup: (Group & GroupData) | string
386
+ givenGroup: (Group & GroupData) | string,
387
387
  ): Promise<boolean> {
388
388
  const tilmeld = enforceTilmeld(this);
389
389
  let group: Group & GroupData;
@@ -423,7 +423,7 @@ export default class Group extends AbleObject<GroupData> {
423
423
  type: '&',
424
424
  equal: ['enabled', true],
425
425
  ref: ['parent', this],
426
- }
426
+ },
427
427
  );
428
428
  }
429
429
 
@@ -434,7 +434,7 @@ export default class Group extends AbleObject<GroupData> {
434
434
  * @returns An array of groups.
435
435
  */
436
436
  public async $getDescendants(
437
- andSelf = false
437
+ andSelf = false,
438
438
  ): Promise<(Group & GroupData)[]> {
439
439
  const tilmeld = enforceTilmeld(this);
440
440
  let groups: (Group & GroupData)[] = [];
@@ -444,7 +444,7 @@ export default class Group extends AbleObject<GroupData> {
444
444
  type: '&',
445
445
  equal: ['enabled', true],
446
446
  ref: ['parent', this],
447
- }
447
+ },
448
448
  );
449
449
  for (let entity of entities) {
450
450
  groups = (await entity.$getDescendants(true)).concat(groups);
@@ -492,7 +492,7 @@ export default class Group extends AbleObject<GroupData> {
492
492
  public async $getUsers(
493
493
  descendants = false,
494
494
  limit?: number,
495
- offset?: number
495
+ offset?: number,
496
496
  ): Promise<(User & UserData)[]> {
497
497
  const tilmeld = enforceTilmeld(this);
498
498
  let groups: (Group & GroupData)[] = [];
@@ -523,7 +523,7 @@ export default class Group extends AbleObject<GroupData> {
523
523
  group,
524
524
  ]),
525
525
  ],
526
- }
526
+ },
527
527
  );
528
528
  }
529
529
 
@@ -562,7 +562,7 @@ export default class Group extends AbleObject<GroupData> {
562
562
  if (
563
563
  difference(
564
564
  this.$data.groupname.split(''),
565
- tilmeld.config.validChars.split('')
565
+ tilmeld.config.validChars.split(''),
566
566
  ).length
567
567
  ) {
568
568
  return {
@@ -589,7 +589,7 @@ export default class Group extends AbleObject<GroupData> {
589
589
  }
590
590
  const test = await this.$nymph.getEntity(
591
591
  { class: tilmeld.Group, skipAc: true },
592
- selector
592
+ selector,
593
593
  );
594
594
  if (test != null) {
595
595
  return { result: false, message: 'That groupname is taken.' };
@@ -656,7 +656,7 @@ export default class Group extends AbleObject<GroupData> {
656
656
  }
657
657
  const test = await this.$nymph.getEntity(
658
658
  { class: tilmeld.Group, skipAc: true },
659
- selector
659
+ selector,
660
660
  );
661
661
  if (test != null) {
662
662
  return {
@@ -749,7 +749,7 @@ export default class Group extends AbleObject<GroupData> {
749
749
  (await parent.$isDescendant(this)))
750
750
  ) {
751
751
  throw new BadDataError(
752
- "Group parent can't be itself or descendant of itself."
752
+ "Group parent can't be itself or descendant of itself.",
753
753
  );
754
754
  }
755
755
 
@@ -763,14 +763,14 @@ export default class Group extends AbleObject<GroupData> {
763
763
  if (this.$data.defaultPrimary) {
764
764
  const currentPrimary = await this.$nymph.getEntity(
765
765
  { class: tilmeld.Group },
766
- { type: '&', truthy: 'defaultPrimary' }
766
+ { type: '&', truthy: 'defaultPrimary' },
767
767
  );
768
768
  if (currentPrimary != null && !this.$is(currentPrimary)) {
769
769
  currentPrimary.defaultPrimary = false;
770
770
  if (!(await currentPrimary.$save())) {
771
771
  throw new CouldNotChangeDefaultPrimaryGroupError(
772
772
  'Could not change new user primary group from ' +
773
- `${currentPrimary.groupname}.`
773
+ `${currentPrimary.groupname}.`,
774
774
  );
775
775
  }
776
776
  }
@@ -828,7 +828,7 @@ export default class Group extends AbleObject<GroupData> {
828
828
  {
829
829
  type: '&',
830
830
  ref: ['group', this],
831
- }
831
+ },
832
832
  );
833
833
  for (let user of primaryUsers) {
834
834
  delete user.group;
@@ -848,7 +848,7 @@ export default class Group extends AbleObject<GroupData> {
848
848
  {
849
849
  type: '&',
850
850
  ref: ['groups', this],
851
- }
851
+ },
852
852
  );
853
853
  for (let user of secondaryUsers) {
854
854
  user.$delGroup(this);
package/src/Tilmeld.ts CHANGED
@@ -183,7 +183,7 @@ export default class Tilmeld implements TilmeldInterface {
183
183
  const handleQuery = function (
184
184
  nymph: Nymph,
185
185
  options: Options,
186
- selectors: FormattedSelector[]
186
+ selectors: FormattedSelector[],
187
187
  ) {
188
188
  const tilmeld = enforceTilmeld(nymph);
189
189
  if (
@@ -225,7 +225,7 @@ export default class Tilmeld implements TilmeldInterface {
225
225
  // Filter entities being deleted for user permissions.
226
226
  const checkPermissionsDelete = async function (
227
227
  nymph: Nymph,
228
- entity: EntityInterface
228
+ entity: EntityInterface,
229
229
  ) {
230
230
  const tilmeld = enforceTilmeld(nymph);
231
231
  if (
@@ -245,11 +245,11 @@ export default class Tilmeld implements TilmeldInterface {
245
245
  const checkPermissionsDeleteByID = async function (
246
246
  nymph: Nymph,
247
247
  guid: string,
248
- className?: string
248
+ className?: string,
249
249
  ) {
250
250
  const entity = await nymph.getEntity(
251
251
  { class: nymph.getEntityClass(className ?? 'Entity') },
252
- { type: '&', guid: guid }
252
+ { type: '&', guid: guid },
253
253
  );
254
254
  if (entity != null) {
255
255
  checkPermissionsDelete(nymph, entity);
@@ -261,7 +261,7 @@ export default class Tilmeld implements TilmeldInterface {
261
261
  // disallowed changes to AC properties.
262
262
  const checkPermissionsSaveAndFilterAcChanges = async function (
263
263
  nymph: Nymph,
264
- entity: EntityInterface & AccessControlData
264
+ entity: EntityInterface & AccessControlData,
265
265
  ) {
266
266
  const tilmeld = enforceTilmeld(nymph);
267
267
  if (!entity) {
@@ -338,12 +338,12 @@ export default class Tilmeld implements TilmeldInterface {
338
338
  entity,
339
339
  TilmeldAccessLevels.FULL_ACCESS,
340
340
  undefined,
341
- originalAc
341
+ originalAc,
342
342
  )
343
343
  ) {
344
344
  // Only allow changes to AC properties if the user has full access.
345
345
  throw new AccessControlError(
346
- 'No permission to change access control properties.'
346
+ 'No permission to change access control properties.',
347
347
  );
348
348
  }
349
349
 
@@ -354,7 +354,7 @@ export default class Tilmeld implements TilmeldInterface {
354
354
  newAc.user !== tilmeld.currentUser)
355
355
  ) {
356
356
  throw new AccessControlError(
357
- 'No permission to assign to another user.'
357
+ 'No permission to assign to another user.',
358
358
  );
359
359
  }
360
360
 
@@ -366,7 +366,7 @@ export default class Tilmeld implements TilmeldInterface {
366
366
  (tilmeld.currentUser?.$getGids() ?? []).includes(newAc.group))
367
367
  ) {
368
368
  throw new AccessControlError(
369
- 'No permission to assign to another group.'
369
+ 'No permission to assign to another group.',
370
370
  );
371
371
  }
372
372
  }
@@ -397,7 +397,7 @@ export default class Tilmeld implements TilmeldInterface {
397
397
  */
398
398
  const addAccess = async function (
399
399
  nymph: Nymph,
400
- entity: EntityInterface & AccessControlData
400
+ entity: EntityInterface & AccessControlData,
401
401
  ) {
402
402
  const tilmeld = enforceTilmeld(nymph);
403
403
  const user = tilmeld.currentUser;
@@ -440,7 +440,7 @@ export default class Tilmeld implements TilmeldInterface {
440
440
 
441
441
  const validate = async function (
442
442
  _nymph: Nymph,
443
- entity: EntityInterface & AccessControlData
443
+ entity: EntityInterface & AccessControlData,
444
444
  ) {
445
445
  if (!(entity instanceof User) && !(entity instanceof Group)) {
446
446
  const ownershipAcPropertyValidator = (prop: any) => {
@@ -450,7 +450,7 @@ export default class Tilmeld implements TilmeldInterface {
450
450
  prop > TilmeldAccessLevels.FULL_ACCESS
451
451
  ) {
452
452
  throw new AccessControlError(
453
- 'Invalid access control property: ' + prop
453
+ 'Invalid access control property: ' + prop,
454
454
  );
455
455
  }
456
456
  };
@@ -458,13 +458,13 @@ export default class Tilmeld implements TilmeldInterface {
458
458
  const accessAcPropertyValidator = (prop: any) => {
459
459
  if (!Array.isArray(prop)) {
460
460
  throw new AccessControlError(
461
- 'Invalid access control property: ' + prop
461
+ 'Invalid access control property: ' + prop,
462
462
  );
463
463
  }
464
464
  prop.forEach((value) => {
465
465
  if (!(value instanceof User || value instanceof Group)) {
466
466
  throw new AccessControlError(
467
- 'Invalid access control property: ' + prop
467
+ 'Invalid access control property: ' + prop,
468
468
  );
469
469
  }
470
470
  });
@@ -473,7 +473,7 @@ export default class Tilmeld implements TilmeldInterface {
473
473
  if ('user' in entity) {
474
474
  if (!(entity.user instanceof User)) {
475
475
  throw new AccessControlError(
476
- 'Invalid access control property: user'
476
+ 'Invalid access control property: user',
477
477
  );
478
478
  }
479
479
  }
@@ -481,7 +481,7 @@ export default class Tilmeld implements TilmeldInterface {
481
481
  if ('group' in entity) {
482
482
  if (!(entity.group instanceof Group)) {
483
483
  throw new AccessControlError(
484
- 'Invalid access control property: group'
484
+ 'Invalid access control property: group',
485
485
  );
486
486
  }
487
487
  }
@@ -526,7 +526,7 @@ export default class Tilmeld implements TilmeldInterface {
526
526
  */
527
527
  public addAccessControlSelectors(
528
528
  options: Options,
529
- selectors: FormattedSelector[]
529
+ selectors: FormattedSelector[],
530
530
  ) {
531
531
  const user = this.currentUser;
532
532
 
@@ -691,7 +691,7 @@ export default class Tilmeld implements TilmeldInterface {
691
691
  entity: EntityInterface,
692
692
  type: TilmeldAccessLevels = TilmeldAccessLevels.READ_ACCESS,
693
693
  user?: (User & UserData) | false,
694
- acProperties?: ACProperties
694
+ acProperties?: ACProperties,
695
695
  ) {
696
696
  if (!acProperties) {
697
697
  acProperties = entity.$getCurrentAcValues() as ACProperties;
@@ -811,7 +811,7 @@ export default class Tilmeld implements TilmeldInterface {
811
811
  public async checkClientUIDPermissions(
812
812
  name: string,
813
813
  type: TilmeldAccessLevels = TilmeldAccessLevels.READ_ACCESS,
814
- user?: (User & UserData) | false
814
+ user?: (User & UserData) | false,
815
815
  ) {
816
816
  let userOrEmpty: User & UserData = this.User.factorySync();
817
817
  // Calculate the user.
@@ -896,7 +896,7 @@ export default class Tilmeld implements TilmeldInterface {
896
896
  {
897
897
  type: '&',
898
898
  guid: guid,
899
- }
899
+ },
900
900
  );
901
901
  if (!user || !user.guid) {
902
902
  return null;
@@ -1050,7 +1050,7 @@ export default class Tilmeld implements TilmeldInterface {
1050
1050
  public async login(
1051
1051
  user: User & UserData,
1052
1052
  sendAuthHeader: boolean,
1053
- sendCookie = true
1053
+ sendCookie = true,
1054
1054
  ) {
1055
1055
  if (user.guid != null && user.enabled) {
1056
1056
  if (this.response) {
@@ -1096,7 +1096,7 @@ export default class Tilmeld implements TilmeldInterface {
1096
1096
  public async loginSwitch(
1097
1097
  user: User & UserData,
1098
1098
  sendAuthHeader: boolean,
1099
- sendCookie = true
1099
+ sendCookie = true,
1100
1100
  ) {
1101
1101
  if (user.guid != null) {
1102
1102
  if (this.response) {
package/src/User.test.ts CHANGED
@@ -21,7 +21,7 @@ const _nymph = new Nymph(
21
21
  new SQLite3Driver({
22
22
  filename: ':memory:',
23
23
  }),
24
- tilmeld
24
+ tilmeld,
25
25
  );
26
26
 
27
27
  const User = tilmeld.User;