@nymphjs/tilmeld 1.0.0-beta.132 → 1.0.0-beta.133
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/AbleObject.d.ts +6 -3
- package/dist/AbleObject.js +9 -9
- package/dist/AbleObject.js.map +1 -1
- package/dist/Group.d.ts +24 -23
- package/dist/Group.js +84 -92
- package/dist/Group.js.map +1 -1
- package/dist/Tilmeld.d.ts +9 -9
- package/dist/Tilmeld.js +6 -4
- package/dist/Tilmeld.js.map +1 -1
- package/dist/Tilmeld.types.d.ts +6 -6
- package/dist/User.d.ts +32 -31
- package/dist/User.js +280 -289
- package/dist/User.js.map +1 -1
- package/dist/conf/defaults.js +2 -2
- package/dist/conf/defaults.js.map +1 -1
- package/dist/conf/index.d.ts +8 -10
- package/dist/conf/index.js.map +1 -1
- package/dist/index.d.ts +2 -8
- package/dist/index.js +2 -8
- package/dist/index.js.map +1 -1
- package/dist/testArtifacts.d.ts +4 -2
- package/dist/testArtifacts.js.map +1 -1
- package/dist/tilmeldJoiProps.d.ts +1 -2
- package/dist/tilmeldJoiProps.js +3 -3
- package/dist/tilmeldJoiProps.js.map +1 -1
- package/package.json +5 -5
- package/src/AbleObject.ts +17 -11
- package/src/Group.ts +98 -122
- package/src/Tilmeld.ts +15 -17
- package/src/Tilmeld.types.ts +6 -6
- package/src/User.ts +303 -348
- package/src/conf/defaults.ts +2 -2
- package/src/conf/index.ts +8 -14
- package/src/index.ts +2 -8
- package/src/testArtifacts.ts +6 -4
- package/src/tilmeldJoiProps.ts +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [1.0.0-beta.133](https://forge.sciactive.com/sciactive/nymphjs/compare/v1.0.0-beta.132...v1.0.0-beta.133) (2026-10-28)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- remove necessity for data prop inside entities ([34e13f5](https://forge.sciactive.com/sciactive/nymphjs/commits/34e13f57375e82ab9677c6fd42ecc433333e0d22))
|
|
11
|
+
|
|
6
12
|
# [1.0.0-beta.132](https://forge.sciactive.com/sciactive/nymphjs/compare/v1.0.0-beta.131...v1.0.0-beta.132) (2026-10-26)
|
|
7
13
|
|
|
8
14
|
### Bug Fixes
|
package/dist/AbleObject.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { Entity } from '@nymphjs/nymph';
|
|
2
|
+
export interface AbleObjectData {
|
|
3
|
+
abilities?: string[];
|
|
4
|
+
}
|
|
5
|
+
export interface AbleObject<T extends {}> extends AbleObjectData {
|
|
6
|
+
}
|
|
2
7
|
/**
|
|
3
8
|
* AbleObject abstract class.
|
|
4
9
|
*
|
|
5
10
|
* Used in entities which support abilities, such as users and groups.
|
|
6
11
|
*/
|
|
7
|
-
export
|
|
8
|
-
abilities?: string[];
|
|
9
|
-
}> extends Entity<T> {
|
|
12
|
+
export declare abstract class AbleObject<T extends {}> extends Entity<T & AbleObjectData> {
|
|
10
13
|
/**
|
|
11
14
|
* Grant an ability.
|
|
12
15
|
*
|
package/dist/AbleObject.js
CHANGED
|
@@ -4,18 +4,18 @@ import { Entity } from '@nymphjs/nymph';
|
|
|
4
4
|
*
|
|
5
5
|
* Used in entities which support abilities, such as users and groups.
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
7
|
+
export class AbleObject extends Entity {
|
|
8
8
|
/**
|
|
9
9
|
* Grant an ability.
|
|
10
10
|
*
|
|
11
11
|
* @param ability The ability.
|
|
12
12
|
*/
|
|
13
13
|
$grant(ability) {
|
|
14
|
-
if (!Array.isArray(this
|
|
15
|
-
this
|
|
14
|
+
if (!Array.isArray(this.abilities)) {
|
|
15
|
+
this.abilities = [];
|
|
16
16
|
}
|
|
17
|
-
if (!this
|
|
18
|
-
this
|
|
17
|
+
if (!this.abilities.includes(ability)) {
|
|
18
|
+
this.abilities.push(ability);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
@@ -24,14 +24,14 @@ export default class AbleObject extends Entity {
|
|
|
24
24
|
* @param ability The ability.
|
|
25
25
|
*/
|
|
26
26
|
$revoke(ability) {
|
|
27
|
-
if (!Array.isArray(this
|
|
28
|
-
this
|
|
27
|
+
if (!Array.isArray(this.abilities)) {
|
|
28
|
+
this.abilities = [];
|
|
29
29
|
}
|
|
30
30
|
let idx;
|
|
31
31
|
do {
|
|
32
|
-
idx = this
|
|
32
|
+
idx = this.abilities.indexOf(ability);
|
|
33
33
|
if (idx !== -1) {
|
|
34
|
-
this
|
|
34
|
+
this.abilities.splice(idx, 1);
|
|
35
35
|
}
|
|
36
36
|
} while (idx !== -1);
|
|
37
37
|
}
|
package/dist/AbleObject.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbleObject.js","sourceRoot":"","sources":["../src/AbleObject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"AbleObject.js","sourceRoot":"","sources":["../src/AbleObject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAQxC;;;;GAIG;AACH,MAAM,OAAgB,UAAyB,SAAQ,MAEtD;IACC;;;;OAIG;IACI,MAAM,CAAC,OAAe;QAC3B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YACnC,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;QACtB,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YACtC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;IAED;;;;OAIG;IACI,OAAO,CAAC,OAAe;QAC5B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YACnC,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;QACtB,CAAC;QACD,IAAI,GAAW,CAAC;QAChB,GAAG,CAAC;YACF,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACtC,IAAI,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC;gBACf,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;YAChC,CAAC;QACH,CAAC,QAAQ,GAAG,KAAK,CAAC,CAAC,EAAE;IACvB,CAAC;CACF"}
|
package/dist/Group.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import AbleObject from './AbleObject.js';
|
|
3
|
-
import UserClass from './User.js';
|
|
4
|
-
import type { UserData } from './User.js';
|
|
1
|
+
import { type EntityJson, type EntityPatch, type Options, type Selector, type SerializedEntityData } from '@nymphjs/nymph';
|
|
2
|
+
import { AbleObject } from './AbleObject.js';
|
|
3
|
+
import { User as UserClass } from './User.js';
|
|
5
4
|
export type GroupEventType = 'checkGroupname' | 'beforeSave' | 'afterSave' | 'beforeDelete' | 'afterDelete';
|
|
6
5
|
/**
|
|
7
6
|
* This is run when the user has entered an otherwise valid groupname into the
|
|
8
7
|
* signup form. It should return a result, which when false will stop the
|
|
9
8
|
* process and return the included message, disallowing the groupname.
|
|
10
9
|
*/
|
|
11
|
-
export type TilmeldCheckGroupnameCallback = (group: Group
|
|
10
|
+
export type TilmeldCheckGroupnameCallback = (group: Group, data: {
|
|
12
11
|
groupname: string;
|
|
13
12
|
}) => Promise<{
|
|
14
13
|
result: boolean;
|
|
@@ -19,24 +18,24 @@ export type TilmeldCheckGroupnameCallback = (group: Group & GroupData, data: {
|
|
|
19
18
|
*
|
|
20
19
|
* The transaction is available in `group.$nymph`.
|
|
21
20
|
*/
|
|
22
|
-
export type TilmeldBeforeGroupSaveCallback = (group: Group
|
|
21
|
+
export type TilmeldBeforeGroupSaveCallback = (group: Group) => Promise<void>;
|
|
23
22
|
/**
|
|
24
23
|
* This is run before the transaction is committed, and you can perform
|
|
25
24
|
* additional functions on the transaction, which is available in
|
|
26
25
|
* `group.$nymph`.
|
|
27
26
|
*/
|
|
28
|
-
export type TilmeldAfterGroupSaveCallback = (group: Group
|
|
27
|
+
export type TilmeldAfterGroupSaveCallback = (group: Group) => Promise<void>;
|
|
29
28
|
/**
|
|
30
29
|
* The transaction is available in `group.$nymph`.
|
|
31
30
|
*/
|
|
32
|
-
export type TilmeldBeforeGroupDeleteCallback = (group: Group
|
|
31
|
+
export type TilmeldBeforeGroupDeleteCallback = (group: Group) => Promise<void>;
|
|
33
32
|
/**
|
|
34
33
|
* This is run before the transaction is committed, and you can perform
|
|
35
34
|
* additional functions on the transaction, which is available in
|
|
36
35
|
* `group.$nymph`.
|
|
37
36
|
*/
|
|
38
|
-
export type TilmeldAfterGroupDeleteCallback = (group: Group
|
|
39
|
-
export
|
|
37
|
+
export type TilmeldAfterGroupDeleteCallback = (group: Group) => Promise<void>;
|
|
38
|
+
export interface GroupData {
|
|
40
39
|
/**
|
|
41
40
|
* The abilities granted to the group.
|
|
42
41
|
*/
|
|
@@ -64,11 +63,11 @@ export type GroupData = {
|
|
|
64
63
|
/**
|
|
65
64
|
* The group's parent.
|
|
66
65
|
*/
|
|
67
|
-
parent?: Group
|
|
66
|
+
parent?: Group;
|
|
68
67
|
/**
|
|
69
68
|
* If generatePrimary is on, this will be the user who generated this group.
|
|
70
69
|
*/
|
|
71
|
-
user?:
|
|
70
|
+
user?: UserClass | null;
|
|
72
71
|
/**
|
|
73
72
|
* Whether the group can be used.
|
|
74
73
|
*/
|
|
@@ -85,7 +84,9 @@ export type GroupData = {
|
|
|
85
84
|
* Whether this group is a default secondary group for unverified users.
|
|
86
85
|
*/
|
|
87
86
|
unverifiedSecondary?: boolean;
|
|
88
|
-
}
|
|
87
|
+
}
|
|
88
|
+
export interface Group extends GroupData {
|
|
89
|
+
}
|
|
89
90
|
/**
|
|
90
91
|
* A user group data model.
|
|
91
92
|
*
|
|
@@ -95,7 +96,7 @@ export type GroupData = {
|
|
|
95
96
|
* @copyright SciActive Inc
|
|
96
97
|
* @see http://nymph.io/
|
|
97
98
|
*/
|
|
98
|
-
export
|
|
99
|
+
export declare class Group extends AbleObject<GroupData> {
|
|
99
100
|
static ETYPE: string;
|
|
100
101
|
static class: string;
|
|
101
102
|
private static checkGroupnameCallbacks;
|
|
@@ -125,7 +126,7 @@ export default class Group extends AbleObject<GroupData> {
|
|
|
125
126
|
*/
|
|
126
127
|
$originalGroupname?: string;
|
|
127
128
|
static getFTSText(name: string, value: any): string | null;
|
|
128
|
-
static factoryGroupname(groupname?: string): Promise<Group
|
|
129
|
+
static factoryGroupname(groupname?: string): Promise<Group>;
|
|
129
130
|
/**
|
|
130
131
|
* Get all the groups that can be assigned as primary groups.
|
|
131
132
|
*
|
|
@@ -133,7 +134,7 @@ export default class Group extends AbleObject<GroupData> {
|
|
|
133
134
|
* @param selectors The selectors for an optional search query.
|
|
134
135
|
* @returns An array of the assignable primary groups.
|
|
135
136
|
*/
|
|
136
|
-
static getPrimaryGroups(options?: Options, selectors?: Selector[]): Promise<
|
|
137
|
+
static getPrimaryGroups(options?: Options, selectors?: Selector[]): Promise<Group[]>;
|
|
137
138
|
/**
|
|
138
139
|
* Get all the groups that can be assigned as secondary groups.
|
|
139
140
|
*
|
|
@@ -141,7 +142,7 @@ export default class Group extends AbleObject<GroupData> {
|
|
|
141
142
|
* @param selectors The selectors for an optional search query.
|
|
142
143
|
* @returns An array of the assignable secondary groups.
|
|
143
144
|
*/
|
|
144
|
-
static getSecondaryGroups(options?: Options, selectors?: Selector[]): Promise<
|
|
145
|
+
static getSecondaryGroups(options?: Options, selectors?: Selector[]): Promise<Group[]>;
|
|
145
146
|
private static getAssignableGroups;
|
|
146
147
|
constructor();
|
|
147
148
|
$getUniques(): Promise<string[]>;
|
|
@@ -149,26 +150,26 @@ export default class Group extends AbleObject<GroupData> {
|
|
|
149
150
|
$jsonAcceptData(input: EntityJson, allowConflict?: boolean): void;
|
|
150
151
|
$jsonAcceptPatch(patch: EntityPatch, allowConflict?: boolean): void;
|
|
151
152
|
private $checkIncomingAbilities;
|
|
152
|
-
$putData(data:
|
|
153
|
+
$putData(data: GroupData, sdata?: SerializedEntityData, source?: 'server'): void;
|
|
153
154
|
/**
|
|
154
155
|
* Update the data protection arrays for a user.
|
|
155
156
|
*
|
|
156
157
|
* @param givenUser User to update protection for. If undefined, will use the currently logged in user.
|
|
157
158
|
*/
|
|
158
|
-
$updateDataProtection(givenUser?: UserClass
|
|
159
|
+
$updateDataProtection(givenUser?: UserClass): void;
|
|
159
160
|
/**
|
|
160
161
|
* Check whether the group is a descendant of the given group.
|
|
161
162
|
*
|
|
162
163
|
* @param group The group, or the group's GUID.
|
|
163
164
|
* @returns True or false.
|
|
164
165
|
*/
|
|
165
|
-
$isDescendant(givenGroup:
|
|
166
|
+
$isDescendant(givenGroup: Group | string): Promise<boolean>;
|
|
166
167
|
/**
|
|
167
168
|
* Gets an array of the group's child groups.
|
|
168
169
|
*
|
|
169
170
|
* @returns An array of groups.
|
|
170
171
|
*/
|
|
171
|
-
$getChildren(): Promise<
|
|
172
|
+
$getChildren(): Promise<Group[]>;
|
|
172
173
|
/**
|
|
173
174
|
* Gets an array of the group's descendant groups.
|
|
174
175
|
*
|
|
@@ -176,7 +177,7 @@ export default class Group extends AbleObject<GroupData> {
|
|
|
176
177
|
* @param andDisabled Include disabled groups.
|
|
177
178
|
* @returns An array of groups.
|
|
178
179
|
*/
|
|
179
|
-
$getDescendants(andSelf?: boolean, andDisabled?: boolean): Promise<
|
|
180
|
+
$getDescendants(andSelf?: boolean, andDisabled?: boolean): Promise<Group[]>;
|
|
180
181
|
/**
|
|
181
182
|
* Get the number of parents the group has.
|
|
182
183
|
*
|
|
@@ -197,7 +198,7 @@ export default class Group extends AbleObject<GroupData> {
|
|
|
197
198
|
* @param offset The offset for the query.
|
|
198
199
|
* @returns An array of users.
|
|
199
200
|
*/
|
|
200
|
-
$getUsers(descendants?: boolean, limit?: number, offset?: number): Promise<
|
|
201
|
+
$getUsers(descendants?: boolean, limit?: number, offset?: number): Promise<UserClass[]>;
|
|
201
202
|
/**
|
|
202
203
|
* Check that a groupname is valid.
|
|
203
204
|
*
|
package/dist/Group.js
CHANGED
|
@@ -38,9 +38,18 @@ import { nanoid } from '@nymphjs/guid';
|
|
|
38
38
|
import { difference, xor } from 'lodash-es';
|
|
39
39
|
import { splitn } from '@sciactive/splitn';
|
|
40
40
|
import { enforceTilmeld } from './enforceTilmeld.js';
|
|
41
|
-
import AbleObject from './AbleObject.js';
|
|
41
|
+
import { AbleObject } from './AbleObject.js';
|
|
42
42
|
import { AccessControlError, BadDataError, BadEmailError, BadUsernameError, CouldNotChangeDefaultPrimaryGroupError, } from './errors/index.js';
|
|
43
|
-
import UserClass from './User.js';
|
|
43
|
+
import { User as UserClass } from './User.js';
|
|
44
|
+
/**
|
|
45
|
+
* A user group data model.
|
|
46
|
+
*
|
|
47
|
+
* Written by Hunter Perrin for SciActive.
|
|
48
|
+
*
|
|
49
|
+
* @author Hunter Perrin <hperrin@port87.com>
|
|
50
|
+
* @copyright SciActive Inc
|
|
51
|
+
* @see http://nymph.io/
|
|
52
|
+
*/
|
|
44
53
|
let Group = (() => {
|
|
45
54
|
let _classSuper = AbleObject;
|
|
46
55
|
let _instanceExtraInitializers = [];
|
|
@@ -176,33 +185,33 @@ let Group = (() => {
|
|
|
176
185
|
constructor() {
|
|
177
186
|
super();
|
|
178
187
|
// Defaults.
|
|
179
|
-
this
|
|
180
|
-
this
|
|
188
|
+
this.enabled = true;
|
|
189
|
+
this.abilities = [];
|
|
181
190
|
this.$updateDataProtection();
|
|
182
191
|
}
|
|
183
192
|
async $getUniques() {
|
|
184
193
|
const tilmeld = enforceTilmeld(this);
|
|
185
|
-
const uniques = [`u:${this
|
|
194
|
+
const uniques = [`u:${this.groupname}`];
|
|
186
195
|
if (!tilmeld.config.emailUsernames &&
|
|
187
196
|
tilmeld.config.userFields.includes('email')) {
|
|
188
|
-
uniques.push(`e:${this
|
|
197
|
+
uniques.push(`e:${this.email}`);
|
|
189
198
|
}
|
|
190
|
-
if (this
|
|
199
|
+
if (this.defaultPrimary) {
|
|
191
200
|
uniques.push(`o:default-primary`);
|
|
192
201
|
}
|
|
193
202
|
return uniques;
|
|
194
203
|
}
|
|
195
204
|
$getAvatar() {
|
|
196
|
-
if (this
|
|
197
|
-
return this
|
|
205
|
+
if (this.avatar != null && this.avatar !== '') {
|
|
206
|
+
return this.avatar;
|
|
198
207
|
}
|
|
199
|
-
if (this
|
|
208
|
+
if (this.email == null || !this.email.length) {
|
|
200
209
|
return 'https://secure.gravatar.com/avatar/?d=mm&s=40';
|
|
201
210
|
}
|
|
202
211
|
return ('https://secure.gravatar.com/avatar/' +
|
|
203
212
|
crypto
|
|
204
213
|
.createHash('sha256')
|
|
205
|
-
.update(this
|
|
214
|
+
.update(this.email.trim().toLowerCase())
|
|
206
215
|
.digest('hex')
|
|
207
216
|
.toLowerCase() +
|
|
208
217
|
'?d=identicon&s=40');
|
|
@@ -228,24 +237,24 @@ let Group = (() => {
|
|
|
228
237
|
throw new BadDataError('Abilities must be an array of strings.');
|
|
229
238
|
}
|
|
230
239
|
if (incoming.includes('system/admin') !==
|
|
231
|
-
this
|
|
240
|
+
this.abilities?.includes('system/admin') &&
|
|
232
241
|
(!tilmeld.currentUser ||
|
|
233
242
|
!tilmeld.currentUser.abilities?.includes('system/admin'))) {
|
|
234
243
|
throw new BadDataError("You don't have the authority to grant or revoke system/admin.");
|
|
235
244
|
}
|
|
236
245
|
if (incoming.includes('tilmeld/admin') !==
|
|
237
|
-
this
|
|
246
|
+
this.abilities?.includes('tilmeld/admin') &&
|
|
238
247
|
(!tilmeld.currentUser ||
|
|
239
248
|
!tilmeld.currentUser.abilities?.includes('system/admin'))) {
|
|
240
249
|
throw new BadDataError("You don't have the authority to grant or revoke tilmeld/admin.");
|
|
241
250
|
}
|
|
242
251
|
if (incoming.includes('tilmeld/switch') !==
|
|
243
|
-
this
|
|
252
|
+
this.abilities?.includes('tilmeld/switch') &&
|
|
244
253
|
(!tilmeld.currentUser ||
|
|
245
254
|
!tilmeld.currentUser.abilities?.includes('system/admin'))) {
|
|
246
255
|
throw new BadDataError("You don't have the authority to grant or revoke tilmeld/switch.");
|
|
247
256
|
}
|
|
248
|
-
if (xor(incoming.filter((ability) => ability.startsWith('tilmeld/')), this
|
|
257
|
+
if (xor(incoming.filter((ability) => ability.startsWith('tilmeld/')), this.abilities?.filter((ability) => ability.startsWith('tilmeld/')) ?? []).length &&
|
|
249
258
|
(!tilmeld.currentUser ||
|
|
250
259
|
(!tilmeld.currentUser.abilities?.includes('system/admin') &&
|
|
251
260
|
!tilmeld.currentUser.abilities?.includes('tilmeld/admin')))) {
|
|
@@ -256,13 +265,13 @@ let Group = (() => {
|
|
|
256
265
|
super.$putData(data, sdata, source);
|
|
257
266
|
// TODO: Fix these being added by the drivers.
|
|
258
267
|
// @ts-ignore
|
|
259
|
-
delete this
|
|
268
|
+
delete this.acRead;
|
|
260
269
|
// @ts-ignore
|
|
261
|
-
delete this
|
|
270
|
+
delete this.acWrite;
|
|
262
271
|
// @ts-ignore
|
|
263
|
-
delete this
|
|
272
|
+
delete this.acFull;
|
|
264
273
|
if (source === 'server') {
|
|
265
|
-
this.$originalGroupname = this
|
|
274
|
+
this.$originalGroupname = this.groupname;
|
|
266
275
|
}
|
|
267
276
|
this.$updateDataProtection();
|
|
268
277
|
}
|
|
@@ -275,8 +284,8 @@ let Group = (() => {
|
|
|
275
284
|
const tilmeld = enforceTilmeld(this);
|
|
276
285
|
let user = givenUser ?? tilmeld.User.current();
|
|
277
286
|
let [_groupname, domain] = tilmeld.config.domainSupport
|
|
278
|
-
? splitn(this
|
|
279
|
-
: [this
|
|
287
|
+
? splitn(this.groupname ?? '', '@', 2)
|
|
288
|
+
: [this.groupname, null];
|
|
280
289
|
// Lowercase the domain part.
|
|
281
290
|
if (domain) {
|
|
282
291
|
domain = domain.toLowerCase();
|
|
@@ -293,9 +302,9 @@ let Group = (() => {
|
|
|
293
302
|
this.$privateData = [];
|
|
294
303
|
this.$allowlistData = undefined;
|
|
295
304
|
}
|
|
296
|
-
else if (this
|
|
305
|
+
else if (this.user != null &&
|
|
297
306
|
user != null &&
|
|
298
|
-
this
|
|
307
|
+
this.user.guid === user.guid) {
|
|
299
308
|
// Users can see their group's data.
|
|
300
309
|
this.$privateData = [];
|
|
301
310
|
}
|
|
@@ -326,7 +335,7 @@ let Group = (() => {
|
|
|
326
335
|
return false;
|
|
327
336
|
}
|
|
328
337
|
// Check to see if the group is a descendant of the given group.
|
|
329
|
-
const parent = this
|
|
338
|
+
const parent = this.parent;
|
|
330
339
|
await parent?.$wake();
|
|
331
340
|
if (parent == null) {
|
|
332
341
|
return false;
|
|
@@ -423,14 +432,8 @@ let Group = (() => {
|
|
|
423
432
|
ref: [
|
|
424
433
|
['group', this],
|
|
425
434
|
['groups', this],
|
|
426
|
-
...groups.map((group) => [
|
|
427
|
-
|
|
428
|
-
group,
|
|
429
|
-
]),
|
|
430
|
-
...groups.map((group) => [
|
|
431
|
-
'groups',
|
|
432
|
-
group,
|
|
433
|
-
]),
|
|
435
|
+
...groups.map((group) => ['group', group]),
|
|
436
|
+
...groups.map((group) => ['groups', group]),
|
|
434
437
|
],
|
|
435
438
|
});
|
|
436
439
|
}
|
|
@@ -443,15 +446,15 @@ let Group = (() => {
|
|
|
443
446
|
const tilmeld = enforceTilmeld(this);
|
|
444
447
|
if (!tilmeld.config.emailUsernames) {
|
|
445
448
|
let [groupname, domain] = tilmeld.config.domainSupport
|
|
446
|
-
? splitn(this
|
|
447
|
-
: [this
|
|
449
|
+
? splitn(this.groupname ?? '', '@', 2)
|
|
450
|
+
: [this.groupname, null];
|
|
448
451
|
// Lowercase the domain part.
|
|
449
452
|
if (domain) {
|
|
450
453
|
domain = domain.toLowerCase();
|
|
451
|
-
this
|
|
454
|
+
this.groupname = `${groupname}@${domain}`;
|
|
452
455
|
}
|
|
453
|
-
if (this
|
|
454
|
-
!this
|
|
456
|
+
if (this.groupname == null ||
|
|
457
|
+
!this.groupname.length ||
|
|
455
458
|
groupname == null ||
|
|
456
459
|
!groupname.length) {
|
|
457
460
|
return { result: false, message: 'Please specify a groupname.' };
|
|
@@ -504,7 +507,7 @@ let Group = (() => {
|
|
|
504
507
|
type: '&',
|
|
505
508
|
ilike: [
|
|
506
509
|
'groupname',
|
|
507
|
-
this
|
|
510
|
+
this.groupname.replace(/([\\%_])/g, (s) => `\\${s}`),
|
|
508
511
|
],
|
|
509
512
|
};
|
|
510
513
|
if (this.guid != null) {
|
|
@@ -518,7 +521,7 @@ let Group = (() => {
|
|
|
518
521
|
.checkGroupnameCallbacks) {
|
|
519
522
|
if (callback) {
|
|
520
523
|
const result = await callback(this, {
|
|
521
|
-
groupname: this
|
|
524
|
+
groupname: this.groupname,
|
|
522
525
|
});
|
|
523
526
|
if (!result.result) {
|
|
524
527
|
return { message: 'Groupname is not available.', ...result };
|
|
@@ -531,11 +534,11 @@ let Group = (() => {
|
|
|
531
534
|
};
|
|
532
535
|
}
|
|
533
536
|
else {
|
|
534
|
-
this
|
|
535
|
-
if (this
|
|
537
|
+
this.email = this.groupname;
|
|
538
|
+
if (this.groupname == null || !this.groupname.length) {
|
|
536
539
|
return { result: false, message: 'Please specify an email.' };
|
|
537
540
|
}
|
|
538
|
-
if (this
|
|
541
|
+
if (this.groupname.length < tilmeld.config.minUsernameLength) {
|
|
539
542
|
return {
|
|
540
543
|
result: false,
|
|
541
544
|
message: 'Emails must be at least ' +
|
|
@@ -543,7 +546,7 @@ let Group = (() => {
|
|
|
543
546
|
' characters.',
|
|
544
547
|
};
|
|
545
548
|
}
|
|
546
|
-
if (this
|
|
549
|
+
if (this.groupname.length > tilmeld.config.maxUsernameLength) {
|
|
547
550
|
return {
|
|
548
551
|
result: false,
|
|
549
552
|
message: 'Emails must not exceed ' +
|
|
@@ -561,13 +564,13 @@ let Group = (() => {
|
|
|
561
564
|
*/
|
|
562
565
|
async $checkEmail() {
|
|
563
566
|
const tilmeld = enforceTilmeld(this);
|
|
564
|
-
if (this
|
|
567
|
+
if (this.email === '') {
|
|
565
568
|
return { result: true, message: '' };
|
|
566
569
|
}
|
|
567
|
-
if (this
|
|
570
|
+
if (this.email == null) {
|
|
568
571
|
return { result: false, message: 'Please specify a valid email.' };
|
|
569
572
|
}
|
|
570
|
-
if (!tilmeld.config.validEmailRegex.test(this
|
|
573
|
+
if (!tilmeld.config.validEmailRegex.test(this.email)) {
|
|
571
574
|
return {
|
|
572
575
|
result: false,
|
|
573
576
|
message: tilmeld.config.validEmailRegexNotice,
|
|
@@ -575,7 +578,7 @@ let Group = (() => {
|
|
|
575
578
|
}
|
|
576
579
|
const selector = {
|
|
577
580
|
type: '&',
|
|
578
|
-
ilike: ['email', this
|
|
581
|
+
ilike: ['email', this.email.replace(/([\\%_])/g, (s) => `\\${s}`)],
|
|
579
582
|
};
|
|
580
583
|
if (this.guid != null) {
|
|
581
584
|
selector['!guid'] = this.guid;
|
|
@@ -594,18 +597,18 @@ let Group = (() => {
|
|
|
594
597
|
}
|
|
595
598
|
async $save() {
|
|
596
599
|
let tilmeld = enforceTilmeld(this);
|
|
597
|
-
if (this
|
|
600
|
+
if (this.groupname == null || !this.groupname.trim().length) {
|
|
598
601
|
throw new BadUsernameError('Groupname must not be empty.');
|
|
599
602
|
}
|
|
600
603
|
// Lowercase the domain part.
|
|
601
604
|
if (tilmeld.config.domainSupport) {
|
|
602
|
-
const [groupname, domain] = splitn(this
|
|
605
|
+
const [groupname, domain] = splitn(this.groupname ?? '', '@', 2);
|
|
603
606
|
if (domain) {
|
|
604
|
-
this
|
|
607
|
+
this.groupname = `${groupname}@${domain.toLowerCase()}`;
|
|
605
608
|
}
|
|
606
609
|
}
|
|
607
610
|
if (tilmeld.config.domainSupport) {
|
|
608
|
-
const [_groupname, domain] = splitn(this
|
|
611
|
+
const [_groupname, domain] = splitn(this.groupname ?? '', '@', 2);
|
|
609
612
|
const [_originalGroupname, originalDomain] = splitn(this.$originalGroupname ?? '', '@', 2);
|
|
610
613
|
if (this.guid != null &&
|
|
611
614
|
((originalDomain == null && domain != null) ||
|
|
@@ -629,47 +632,45 @@ let Group = (() => {
|
|
|
629
632
|
}
|
|
630
633
|
}
|
|
631
634
|
// Formatting.
|
|
632
|
-
this
|
|
635
|
+
this.groupname = this.groupname.trim();
|
|
633
636
|
if (tilmeld.config.emailUsernames) {
|
|
634
|
-
this
|
|
637
|
+
this.email = this.groupname;
|
|
635
638
|
}
|
|
636
|
-
this
|
|
637
|
-
this
|
|
638
|
-
this
|
|
639
|
-
this
|
|
639
|
+
this.email = (this.email ?? '').trim();
|
|
640
|
+
this.name = (this.name ?? '').trim();
|
|
641
|
+
this.phone = (this.phone ?? '').trim();
|
|
642
|
+
this.enabled = !!this.enabled;
|
|
640
643
|
// Clear empty values.
|
|
641
|
-
if (this
|
|
642
|
-
delete this
|
|
644
|
+
if (this.name === '' || !tilmeld.config.userFields.includes('name')) {
|
|
645
|
+
delete this.name;
|
|
643
646
|
}
|
|
644
|
-
if (this
|
|
645
|
-
|
|
646
|
-
delete this.$data.email;
|
|
647
|
+
if (this.email === '' || !tilmeld.config.userFields.includes('email')) {
|
|
648
|
+
delete this.email;
|
|
647
649
|
}
|
|
648
|
-
if (this
|
|
649
|
-
delete this
|
|
650
|
+
if (this.avatar === '') {
|
|
651
|
+
delete this.avatar;
|
|
650
652
|
}
|
|
651
|
-
if (this
|
|
652
|
-
|
|
653
|
-
delete this.$data.phone;
|
|
653
|
+
if (this.phone === '' || !tilmeld.config.userFields.includes('phone')) {
|
|
654
|
+
delete this.phone;
|
|
654
655
|
}
|
|
655
|
-
if (this
|
|
656
|
-
delete this
|
|
656
|
+
if (this.parent == null) {
|
|
657
|
+
delete this.parent;
|
|
657
658
|
}
|
|
658
|
-
if (this
|
|
659
|
-
delete this
|
|
659
|
+
if (this.user == null) {
|
|
660
|
+
delete this.user;
|
|
660
661
|
}
|
|
661
|
-
if (!this
|
|
662
|
-
delete this
|
|
662
|
+
if (!this.defaultPrimary) {
|
|
663
|
+
delete this.defaultPrimary;
|
|
663
664
|
}
|
|
664
|
-
if (!this
|
|
665
|
-
delete this
|
|
665
|
+
if (!this.defaultSecondary) {
|
|
666
|
+
delete this.defaultSecondary;
|
|
666
667
|
}
|
|
667
|
-
if (!this
|
|
668
|
-
delete this
|
|
668
|
+
if (!this.unverifiedSecondary) {
|
|
669
|
+
delete this.unverifiedSecondary;
|
|
669
670
|
}
|
|
670
671
|
// Groups should never have 'system/admin', 'tilmeld/admin',
|
|
671
672
|
// 'tilmeld/switch', or domain admin abilities.
|
|
672
|
-
this
|
|
673
|
+
this.abilities = (this.abilities ?? []).filter((ability) => {
|
|
673
674
|
if (['system/admin', 'tilmeld/admin', 'tilmeld/switch'].indexOf(ability) !==
|
|
674
675
|
-1) {
|
|
675
676
|
return false;
|
|
@@ -695,7 +696,7 @@ let Group = (() => {
|
|
|
695
696
|
}
|
|
696
697
|
}
|
|
697
698
|
// Validate group parent. Make sure it's not a descendant of this group.
|
|
698
|
-
const parent = this
|
|
699
|
+
const parent = this.parent;
|
|
699
700
|
await parent?.$wake();
|
|
700
701
|
if (parent &&
|
|
701
702
|
(parent.cdate == null ||
|
|
@@ -710,7 +711,7 @@ let Group = (() => {
|
|
|
710
711
|
throw new BadDataError(e?.message);
|
|
711
712
|
}
|
|
712
713
|
// Only one default primary group is allowed.
|
|
713
|
-
if (this
|
|
714
|
+
if (this.defaultPrimary) {
|
|
714
715
|
const currentPrimary = await this.$nymph.getEntity({ class: tilmeld.Group }, { type: '&', truthy: 'defaultPrimary' });
|
|
715
716
|
if (currentPrimary != null && !this.$is(currentPrimary)) {
|
|
716
717
|
currentPrimary.defaultPrimary = false;
|
|
@@ -749,7 +750,7 @@ let Group = (() => {
|
|
|
749
750
|
}, async (nymph, committed) => {
|
|
750
751
|
this.$setNymph(nymph);
|
|
751
752
|
if (committed) {
|
|
752
|
-
this.$originalGroupname = this
|
|
753
|
+
this.$originalGroupname = this.groupname;
|
|
753
754
|
}
|
|
754
755
|
else {
|
|
755
756
|
this.guid = preGuid;
|
|
@@ -778,7 +779,7 @@ let Group = (() => {
|
|
|
778
779
|
if (!this.$skipAcWhenDeleting && !tilmeld.gatekeeper('tilmeld/admin')) {
|
|
779
780
|
throw new AccessControlError("You don't have the authority to delete groups.");
|
|
780
781
|
}
|
|
781
|
-
if (this
|
|
782
|
+
if (this.groupname !== this.$originalGroupname) {
|
|
782
783
|
throw new AccessControlError("You can't delete a group while switching its groupname.");
|
|
783
784
|
}
|
|
784
785
|
for (let callback of this.constructor
|
|
@@ -868,14 +869,5 @@ let Group = (() => {
|
|
|
868
869
|
}
|
|
869
870
|
};
|
|
870
871
|
})();
|
|
871
|
-
|
|
872
|
-
* A user group data model.
|
|
873
|
-
*
|
|
874
|
-
* Written by Hunter Perrin for SciActive.
|
|
875
|
-
*
|
|
876
|
-
* @author Hunter Perrin <hperrin@port87.com>
|
|
877
|
-
* @copyright SciActive Inc
|
|
878
|
-
* @see http://nymph.io/
|
|
879
|
-
*/
|
|
880
|
-
export default Group;
|
|
872
|
+
export { Group };
|
|
881
873
|
//# sourceMappingURL=Group.js.map
|