@nymphjs/tilmeld 1.0.0-beta.90 → 1.0.0-beta.91
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/Group.d.ts +41 -0
- package/dist/Group.js +90 -6
- package/dist/Group.js.map +1 -1
- package/dist/Tilmeld.d.ts +2 -0
- package/dist/Tilmeld.js +2 -0
- package/dist/Tilmeld.js.map +1 -1
- package/dist/User.d.ts +38 -8
- package/dist/User.js +76 -26
- package/dist/User.js.map +1 -1
- package/package.json +7 -7
- package/src/Group.ts +189 -6
- package/src/Tilmeld.ts +2 -0
- package/src/User.ts +188 -69
package/src/Group.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type {
|
|
|
8
8
|
Selector,
|
|
9
9
|
SerializedEntityData,
|
|
10
10
|
} from '@nymphjs/nymph';
|
|
11
|
+
import { nanoid } from '@nymphjs/guid';
|
|
11
12
|
import { difference, xor } from 'lodash-es';
|
|
12
13
|
import { splitn } from '@sciactive/splitn';
|
|
13
14
|
|
|
@@ -23,6 +24,52 @@ import {
|
|
|
23
24
|
import UserClass from './User.js';
|
|
24
25
|
import type { UserData } from './User.js';
|
|
25
26
|
|
|
27
|
+
export type GroupEventType =
|
|
28
|
+
| 'checkGroupname'
|
|
29
|
+
| 'beforeSave'
|
|
30
|
+
| 'afterSave'
|
|
31
|
+
| 'beforeDelete'
|
|
32
|
+
| 'afterDelete';
|
|
33
|
+
/**
|
|
34
|
+
* This is run when the user has entered an otherwise valid groupname into the
|
|
35
|
+
* signup form. It should return a result, which when false will stop the
|
|
36
|
+
* process and return the included message, disallowing the groupname.
|
|
37
|
+
*/
|
|
38
|
+
export type TilmeldCheckGroupnameCallback = (
|
|
39
|
+
group: Group & GroupData,
|
|
40
|
+
data: { groupname: string },
|
|
41
|
+
) => Promise<{ result: boolean; message?: string }>;
|
|
42
|
+
/**
|
|
43
|
+
* This is run just before the group is saved, so all checks have passed.
|
|
44
|
+
*
|
|
45
|
+
* The transaction is available in `group.$nymph`.
|
|
46
|
+
*/
|
|
47
|
+
export type TilmeldBeforeGroupSaveCallback = (
|
|
48
|
+
group: Group & GroupData,
|
|
49
|
+
) => Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* This is run before the transaction is committed, and you can perform
|
|
52
|
+
* additional functions on the transaction, which is available in
|
|
53
|
+
* `group.$nymph`.
|
|
54
|
+
*/
|
|
55
|
+
export type TilmeldAfterGroupSaveCallback = (
|
|
56
|
+
group: Group & GroupData,
|
|
57
|
+
) => Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* The transaction is available in `group.$nymph`.
|
|
60
|
+
*/
|
|
61
|
+
export type TilmeldBeforeGroupDeleteCallback = (
|
|
62
|
+
group: Group & GroupData,
|
|
63
|
+
) => Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* This is run before the transaction is committed, and you can perform
|
|
66
|
+
* additional functions on the transaction, which is available in
|
|
67
|
+
* `group.$nymph`.
|
|
68
|
+
*/
|
|
69
|
+
export type TilmeldAfterGroupDeleteCallback = (
|
|
70
|
+
group: Group & GroupData,
|
|
71
|
+
) => Promise<void>;
|
|
72
|
+
|
|
26
73
|
export type GroupData = {
|
|
27
74
|
/**
|
|
28
75
|
* The abilities granted to the group.
|
|
@@ -90,6 +137,11 @@ export default class Group extends AbleObject<GroupData> {
|
|
|
90
137
|
*/
|
|
91
138
|
static ETYPE = 'tilmeld_group';
|
|
92
139
|
static class = 'Group';
|
|
140
|
+
private static checkGroupnameCallbacks: TilmeldCheckGroupnameCallback[] = [];
|
|
141
|
+
private static beforeSaveCallbacks: TilmeldBeforeGroupSaveCallback[] = [];
|
|
142
|
+
private static afterSaveCallbacks: TilmeldAfterGroupSaveCallback[] = [];
|
|
143
|
+
private static beforeDeleteCallbacks: TilmeldBeforeGroupDeleteCallback[] = [];
|
|
144
|
+
private static afterDeleteCallbacks: TilmeldAfterGroupDeleteCallback[] = [];
|
|
93
145
|
|
|
94
146
|
private static DEFAULT_PRIVATE_DATA = ['email', 'phone', 'abilities', 'user'];
|
|
95
147
|
private static DEFAULT_ALLOWLIST_DATA: string[] = [];
|
|
@@ -677,6 +729,18 @@ export default class Group extends AbleObject<GroupData> {
|
|
|
677
729
|
return { result: false, message: 'That groupname is taken.' };
|
|
678
730
|
}
|
|
679
731
|
|
|
732
|
+
for (let callback of (this.constructor as typeof Group)
|
|
733
|
+
.checkGroupnameCallbacks) {
|
|
734
|
+
if (callback) {
|
|
735
|
+
const result = await callback(this, {
|
|
736
|
+
groupname: this.$data.groupname,
|
|
737
|
+
});
|
|
738
|
+
if (!result.result) {
|
|
739
|
+
return { message: 'Groupname is not available.', ...result };
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
|
|
680
744
|
return {
|
|
681
745
|
result: true,
|
|
682
746
|
message:
|
|
@@ -755,7 +819,7 @@ export default class Group extends AbleObject<GroupData> {
|
|
|
755
819
|
}
|
|
756
820
|
|
|
757
821
|
public async $save() {
|
|
758
|
-
|
|
822
|
+
let tilmeld = enforceTilmeld(this);
|
|
759
823
|
if (this.$data.groupname == null || !this.$data.groupname.trim().length) {
|
|
760
824
|
return false;
|
|
761
825
|
}
|
|
@@ -932,11 +996,45 @@ export default class Group extends AbleObject<GroupData> {
|
|
|
932
996
|
}
|
|
933
997
|
}
|
|
934
998
|
|
|
935
|
-
const
|
|
936
|
-
|
|
937
|
-
|
|
999
|
+
const transaction = 'tilmeld-save-group-' + (this.guid || nanoid());
|
|
1000
|
+
const nymph = this.$nymph;
|
|
1001
|
+
const tnymph = await nymph.startTransaction(transaction);
|
|
1002
|
+
this.$setNymph(tnymph);
|
|
1003
|
+
tilmeld = enforceTilmeld(this);
|
|
1004
|
+
|
|
1005
|
+
let preGuid = this.guid;
|
|
1006
|
+
let preCdate = this.cdate;
|
|
1007
|
+
let preMdate = this.mdate;
|
|
1008
|
+
|
|
1009
|
+
try {
|
|
1010
|
+
for (let callback of (this.constructor as typeof Group)
|
|
1011
|
+
.beforeSaveCallbacks) {
|
|
1012
|
+
if (callback) {
|
|
1013
|
+
await callback(this);
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
let ret = await super.$save();
|
|
1018
|
+
if (ret) {
|
|
1019
|
+
this.$originalGroupname = this.$data.groupname;
|
|
1020
|
+
}
|
|
1021
|
+
for (let callback of (this.constructor as typeof Group)
|
|
1022
|
+
.afterSaveCallbacks) {
|
|
1023
|
+
if (callback) {
|
|
1024
|
+
await callback(this);
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
ret = await tnymph.commit(transaction);
|
|
1028
|
+
this.$setNymph(nymph);
|
|
1029
|
+
return ret;
|
|
1030
|
+
} catch (e: any) {
|
|
1031
|
+
await tnymph.rollback(transaction);
|
|
1032
|
+
this.guid = preGuid;
|
|
1033
|
+
this.cdate = preCdate;
|
|
1034
|
+
this.mdate = preMdate;
|
|
1035
|
+
this.$setNymph(nymph);
|
|
1036
|
+
throw e;
|
|
938
1037
|
}
|
|
939
|
-
return ret;
|
|
940
1038
|
}
|
|
941
1039
|
|
|
942
1040
|
/*
|
|
@@ -968,7 +1066,7 @@ export default class Group extends AbleObject<GroupData> {
|
|
|
968
1066
|
);
|
|
969
1067
|
}
|
|
970
1068
|
|
|
971
|
-
const transaction = 'tilmeld-delete-' + this.guid;
|
|
1069
|
+
const transaction = 'tilmeld-delete-group-' + this.guid;
|
|
972
1070
|
const nymph = this.$nymph;
|
|
973
1071
|
const tnymph = await nymph.startTransaction(transaction);
|
|
974
1072
|
this.$setNymph(tnymph);
|
|
@@ -976,6 +1074,13 @@ export default class Group extends AbleObject<GroupData> {
|
|
|
976
1074
|
const User = tnymph.getEntityClass(UserClass);
|
|
977
1075
|
|
|
978
1076
|
try {
|
|
1077
|
+
for (let callback of (this.constructor as typeof Group)
|
|
1078
|
+
.beforeDeleteCallbacks) {
|
|
1079
|
+
if (callback) {
|
|
1080
|
+
await callback(this);
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
|
|
979
1084
|
// Delete descendants.
|
|
980
1085
|
const descendants = await this.$getDescendants();
|
|
981
1086
|
if (descendants.length) {
|
|
@@ -1035,6 +1140,7 @@ export default class Group extends AbleObject<GroupData> {
|
|
|
1035
1140
|
: !(await user.$save())
|
|
1036
1141
|
) {
|
|
1037
1142
|
await tnymph.rollback(transaction);
|
|
1143
|
+
this.$setNymph(nymph);
|
|
1038
1144
|
return false;
|
|
1039
1145
|
}
|
|
1040
1146
|
}
|
|
@@ -1042,6 +1148,13 @@ export default class Group extends AbleObject<GroupData> {
|
|
|
1042
1148
|
// Delete the group.
|
|
1043
1149
|
let success = await super.$delete();
|
|
1044
1150
|
if (success) {
|
|
1151
|
+
for (let callback of (this.constructor as typeof Group)
|
|
1152
|
+
.afterDeleteCallbacks) {
|
|
1153
|
+
if (callback) {
|
|
1154
|
+
await callback(this);
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1045
1158
|
success = await tnymph.commit(transaction);
|
|
1046
1159
|
} else {
|
|
1047
1160
|
await tnymph.rollback(transaction);
|
|
@@ -1070,4 +1183,74 @@ export default class Group extends AbleObject<GroupData> {
|
|
|
1070
1183
|
}
|
|
1071
1184
|
return false;
|
|
1072
1185
|
}
|
|
1186
|
+
|
|
1187
|
+
public static on<T extends GroupEventType>(
|
|
1188
|
+
event: T,
|
|
1189
|
+
callback: T extends 'checkGroupname'
|
|
1190
|
+
? TilmeldCheckGroupnameCallback
|
|
1191
|
+
: T extends 'beforeSave'
|
|
1192
|
+
? TilmeldBeforeGroupSaveCallback
|
|
1193
|
+
: T extends 'afterSave'
|
|
1194
|
+
? TilmeldAfterGroupSaveCallback
|
|
1195
|
+
: T extends 'beforeDelete'
|
|
1196
|
+
? TilmeldBeforeGroupDeleteCallback
|
|
1197
|
+
: T extends 'afterDelete'
|
|
1198
|
+
? TilmeldAfterGroupDeleteCallback
|
|
1199
|
+
: never,
|
|
1200
|
+
) {
|
|
1201
|
+
const prop = (event + 'Callbacks') as T extends 'checkGroupname'
|
|
1202
|
+
? 'checkGroupnameCallbacks'
|
|
1203
|
+
: T extends 'beforeSave'
|
|
1204
|
+
? 'beforeSaveCallbacks'
|
|
1205
|
+
: T extends 'afterSave'
|
|
1206
|
+
? 'afterSaveCallbacks'
|
|
1207
|
+
: T extends 'beforeDelete'
|
|
1208
|
+
? 'beforeDeleteCallbacks'
|
|
1209
|
+
: T extends 'afterDelete'
|
|
1210
|
+
? 'afterDeleteCallbacks'
|
|
1211
|
+
: never;
|
|
1212
|
+
if (!(prop in this)) {
|
|
1213
|
+
throw new Error('Invalid event type.');
|
|
1214
|
+
}
|
|
1215
|
+
// @ts-ignore: The callback should always be the right type here.
|
|
1216
|
+
this[prop].push(callback);
|
|
1217
|
+
return () => this.off(event, callback);
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
public static off<T extends GroupEventType>(
|
|
1221
|
+
event: T,
|
|
1222
|
+
callback: T extends 'checkGroupname'
|
|
1223
|
+
? TilmeldCheckGroupnameCallback
|
|
1224
|
+
: T extends 'beforeSave'
|
|
1225
|
+
? TilmeldBeforeGroupSaveCallback
|
|
1226
|
+
: T extends 'afterSave'
|
|
1227
|
+
? TilmeldAfterGroupSaveCallback
|
|
1228
|
+
: T extends 'beforeDelete'
|
|
1229
|
+
? TilmeldBeforeGroupDeleteCallback
|
|
1230
|
+
: T extends 'afterDelete'
|
|
1231
|
+
? TilmeldAfterGroupDeleteCallback
|
|
1232
|
+
: never,
|
|
1233
|
+
) {
|
|
1234
|
+
const prop = (event + 'Callbacks') as T extends 'checkGroupname'
|
|
1235
|
+
? 'checkGroupnameCallbacks'
|
|
1236
|
+
: T extends 'beforeSave'
|
|
1237
|
+
? 'beforeSaveCallbacks'
|
|
1238
|
+
: T extends 'afterSave'
|
|
1239
|
+
? 'afterSaveCallbacks'
|
|
1240
|
+
: T extends 'beforeDelete'
|
|
1241
|
+
? 'beforeDeleteCallbacks'
|
|
1242
|
+
: T extends 'afterDelete'
|
|
1243
|
+
? 'afterDeleteCallbacks'
|
|
1244
|
+
: never;
|
|
1245
|
+
if (!(prop in this)) {
|
|
1246
|
+
return false;
|
|
1247
|
+
}
|
|
1248
|
+
// @ts-ignore: The callback should always be the right type here.
|
|
1249
|
+
const i = this[prop].indexOf(callback);
|
|
1250
|
+
if (i > -1) {
|
|
1251
|
+
// @ts-ignore: The callback should always be the right type here.
|
|
1252
|
+
this[prop].splice(i, 1);
|
|
1253
|
+
}
|
|
1254
|
+
return true;
|
|
1255
|
+
}
|
|
1073
1256
|
}
|
package/src/Tilmeld.ts
CHANGED
|
@@ -696,6 +696,8 @@ export default class Tilmeld implements TilmeldInterface {
|
|
|
696
696
|
* whether the check passes:
|
|
697
697
|
*
|
|
698
698
|
* - It is a user or group. (True for READ_ACCESS or Tilmeld admins.)
|
|
699
|
+
* - It is a user or group that belongs to a domain the current user is an
|
|
700
|
+
* admin for, and domain support is enabled. (Always true.)
|
|
699
701
|
* - No user is logged in. (Check other AC.)
|
|
700
702
|
* - The entity is the user. (Always true.)
|
|
701
703
|
* - It is the user's primary group. (True for READ_ACCESS.)
|
package/src/User.ts
CHANGED
|
@@ -31,10 +31,14 @@ export type EventType =
|
|
|
31
31
|
| 'checkUsername'
|
|
32
32
|
| 'beforeRegister'
|
|
33
33
|
| 'afterRegister'
|
|
34
|
+
| 'beforeSave'
|
|
35
|
+
| 'afterSave'
|
|
34
36
|
| 'beforeLogin'
|
|
35
37
|
| 'afterLogin'
|
|
36
38
|
| 'beforeLogout'
|
|
37
|
-
| 'afterLogout'
|
|
39
|
+
| 'afterLogout'
|
|
40
|
+
| 'beforeDelete'
|
|
41
|
+
| 'afterDelete';
|
|
38
42
|
/**
|
|
39
43
|
* This is run when the user has entered an otherwise valid username into the
|
|
40
44
|
* signup form. It should return a result, which when false will stop the
|
|
@@ -45,19 +49,39 @@ export type TilmeldCheckUsernameCallback = (
|
|
|
45
49
|
data: { username: string },
|
|
46
50
|
) => Promise<{ result: boolean; message?: string }>;
|
|
47
51
|
/**
|
|
48
|
-
*
|
|
52
|
+
* This is run before the user data checks, so the only checks before are
|
|
49
53
|
* whether registration is allowed and whether the user is already registered.
|
|
50
54
|
*/
|
|
51
55
|
export type TilmeldBeforeRegisterCallback = (
|
|
52
56
|
user: User & UserData,
|
|
53
57
|
data: { password: string; additionalData?: { [k: string]: any } },
|
|
54
58
|
) => Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* This is run before the transaction is committed, and you can perform
|
|
61
|
+
* additional functions on the transaction, which is available in `user.$nymph`.
|
|
62
|
+
*/
|
|
55
63
|
export type TilmeldAfterRegisterCallback = (
|
|
56
64
|
user: User & UserData,
|
|
57
65
|
result: { loggedin: boolean; message: string },
|
|
58
66
|
) => Promise<void>;
|
|
59
67
|
/**
|
|
60
|
-
*
|
|
68
|
+
* This is run just before the user is saved, so all checks have passed.
|
|
69
|
+
*
|
|
70
|
+
* The transaction is available in `user.$nymph`.
|
|
71
|
+
*/
|
|
72
|
+
export type TilmeldBeforeSaveCallback = (
|
|
73
|
+
user: User & UserData,
|
|
74
|
+
) => Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* This is run before the transaction is committed, and you can perform
|
|
77
|
+
* additional functions on the transaction, which is available in `user.$nymph`.
|
|
78
|
+
*
|
|
79
|
+
* This is run after a new email verification email has been sent, so throwing
|
|
80
|
+
* an error will cause confusion for the user if they've changed their email.
|
|
81
|
+
*/
|
|
82
|
+
export type TilmeldAfterSaveCallback = (user: User & UserData) => Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* This is run after the authentication checks, but before the login action.
|
|
61
85
|
*/
|
|
62
86
|
export type TilmeldBeforeLoginCallback = (
|
|
63
87
|
user: User & UserData,
|
|
@@ -67,10 +91,6 @@ export type TilmeldBeforeLoginCallback = (
|
|
|
67
91
|
additionalData?: { [k: string]: any };
|
|
68
92
|
},
|
|
69
93
|
) => Promise<void>;
|
|
70
|
-
/**
|
|
71
|
-
* This is run before the transaction is committed, and you can perform
|
|
72
|
-
* additional functions on the transaction, which is available in `user.$nymph`.
|
|
73
|
-
*/
|
|
74
94
|
export type TilmeldAfterLoginCallback = (
|
|
75
95
|
user: User & UserData,
|
|
76
96
|
) => Promise<void>;
|
|
@@ -80,6 +100,22 @@ export type TilmeldBeforeLogoutCallback = (
|
|
|
80
100
|
export type TilmeldAfterLogoutCallback = (
|
|
81
101
|
user: User & UserData,
|
|
82
102
|
) => Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* This is run before the user is logged out (if the current user is being
|
|
105
|
+
* deleted).
|
|
106
|
+
*
|
|
107
|
+
* The transaction is available in `user.$nymph`.
|
|
108
|
+
*/
|
|
109
|
+
export type TilmeldBeforeDeleteCallback = (
|
|
110
|
+
user: User & UserData,
|
|
111
|
+
) => Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* This is run before the transaction is committed, and you can perform
|
|
114
|
+
* additional functions on the transaction, which is available in `user.$nymph`.
|
|
115
|
+
*/
|
|
116
|
+
export type TilmeldAfterDeleteCallback = (
|
|
117
|
+
user: User & UserData,
|
|
118
|
+
) => Promise<void>;
|
|
83
119
|
|
|
84
120
|
export type UserData = {
|
|
85
121
|
/**
|
|
@@ -211,10 +247,14 @@ export default class User extends AbleObject<UserData> {
|
|
|
211
247
|
private static checkUsernameCallbacks: TilmeldCheckUsernameCallback[] = [];
|
|
212
248
|
private static beforeRegisterCallbacks: TilmeldBeforeRegisterCallback[] = [];
|
|
213
249
|
private static afterRegisterCallbacks: TilmeldAfterRegisterCallback[] = [];
|
|
250
|
+
private static beforeSaveCallbacks: TilmeldBeforeSaveCallback[] = [];
|
|
251
|
+
private static afterSaveCallbacks: TilmeldAfterSaveCallback[] = [];
|
|
214
252
|
private static beforeLoginCallbacks: TilmeldBeforeLoginCallback[] = [];
|
|
215
253
|
private static afterLoginCallbacks: TilmeldAfterLoginCallback[] = [];
|
|
216
254
|
private static beforeLogoutCallbacks: TilmeldBeforeLogoutCallback[] = [];
|
|
217
255
|
private static afterLogoutCallbacks: TilmeldAfterLogoutCallback[] = [];
|
|
256
|
+
private static beforeDeleteCallbacks: TilmeldBeforeDeleteCallback[] = [];
|
|
257
|
+
private static afterDeleteCallbacks: TilmeldAfterDeleteCallback[] = [];
|
|
218
258
|
|
|
219
259
|
private static DEFAULT_CLIENT_ENABLED_METHODS = [
|
|
220
260
|
'$checkUsername',
|
|
@@ -2504,7 +2544,7 @@ export default class User extends AbleObject<UserData> {
|
|
|
2504
2544
|
}
|
|
2505
2545
|
|
|
2506
2546
|
// Start transaction.
|
|
2507
|
-
const transaction = 'tilmeld-save-' + nanoid();
|
|
2547
|
+
const transaction = 'tilmeld-save-user-' + (this.guid || nanoid());
|
|
2508
2548
|
const nymph = this.$nymph;
|
|
2509
2549
|
const tnymph = await this.$nymph.startTransaction(transaction);
|
|
2510
2550
|
this.$setNymph(tnymph);
|
|
@@ -2628,6 +2668,13 @@ export default class User extends AbleObject<UserData> {
|
|
|
2628
2668
|
let preMdate = this.mdate;
|
|
2629
2669
|
|
|
2630
2670
|
try {
|
|
2671
|
+
for (let callback of (this.constructor as typeof User)
|
|
2672
|
+
.beforeSaveCallbacks) {
|
|
2673
|
+
if (callback) {
|
|
2674
|
+
await callback(this);
|
|
2675
|
+
}
|
|
2676
|
+
}
|
|
2677
|
+
|
|
2631
2678
|
ret = await super.$save();
|
|
2632
2679
|
} catch (e: any) {
|
|
2633
2680
|
await tnymph.rollback(transaction);
|
|
@@ -2653,6 +2700,23 @@ export default class User extends AbleObject<UserData> {
|
|
|
2653
2700
|
|
|
2654
2701
|
this.$descendantGroups = undefined;
|
|
2655
2702
|
this.$gatekeeperCache = undefined;
|
|
2703
|
+
|
|
2704
|
+
try {
|
|
2705
|
+
for (let callback of (this.constructor as typeof User)
|
|
2706
|
+
.afterSaveCallbacks) {
|
|
2707
|
+
if (callback) {
|
|
2708
|
+
await callback(this);
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2711
|
+
} catch (e: any) {
|
|
2712
|
+
await tnymph.rollback(transaction);
|
|
2713
|
+
this.guid = preGuid;
|
|
2714
|
+
this.cdate = preCdate;
|
|
2715
|
+
this.mdate = preMdate;
|
|
2716
|
+
this.$setNymph(nymph);
|
|
2717
|
+
throw e;
|
|
2718
|
+
}
|
|
2719
|
+
|
|
2656
2720
|
ret = await tnymph.commit(transaction);
|
|
2657
2721
|
} else {
|
|
2658
2722
|
await tnymph.rollback(transaction);
|
|
@@ -2712,42 +2776,65 @@ export default class User extends AbleObject<UserData> {
|
|
|
2712
2776
|
);
|
|
2713
2777
|
}
|
|
2714
2778
|
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2779
|
+
const transaction = 'tilmeld-delete-user-' + this.guid;
|
|
2780
|
+
const nymph = this.$nymph;
|
|
2781
|
+
const tnymph = await nymph.startTransaction(transaction);
|
|
2782
|
+
this.$setNymph(tnymph);
|
|
2718
2783
|
|
|
2719
|
-
|
|
2720
|
-
const transaction = 'tilmeld-delete-' + this.guid;
|
|
2721
|
-
const nymph = this.$nymph;
|
|
2722
|
-
const tnymph = await nymph.startTransaction(transaction);
|
|
2723
|
-
this.$setNymph(tnymph);
|
|
2784
|
+
let success = false;
|
|
2724
2785
|
|
|
2725
|
-
|
|
2726
|
-
|
|
2786
|
+
try {
|
|
2787
|
+
for (let callback of (this.constructor as typeof User)
|
|
2788
|
+
.beforeDeleteCallbacks) {
|
|
2789
|
+
if (callback) {
|
|
2790
|
+
await callback(this);
|
|
2791
|
+
}
|
|
2792
|
+
}
|
|
2727
2793
|
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
if (!success) {
|
|
2731
|
-
await tnymph.rollback(transaction);
|
|
2732
|
-
this.$setNymph(nymph);
|
|
2733
|
-
return success;
|
|
2794
|
+
if (tilmeld.User.current(true).$is(this)) {
|
|
2795
|
+
await this.$logout();
|
|
2734
2796
|
}
|
|
2735
2797
|
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
: await this.$data.group.$delete();
|
|
2798
|
+
if (this.$data.group != null && this.$is(this.$data.group.user)) {
|
|
2799
|
+
// Read the skip ac value here, because super.$delete changes it.
|
|
2800
|
+
const $skipAcWhenDeleting = this.$skipAcWhenDeleting;
|
|
2740
2801
|
|
|
2741
|
-
|
|
2742
|
-
success = await
|
|
2802
|
+
// Delete the user.
|
|
2803
|
+
success = await super.$delete();
|
|
2804
|
+
if (success) {
|
|
2805
|
+
// Delete the generated group.
|
|
2806
|
+
success = $skipAcWhenDeleting
|
|
2807
|
+
? await this.$data.group.$deleteSkipAC()
|
|
2808
|
+
: await this.$data.group.$delete();
|
|
2809
|
+
}
|
|
2743
2810
|
} else {
|
|
2744
|
-
await
|
|
2811
|
+
success = await super.$delete();
|
|
2745
2812
|
}
|
|
2813
|
+
} catch (e: any) {
|
|
2814
|
+
await tnymph.rollback(transaction);
|
|
2746
2815
|
this.$setNymph(nymph);
|
|
2747
|
-
|
|
2816
|
+
throw e;
|
|
2817
|
+
}
|
|
2818
|
+
|
|
2819
|
+
if (success) {
|
|
2820
|
+
try {
|
|
2821
|
+
for (let callback of (this.constructor as typeof User)
|
|
2822
|
+
.afterDeleteCallbacks) {
|
|
2823
|
+
if (callback) {
|
|
2824
|
+
await callback(this);
|
|
2825
|
+
}
|
|
2826
|
+
}
|
|
2827
|
+
} catch (e: any) {
|
|
2828
|
+
await tnymph.rollback(transaction);
|
|
2829
|
+
this.$setNymph(nymph);
|
|
2830
|
+
throw e;
|
|
2831
|
+
}
|
|
2832
|
+
success = await tnymph.commit(transaction);
|
|
2748
2833
|
} else {
|
|
2749
|
-
|
|
2834
|
+
await tnymph.rollback(transaction);
|
|
2750
2835
|
}
|
|
2836
|
+
this.$setNymph(nymph);
|
|
2837
|
+
return success;
|
|
2751
2838
|
}
|
|
2752
2839
|
|
|
2753
2840
|
/*
|
|
@@ -2774,15 +2861,23 @@ export default class User extends AbleObject<UserData> {
|
|
|
2774
2861
|
? TilmeldBeforeRegisterCallback
|
|
2775
2862
|
: T extends 'afterRegister'
|
|
2776
2863
|
? TilmeldAfterRegisterCallback
|
|
2777
|
-
: T extends '
|
|
2778
|
-
?
|
|
2779
|
-
: T extends '
|
|
2780
|
-
?
|
|
2781
|
-
: T extends '
|
|
2782
|
-
?
|
|
2783
|
-
: T extends '
|
|
2784
|
-
?
|
|
2785
|
-
:
|
|
2864
|
+
: T extends 'beforeSave'
|
|
2865
|
+
? TilmeldBeforeSaveCallback
|
|
2866
|
+
: T extends 'afterSave'
|
|
2867
|
+
? TilmeldAfterSaveCallback
|
|
2868
|
+
: T extends 'beforeLogin'
|
|
2869
|
+
? TilmeldBeforeLoginCallback
|
|
2870
|
+
: T extends 'afterLogin'
|
|
2871
|
+
? TilmeldAfterLoginCallback
|
|
2872
|
+
: T extends 'beforeLogout'
|
|
2873
|
+
? TilmeldBeforeLogoutCallback
|
|
2874
|
+
: T extends 'afterLogout'
|
|
2875
|
+
? TilmeldAfterLogoutCallback
|
|
2876
|
+
: T extends 'beforeDelete'
|
|
2877
|
+
? TilmeldBeforeDeleteCallback
|
|
2878
|
+
: T extends 'afterDelete'
|
|
2879
|
+
? TilmeldAfterDeleteCallback
|
|
2880
|
+
: never,
|
|
2786
2881
|
) {
|
|
2787
2882
|
const prop = (event + 'Callbacks') as T extends 'checkUsername'
|
|
2788
2883
|
? 'checkUsernameCallbacks'
|
|
@@ -2790,15 +2885,23 @@ export default class User extends AbleObject<UserData> {
|
|
|
2790
2885
|
? 'beforeRegisterCallbacks'
|
|
2791
2886
|
: T extends 'afterRegister'
|
|
2792
2887
|
? 'afterRegisterCallbacks'
|
|
2793
|
-
: T extends '
|
|
2794
|
-
? '
|
|
2795
|
-
: T extends '
|
|
2796
|
-
? '
|
|
2797
|
-
: T extends '
|
|
2798
|
-
? '
|
|
2799
|
-
: T extends '
|
|
2800
|
-
? '
|
|
2801
|
-
:
|
|
2888
|
+
: T extends 'beforeSave'
|
|
2889
|
+
? 'beforeSaveCallbacks'
|
|
2890
|
+
: T extends 'afterSave'
|
|
2891
|
+
? 'afterSaveCallbacks'
|
|
2892
|
+
: T extends 'beforeLogin'
|
|
2893
|
+
? 'beforeLoginCallbacks'
|
|
2894
|
+
: T extends 'afterLogin'
|
|
2895
|
+
? 'afterLoginCallbacks'
|
|
2896
|
+
: T extends 'beforeLogout'
|
|
2897
|
+
? 'beforeLogoutCallbacks'
|
|
2898
|
+
: T extends 'afterLogout'
|
|
2899
|
+
? 'afterLogoutCallbacks'
|
|
2900
|
+
: T extends 'beforeDelete'
|
|
2901
|
+
? 'beforeDeleteCallbacks'
|
|
2902
|
+
: T extends 'afterDelete'
|
|
2903
|
+
? 'afterDeleteCallbacks'
|
|
2904
|
+
: never;
|
|
2802
2905
|
if (!(prop in this)) {
|
|
2803
2906
|
throw new Error('Invalid event type.');
|
|
2804
2907
|
}
|
|
@@ -2815,15 +2918,23 @@ export default class User extends AbleObject<UserData> {
|
|
|
2815
2918
|
? TilmeldBeforeRegisterCallback
|
|
2816
2919
|
: T extends 'afterRegister'
|
|
2817
2920
|
? TilmeldAfterRegisterCallback
|
|
2818
|
-
: T extends '
|
|
2819
|
-
?
|
|
2820
|
-
: T extends '
|
|
2821
|
-
?
|
|
2822
|
-
: T extends '
|
|
2823
|
-
?
|
|
2824
|
-
: T extends '
|
|
2825
|
-
?
|
|
2826
|
-
:
|
|
2921
|
+
: T extends 'beforeSave'
|
|
2922
|
+
? TilmeldBeforeSaveCallback
|
|
2923
|
+
: T extends 'afterSave'
|
|
2924
|
+
? TilmeldAfterSaveCallback
|
|
2925
|
+
: T extends 'beforeLogin'
|
|
2926
|
+
? TilmeldBeforeLoginCallback
|
|
2927
|
+
: T extends 'afterLogin'
|
|
2928
|
+
? TilmeldAfterLoginCallback
|
|
2929
|
+
: T extends 'beforeLogout'
|
|
2930
|
+
? TilmeldBeforeLogoutCallback
|
|
2931
|
+
: T extends 'afterLogout'
|
|
2932
|
+
? TilmeldAfterLogoutCallback
|
|
2933
|
+
: T extends 'beforeDelete'
|
|
2934
|
+
? TilmeldBeforeDeleteCallback
|
|
2935
|
+
: T extends 'afterDelete'
|
|
2936
|
+
? TilmeldAfterDeleteCallback
|
|
2937
|
+
: never,
|
|
2827
2938
|
) {
|
|
2828
2939
|
const prop = (event + 'Callbacks') as T extends 'checkUsername'
|
|
2829
2940
|
? 'checkUsernameCallbacks'
|
|
@@ -2831,15 +2942,23 @@ export default class User extends AbleObject<UserData> {
|
|
|
2831
2942
|
? 'beforeRegisterCallbacks'
|
|
2832
2943
|
: T extends 'afterRegister'
|
|
2833
2944
|
? 'afterRegisterCallbacks'
|
|
2834
|
-
: T extends '
|
|
2835
|
-
? '
|
|
2836
|
-
: T extends '
|
|
2837
|
-
? '
|
|
2838
|
-
: T extends '
|
|
2839
|
-
? '
|
|
2840
|
-
: T extends '
|
|
2841
|
-
? '
|
|
2842
|
-
:
|
|
2945
|
+
: T extends 'beforeSave'
|
|
2946
|
+
? 'beforeSaveCallbacks'
|
|
2947
|
+
: T extends 'afterSave'
|
|
2948
|
+
? 'afterSaveCallbacks'
|
|
2949
|
+
: T extends 'beforeLogin'
|
|
2950
|
+
? 'beforeLoginCallbacks'
|
|
2951
|
+
: T extends 'afterLogin'
|
|
2952
|
+
? 'afterLoginCallbacks'
|
|
2953
|
+
: T extends 'beforeLogout'
|
|
2954
|
+
? 'beforeLogoutCallbacks'
|
|
2955
|
+
: T extends 'afterLogout'
|
|
2956
|
+
? 'afterLogoutCallbacks'
|
|
2957
|
+
: T extends 'beforeDelete'
|
|
2958
|
+
? 'beforeDeleteCallbacks'
|
|
2959
|
+
: T extends 'afterDelete'
|
|
2960
|
+
? 'afterDeleteCallbacks'
|
|
2961
|
+
: never;
|
|
2843
2962
|
if (!(prop in this)) {
|
|
2844
2963
|
return false;
|
|
2845
2964
|
}
|