@nymphjs/tilmeld 1.0.0-beta.4 → 1.0.0-beta.41
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 +189 -0
- package/README.md +13 -0
- package/dist/Group.d.ts +4 -7
- package/dist/Group.js +107 -83
- package/dist/Group.js.map +1 -1
- package/dist/Tilmeld.d.ts +10 -9
- package/dist/Tilmeld.js +226 -175
- package/dist/Tilmeld.js.map +1 -1
- package/dist/User.d.ts +66 -13
- package/dist/User.js +421 -128
- package/dist/User.js.map +1 -1
- package/dist/conf/d.d.ts +3 -1
- package/dist/conf/defaults.js +15 -4
- package/dist/conf/defaults.js.map +1 -1
- package/dist/enforceTilmeld.d.ts +3 -0
- package/dist/enforceTilmeld.js +22 -0
- package/dist/enforceTilmeld.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +24 -21
- package/src/Group.ts +140 -102
- package/src/Tilmeld.ts +312 -221
- package/src/User.ts +600 -145
- package/src/conf/d.ts +16 -7
- package/src/conf/defaults.ts +17 -4
- package/src/enforceTilmeld.ts +20 -0
- package/src/index.ts +2 -0
- package/typedoc.json +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,195 @@
|
|
|
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.41](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.40...v1.0.0-beta.41) (2023-07-12)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- remove synchronous database queries ([b579fb2](https://github.com/sciactive/nymphjs/commit/b579fb2eacd96cdd1b386a62c5c00cdbb2438f6e))
|
|
11
|
+
- rewrite server side async api to match client side api ([9c537a8](https://github.com/sciactive/nymphjs/commit/9c537a8be49e9b989af0822a4c2236e8c2d20f87))
|
|
12
|
+
|
|
13
|
+
# [1.0.0-beta.40](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.39...v1.0.0-beta.40) (2023-07-10)
|
|
14
|
+
|
|
15
|
+
**Note:** Version bump only for package @nymphjs/tilmeld
|
|
16
|
+
|
|
17
|
+
# [1.0.0-beta.39](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.38...v1.0.0-beta.39) (2023-07-09)
|
|
18
|
+
|
|
19
|
+
**Note:** Version bump only for package @nymphjs/tilmeld
|
|
20
|
+
|
|
21
|
+
# [1.0.0-beta.38](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.37...v1.0.0-beta.38) (2023-07-09)
|
|
22
|
+
|
|
23
|
+
**Note:** Version bump only for package @nymphjs/tilmeld
|
|
24
|
+
|
|
25
|
+
# [1.0.0-beta.37](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.36...v1.0.0-beta.37) (2023-07-09)
|
|
26
|
+
|
|
27
|
+
**Note:** Version bump only for package @nymphjs/tilmeld
|
|
28
|
+
|
|
29
|
+
# [1.0.0-beta.36](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.35...v1.0.0-beta.36) (2023-07-09)
|
|
30
|
+
|
|
31
|
+
**Note:** Version bump only for package @nymphjs/tilmeld
|
|
32
|
+
|
|
33
|
+
# [1.0.0-beta.35](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.34...v1.0.0-beta.35) (2023-06-14)
|
|
34
|
+
|
|
35
|
+
**Note:** Version bump only for package @nymphjs/tilmeld
|
|
36
|
+
|
|
37
|
+
# [1.0.0-beta.34](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.33...v1.0.0-beta.34) (2023-05-13)
|
|
38
|
+
|
|
39
|
+
**Note:** Version bump only for package @nymphjs/tilmeld
|
|
40
|
+
|
|
41
|
+
# [1.0.0-beta.33](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.32...v1.0.0-beta.33) (2023-05-13)
|
|
42
|
+
|
|
43
|
+
**Note:** Version bump only for package @nymphjs/tilmeld
|
|
44
|
+
|
|
45
|
+
# [1.0.0-beta.32](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.31...v1.0.0-beta.32) (2023-05-13)
|
|
46
|
+
|
|
47
|
+
**Note:** Version bump only for package @nymphjs/tilmeld
|
|
48
|
+
|
|
49
|
+
# [1.0.0-beta.31](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.30...v1.0.0-beta.31) (2023-05-12)
|
|
50
|
+
|
|
51
|
+
**Note:** Version bump only for package @nymphjs/tilmeld
|
|
52
|
+
|
|
53
|
+
# [1.0.0-beta.30](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.29...v1.0.0-beta.30) (2023-05-12)
|
|
54
|
+
|
|
55
|
+
### Features
|
|
56
|
+
|
|
57
|
+
- allow providing getEntityClass with a class instead of string ([ecd64c1](https://github.com/sciactive/nymphjs/commit/ecd64c1bf92e3657889613b76bcc46652f371ead))
|
|
58
|
+
|
|
59
|
+
# [1.0.0-beta.29](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.28...v1.0.0-beta.29) (2023-05-08)
|
|
60
|
+
|
|
61
|
+
**Note:** Version bump only for package @nymphjs/tilmeld
|
|
62
|
+
|
|
63
|
+
# [1.0.0-beta.28](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.27...v1.0.0-beta.28) (2023-05-05)
|
|
64
|
+
|
|
65
|
+
**Note:** Version bump only for package @nymphjs/tilmeld
|
|
66
|
+
|
|
67
|
+
# [1.0.0-beta.27](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.26...v1.0.0-beta.27) (2023-05-04)
|
|
68
|
+
|
|
69
|
+
**Note:** Version bump only for package @nymphjs/tilmeld
|
|
70
|
+
|
|
71
|
+
# [1.0.0-beta.26](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.25...v1.0.0-beta.26) (2023-05-04)
|
|
72
|
+
|
|
73
|
+
### Features
|
|
74
|
+
|
|
75
|
+
- update packages and migrate to mysql2 ([72ad611](https://github.com/sciactive/nymphjs/commit/72ad611bd2bf7bf85c3ba8a3486503d9b50c49d6))
|
|
76
|
+
|
|
77
|
+
# [1.0.0-beta.25](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.24...v1.0.0-beta.25) (2023-05-04)
|
|
78
|
+
|
|
79
|
+
### Bug Fixes
|
|
80
|
+
|
|
81
|
+
- tilmeld uses wrong class when cloned with user ([059c2ce](https://github.com/sciactive/nymphjs/commit/059c2cedf1b07b9681e87c240eb36723a4581918))
|
|
82
|
+
|
|
83
|
+
# [1.0.0-beta.24](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.23...v1.0.0-beta.24) (2023-05-02)
|
|
84
|
+
|
|
85
|
+
### Bug Fixes
|
|
86
|
+
|
|
87
|
+
- fill session after setting current user clone ([7bae7cf](https://github.com/sciactive/nymphjs/commit/7bae7cf1bf236b8efc00cb7b5ed53cd21f1370c7))
|
|
88
|
+
|
|
89
|
+
# [1.0.0-beta.23](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.22...v1.0.0-beta.23) (2023-05-02)
|
|
90
|
+
|
|
91
|
+
### Bug Fixes
|
|
92
|
+
|
|
93
|
+
- rare case where currentUser isn't corrent ([97f233a](https://github.com/sciactive/nymphjs/commit/97f233a5fcfd4b97dd282562b0c99097ac3ef41d))
|
|
94
|
+
|
|
95
|
+
# [1.0.0-beta.22](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.21...v1.0.0-beta.22) (2023-05-01)
|
|
96
|
+
|
|
97
|
+
**Note:** Version bump only for package @nymphjs/tilmeld
|
|
98
|
+
|
|
99
|
+
# [1.0.0-beta.21](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.20...v1.0.0-beta.21) (2023-05-01)
|
|
100
|
+
|
|
101
|
+
### Features
|
|
102
|
+
|
|
103
|
+
- add totp two factor authentication ([cc9f8ed](https://github.com/sciactive/nymphjs/commit/cc9f8edb183271fa7f51e4b182b876efb8fa0f8d))
|
|
104
|
+
|
|
105
|
+
# [1.0.0-beta.20](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.19...v1.0.0-beta.20) (2023-04-30)
|
|
106
|
+
|
|
107
|
+
### Features
|
|
108
|
+
|
|
109
|
+
- let the user revoke all current auth tokens ([63af3b9](https://github.com/sciactive/nymphjs/commit/63af3b9a31c6c221ab40c2c8a69231675f4634a2))
|
|
110
|
+
|
|
111
|
+
# [1.0.0-beta.19](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.18...v1.0.0-beta.19) (2023-04-29)
|
|
112
|
+
|
|
113
|
+
### Bug Fixes
|
|
114
|
+
|
|
115
|
+
- some type issues ([ee69d5d](https://github.com/sciactive/nymphjs/commit/ee69d5d73361dacda5745d697df18fafd47810bc))
|
|
116
|
+
|
|
117
|
+
# [1.0.0-beta.18](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.17...v1.0.0-beta.18) (2023-04-27)
|
|
118
|
+
|
|
119
|
+
### Bug Fixes
|
|
120
|
+
|
|
121
|
+
- small type issues ([b91579c](https://github.com/sciactive/nymphjs/commit/b91579c9c1e96500d903332648f5a93c9a7e7d9b))
|
|
122
|
+
|
|
123
|
+
### Features
|
|
124
|
+
|
|
125
|
+
- add enforceTilmeld function ([130faf1](https://github.com/sciactive/nymphjs/commit/130faf151dcdfbfacd6814833868907dca037d24))
|
|
126
|
+
- add the ability to switch to a user without their password ([ca4466a](https://github.com/sciactive/nymphjs/commit/ca4466af1704d68905ac087350a8cf151c1072d9))
|
|
127
|
+
- forbid modifying ac props from client ([f9e896f](https://github.com/sciactive/nymphjs/commit/f9e896f6c57b08ae100bc50d33a0234b6a431333))
|
|
128
|
+
- remove access control bypass for sysadmins and ownerless entities, no longer needed ([345bbf4](https://github.com/sciactive/nymphjs/commit/345bbf4fd78a8f9d6d01fd0be8337854a1277ce6))
|
|
129
|
+
|
|
130
|
+
# [1.0.0-beta.17](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.16...v1.0.0-beta.17) (2023-04-24)
|
|
131
|
+
|
|
132
|
+
**Note:** Version bump only for package @nymphjs/tilmeld
|
|
133
|
+
|
|
134
|
+
# [1.0.0-beta.16](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.15...v1.0.0-beta.16) (2023-03-31)
|
|
135
|
+
|
|
136
|
+
### Features
|
|
137
|
+
|
|
138
|
+
- add ability to tell tilmeld to log in a specific user during authentication ([922e145](https://github.com/sciactive/nymphjs/commit/922e1452adae44bed2aa9655be16e19796acb39b))
|
|
139
|
+
- username check callback ([372e95c](https://github.com/sciactive/nymphjs/commit/372e95c39664c0d718e497ec1b09426e7cfa8862))
|
|
140
|
+
|
|
141
|
+
# [1.0.0-beta.15](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.14...v1.0.0-beta.15) (2023-03-23)
|
|
142
|
+
|
|
143
|
+
**Note:** Version bump only for package @nymphjs/tilmeld
|
|
144
|
+
|
|
145
|
+
# [1.0.0-beta.14](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.13...v1.0.0-beta.14) (2023-03-17)
|
|
146
|
+
|
|
147
|
+
**Note:** Version bump only for package @nymphjs/tilmeld
|
|
148
|
+
|
|
149
|
+
# [1.0.0-beta.13](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.12...v1.0.0-beta.13) (2023-03-16)
|
|
150
|
+
|
|
151
|
+
**Note:** Version bump only for package @nymphjs/tilmeld
|
|
152
|
+
|
|
153
|
+
# [1.0.0-beta.12](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.11...v1.0.0-beta.12) (2023-03-04)
|
|
154
|
+
|
|
155
|
+
**Note:** Version bump only for package @nymphjs/tilmeld
|
|
156
|
+
|
|
157
|
+
# [1.0.0-beta.11](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.10...v1.0.0-beta.11) (2023-02-27)
|
|
158
|
+
|
|
159
|
+
**Note:** Version bump only for package @nymphjs/tilmeld
|
|
160
|
+
|
|
161
|
+
# [1.0.0-beta.10](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.9...v1.0.0-beta.10) (2023-01-19)
|
|
162
|
+
|
|
163
|
+
**Note:** Version bump only for package @nymphjs/tilmeld
|
|
164
|
+
|
|
165
|
+
# [1.0.0-beta.9](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.8...v1.0.0-beta.9) (2023-01-09)
|
|
166
|
+
|
|
167
|
+
**Note:** Version bump only for package @nymphjs/tilmeld
|
|
168
|
+
|
|
169
|
+
# [1.0.0-beta.8](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.7...v1.0.0-beta.8) (2023-01-09)
|
|
170
|
+
|
|
171
|
+
**Note:** Version bump only for package @nymphjs/tilmeld
|
|
172
|
+
|
|
173
|
+
# [1.0.0-beta.7](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.6...v1.0.0-beta.7) (2023-01-05)
|
|
174
|
+
|
|
175
|
+
### Bug Fixes
|
|
176
|
+
|
|
177
|
+
- sqlite transaction returns wrong instance of nymph if it has been cloned ([b278c76](https://github.com/sciactive/nymphjs/commit/b278c7633722cb1cca7a941187ae2f1ff8ebdc7b))
|
|
178
|
+
|
|
179
|
+
# [1.0.0-beta.6](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.5...v1.0.0-beta.6) (2023-01-05)
|
|
180
|
+
|
|
181
|
+
### Bug Fixes
|
|
182
|
+
|
|
183
|
+
- extend class with correct nymph property when added to instance ([1d63f45](https://github.com/sciactive/nymphjs/commit/1d63f457c16de852322d81fd9fdc25e3eb841c8d))
|
|
184
|
+
|
|
185
|
+
### Features
|
|
186
|
+
|
|
187
|
+
- addEntityClass now returns the new class, which is required to use the class ([e752c3e](https://github.com/sciactive/nymphjs/commit/e752c3e50796656bdea8f8525932ede07c8a5378))
|
|
188
|
+
|
|
189
|
+
# [1.0.0-beta.5](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.4...v1.0.0-beta.5) (2022-11-24)
|
|
190
|
+
|
|
191
|
+
### Bug Fixes
|
|
192
|
+
|
|
193
|
+
- correctly check for system admin ability in incoming data ([e777902](https://github.com/sciactive/nymphjs/commit/e77790260bd7ca5331a9d1923dc7d4f3281749dc))
|
|
194
|
+
|
|
6
195
|
# [1.0.0-beta.4](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.3...v1.0.0-beta.4) (2022-11-23)
|
|
7
196
|
|
|
8
197
|
**Note:** Version bump only for package @nymphjs/tilmeld
|
package/README.md
CHANGED
|
@@ -49,6 +49,19 @@ const { User, Group } = tilmeld;
|
|
|
49
49
|
|
|
50
50
|
See the [config declaration file](src/conf/d.ts).
|
|
51
51
|
|
|
52
|
+
## Abilities
|
|
53
|
+
|
|
54
|
+
There are a few abilities that Tilmeld uses internally:
|
|
55
|
+
|
|
56
|
+
- `system/admin` - A user with this ability has **all** abilities.
|
|
57
|
+
- `tilmeld/admin` - Allow the user to manage and edit other user's account and group information and grant/revoke abilities.
|
|
58
|
+
- `tilmeld/switch` - Allow the user to switch to other users (log in as them without their password).
|
|
59
|
+
- `uid/get/[name]` - Allow the user to read the named UID.
|
|
60
|
+
- `uid/new/[name]` - Allow the user to read, create, and increment the named UID.
|
|
61
|
+
- `uid/set/[name]` - Allow the user to read, create, increment, set, and delete the named UID.
|
|
62
|
+
|
|
63
|
+
The admin and switch abilities cannot be inherited from groups.
|
|
64
|
+
|
|
52
65
|
# License
|
|
53
66
|
|
|
54
67
|
Copyright 2021 SciActive Inc
|
package/dist/Group.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { EntityData, EntityJson, EntityPatch, Options, Selector, SerializedEntityData } from '@nymphjs/nymph';
|
|
2
|
-
import type Tilmeld from './Tilmeld';
|
|
3
2
|
import AbleObject from './AbleObject';
|
|
4
3
|
import User, { UserData } from './User';
|
|
5
4
|
export type GroupData = {
|
|
@@ -17,7 +16,6 @@ export type GroupData = {
|
|
|
17
16
|
unverifiedSecondary?: boolean;
|
|
18
17
|
};
|
|
19
18
|
export default class Group extends AbleObject<GroupData> {
|
|
20
|
-
static tilmeld: Tilmeld;
|
|
21
19
|
static ETYPE: string;
|
|
22
20
|
static class: string;
|
|
23
21
|
private static DEFAULT_PRIVATE_DATA;
|
|
@@ -32,8 +30,8 @@ export default class Group extends AbleObject<GroupData> {
|
|
|
32
30
|
private $skipAcWhenSaving;
|
|
33
31
|
static factory(guid?: string): Promise<Group & GroupData>;
|
|
34
32
|
static factoryGroupname(groupname?: string): Promise<Group & GroupData>;
|
|
35
|
-
static factorySync(
|
|
36
|
-
constructor(
|
|
33
|
+
static factorySync(): Group & GroupData;
|
|
34
|
+
constructor();
|
|
37
35
|
static getPrimaryGroups(options?: Options, selectors?: Selector[]): Promise<(Group & GroupData)[]>;
|
|
38
36
|
static getSecondaryGroups(options?: Options, selectors?: Selector[]): Promise<(Group & GroupData)[]>;
|
|
39
37
|
private static getAssignableGroups;
|
|
@@ -42,11 +40,10 @@ export default class Group extends AbleObject<GroupData> {
|
|
|
42
40
|
$jsonAcceptPatch(patch: EntityPatch, allowConflict?: boolean): void;
|
|
43
41
|
$putData(data: EntityData, sdata?: SerializedEntityData): void;
|
|
44
42
|
$updateDataProtection(givenUser?: User & UserData): void;
|
|
45
|
-
$isDescendant(givenGroup: (Group & GroupData) | string): boolean
|
|
43
|
+
$isDescendant(givenGroup: (Group & GroupData) | string): Promise<boolean>;
|
|
46
44
|
$getChildren(): Promise<(Group & GroupData)[]>;
|
|
47
45
|
$getDescendants(andSelf?: boolean): Promise<(Group & GroupData)[]>;
|
|
48
|
-
$
|
|
49
|
-
$getLevel(): number;
|
|
46
|
+
$getLevel(): Promise<number>;
|
|
50
47
|
$getUsers(descendants?: boolean, limit?: number, offset?: number): Promise<(User & UserData)[]>;
|
|
51
48
|
$checkGroupname(): Promise<{
|
|
52
49
|
result: boolean;
|
package/dist/Group.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const md5_1 = __importDefault(require("crypto-js/md5"));
|
|
7
7
|
const lodash_1 = require("lodash");
|
|
8
|
+
const enforceTilmeld_1 = require("./enforceTilmeld");
|
|
8
9
|
const AbleObject_1 = __importDefault(require("./AbleObject"));
|
|
9
10
|
const errors_1 = require("./errors");
|
|
10
11
|
class Group extends AbleObject_1.default {
|
|
@@ -26,11 +27,11 @@ class Group extends AbleObject_1.default {
|
|
|
26
27
|
}
|
|
27
28
|
return entity;
|
|
28
29
|
}
|
|
29
|
-
static factorySync(
|
|
30
|
-
return super.factorySync(
|
|
30
|
+
static factorySync() {
|
|
31
|
+
return super.factorySync();
|
|
31
32
|
}
|
|
32
|
-
constructor(
|
|
33
|
-
super(
|
|
33
|
+
constructor() {
|
|
34
|
+
super();
|
|
34
35
|
this.$tags = [];
|
|
35
36
|
this.$clientEnabledMethods = [
|
|
36
37
|
'$checkGroupname',
|
|
@@ -45,41 +46,46 @@ class Group extends AbleObject_1.default {
|
|
|
45
46
|
this.$allowlistData = [...Group.DEFAULT_ALLOWLIST_DATA];
|
|
46
47
|
this.$allowlistTags = [];
|
|
47
48
|
this.$skipAcWhenSaving = false;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
this.$updateDataProtection();
|
|
52
|
-
}
|
|
49
|
+
this.$data.enabled = true;
|
|
50
|
+
this.$data.abilities = [];
|
|
51
|
+
this.$updateDataProtection();
|
|
53
52
|
}
|
|
54
53
|
static async getPrimaryGroups(options, selectors) {
|
|
55
|
-
|
|
54
|
+
const tilmeld = (0, enforceTilmeld_1.enforceTilmeld)(this);
|
|
55
|
+
if (!(await tilmeld.gatekeeper('tilmeld/admin'))) {
|
|
56
56
|
throw new Error("You don't have permission to do that.");
|
|
57
57
|
}
|
|
58
|
-
return await this.getAssignableGroups(
|
|
58
|
+
return await this.getAssignableGroups(tilmeld.config.highestPrimary, { ...options, class: tilmeld.Group, return: 'entity' }, [...(selectors ?? [])]);
|
|
59
59
|
}
|
|
60
60
|
static async getSecondaryGroups(options, selectors) {
|
|
61
|
-
|
|
61
|
+
const tilmeld = (0, enforceTilmeld_1.enforceTilmeld)(this);
|
|
62
|
+
if (!(await tilmeld.gatekeeper('tilmeld/admin'))) {
|
|
62
63
|
throw new Error("You don't have permission to do that.");
|
|
63
64
|
}
|
|
64
|
-
return await this.getAssignableGroups(
|
|
65
|
+
return await this.getAssignableGroups(tilmeld.config.highestSecondary, { ...options, class: tilmeld.Group, return: 'entity' }, [...(selectors ?? [])]);
|
|
65
66
|
}
|
|
66
67
|
static async getAssignableGroups(highestParent, options, selectors) {
|
|
68
|
+
const tilmeld = (0, enforceTilmeld_1.enforceTilmeld)(this);
|
|
67
69
|
let assignableGroups = [];
|
|
68
70
|
if (highestParent === false) {
|
|
69
71
|
return assignableGroups;
|
|
70
72
|
}
|
|
71
|
-
assignableGroups = await this.nymph.getEntities({ ...options, class:
|
|
73
|
+
assignableGroups = await this.nymph.getEntities({ ...options, class: tilmeld.Group }, ...selectors);
|
|
72
74
|
if (highestParent !== true) {
|
|
73
|
-
assignableGroups = assignableGroups.
|
|
75
|
+
assignableGroups = (await Promise.all(assignableGroups.map(async (group) => {
|
|
74
76
|
let curGroup = group;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
77
|
+
let parent = curGroup.parent;
|
|
78
|
+
await parent?.$wake();
|
|
79
|
+
while (parent != null && parent?.cdate != null) {
|
|
80
|
+
if (parent?.guid === highestParent) {
|
|
81
|
+
return group;
|
|
78
82
|
}
|
|
79
|
-
curGroup =
|
|
83
|
+
curGroup = parent;
|
|
84
|
+
parent = curGroup.parent;
|
|
85
|
+
await parent?.$wake();
|
|
80
86
|
}
|
|
81
|
-
return
|
|
82
|
-
});
|
|
87
|
+
return null;
|
|
88
|
+
}))).filter((group) => group != null);
|
|
83
89
|
}
|
|
84
90
|
return assignableGroups;
|
|
85
91
|
}
|
|
@@ -95,24 +101,54 @@ class Group extends AbleObject_1.default {
|
|
|
95
101
|
'?d=identicon&s=40');
|
|
96
102
|
}
|
|
97
103
|
$jsonAcceptData(input, allowConflict = false) {
|
|
98
|
-
const tilmeld = this
|
|
99
|
-
this.$
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
!tilmeld.
|
|
104
|
-
|
|
104
|
+
const tilmeld = (0, enforceTilmeld_1.enforceTilmeld)(this);
|
|
105
|
+
this.$check();
|
|
106
|
+
if ('abilities' in input.data &&
|
|
107
|
+
input.data.abilities?.includes('system/admin') !==
|
|
108
|
+
this.$data.abilities?.includes('system/admin') &&
|
|
109
|
+
(!tilmeld.currentUser ||
|
|
110
|
+
!tilmeld.currentUser.abilities?.includes('system/admin'))) {
|
|
111
|
+
throw new errors_1.BadDataError("You don't have the authority to grant or revoke system/admin.");
|
|
112
|
+
}
|
|
113
|
+
if ('abilities' in input.data &&
|
|
114
|
+
input.data.abilities?.includes('tilmeld/admin') !==
|
|
115
|
+
this.$data.abilities?.includes('tilmeld/admin') &&
|
|
116
|
+
(!tilmeld.currentUser ||
|
|
117
|
+
!tilmeld.currentUser.abilities?.includes('system/admin'))) {
|
|
118
|
+
throw new errors_1.BadDataError("You don't have the authority to grant or revoke tilmeld/admin.");
|
|
119
|
+
}
|
|
120
|
+
if ('abilities' in input.data &&
|
|
121
|
+
input.data.abilities?.includes('tilmeld/switch') !==
|
|
122
|
+
this.$data.abilities?.includes('tilmeld/switch') &&
|
|
123
|
+
(!tilmeld.currentUser ||
|
|
124
|
+
!tilmeld.currentUser.abilities?.includes('system/admin'))) {
|
|
125
|
+
throw new errors_1.BadDataError("You don't have the authority to grant or revoke tilmeld/switch.");
|
|
105
126
|
}
|
|
106
127
|
super.$jsonAcceptData(input, allowConflict);
|
|
107
128
|
}
|
|
108
129
|
$jsonAcceptPatch(patch, allowConflict = false) {
|
|
109
|
-
const tilmeld = this
|
|
110
|
-
this.$
|
|
111
|
-
if (
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
!tilmeld.
|
|
115
|
-
|
|
130
|
+
const tilmeld = (0, enforceTilmeld_1.enforceTilmeld)(this);
|
|
131
|
+
this.$check();
|
|
132
|
+
if ('abilities' in patch.set &&
|
|
133
|
+
patch.set.abilities?.includes('system/admin') !==
|
|
134
|
+
this.$data.abilities?.includes('system/admin') &&
|
|
135
|
+
(!tilmeld.currentUser ||
|
|
136
|
+
!tilmeld.currentUser.abilities?.includes('system/admin'))) {
|
|
137
|
+
throw new errors_1.BadDataError("You don't have the authority to grant or revoke system/admin.");
|
|
138
|
+
}
|
|
139
|
+
if ('abilities' in patch.set &&
|
|
140
|
+
patch.set.abilities?.includes('tilmeld/admin') !==
|
|
141
|
+
this.$data.abilities?.includes('tilmeld/admin') &&
|
|
142
|
+
(!tilmeld.currentUser ||
|
|
143
|
+
!tilmeld.currentUser.abilities?.includes('system/admin'))) {
|
|
144
|
+
throw new errors_1.BadDataError("You don't have the authority to grant or revoke tilmeld/admin.");
|
|
145
|
+
}
|
|
146
|
+
if ('abilities' in patch.set &&
|
|
147
|
+
patch.set.abilities?.includes('tilmeld/switch') !==
|
|
148
|
+
this.$data.abilities?.includes('tilmeld/switch') &&
|
|
149
|
+
(!tilmeld.currentUser ||
|
|
150
|
+
!tilmeld.currentUser.abilities?.includes('system/admin'))) {
|
|
151
|
+
throw new errors_1.BadDataError("You don't have the authority to grant or revoke tilmeld/switch.");
|
|
116
152
|
}
|
|
117
153
|
super.$jsonAcceptPatch(patch, allowConflict);
|
|
118
154
|
}
|
|
@@ -121,7 +157,7 @@ class Group extends AbleObject_1.default {
|
|
|
121
157
|
this.$updateDataProtection();
|
|
122
158
|
}
|
|
123
159
|
$updateDataProtection(givenUser) {
|
|
124
|
-
const tilmeld = this
|
|
160
|
+
const tilmeld = (0, enforceTilmeld_1.enforceTilmeld)(this);
|
|
125
161
|
let user = givenUser ?? tilmeld.User.current();
|
|
126
162
|
this.$privateData = [...Group.DEFAULT_PRIVATE_DATA];
|
|
127
163
|
this.$allowlistData = [...Group.DEFAULT_ALLOWLIST_DATA];
|
|
@@ -136,15 +172,15 @@ class Group extends AbleObject_1.default {
|
|
|
136
172
|
}
|
|
137
173
|
else if (this.$data.user != null &&
|
|
138
174
|
user != null &&
|
|
139
|
-
this.$data.user
|
|
175
|
+
this.$data.user.guid === user.guid) {
|
|
140
176
|
this.$privateData = [];
|
|
141
177
|
}
|
|
142
178
|
}
|
|
143
|
-
$isDescendant(givenGroup) {
|
|
144
|
-
const tilmeld = this
|
|
179
|
+
async $isDescendant(givenGroup) {
|
|
180
|
+
const tilmeld = (0, enforceTilmeld_1.enforceTilmeld)(this);
|
|
145
181
|
let group;
|
|
146
182
|
if (typeof givenGroup === 'string') {
|
|
147
|
-
group = tilmeld.Group.
|
|
183
|
+
group = await tilmeld.Group.factory(givenGroup);
|
|
148
184
|
}
|
|
149
185
|
else {
|
|
150
186
|
group = givenGroup;
|
|
@@ -152,19 +188,21 @@ class Group extends AbleObject_1.default {
|
|
|
152
188
|
if (group.guid == null) {
|
|
153
189
|
return false;
|
|
154
190
|
}
|
|
155
|
-
|
|
191
|
+
const parent = this.$data.parent;
|
|
192
|
+
await parent?.$wake();
|
|
193
|
+
if (parent == null) {
|
|
156
194
|
return false;
|
|
157
195
|
}
|
|
158
|
-
if (
|
|
196
|
+
if (parent.$is(group)) {
|
|
159
197
|
return true;
|
|
160
198
|
}
|
|
161
|
-
if (
|
|
199
|
+
if (await parent.$isDescendant(group)) {
|
|
162
200
|
return true;
|
|
163
201
|
}
|
|
164
202
|
return false;
|
|
165
203
|
}
|
|
166
204
|
async $getChildren() {
|
|
167
|
-
const tilmeld = this
|
|
205
|
+
const tilmeld = (0, enforceTilmeld_1.enforceTilmeld)(this);
|
|
168
206
|
return await this.$nymph.getEntities({ class: tilmeld.Group }, {
|
|
169
207
|
type: '&',
|
|
170
208
|
equal: ['enabled', true],
|
|
@@ -172,7 +210,7 @@ class Group extends AbleObject_1.default {
|
|
|
172
210
|
});
|
|
173
211
|
}
|
|
174
212
|
async $getDescendants(andSelf = false) {
|
|
175
|
-
const tilmeld = this
|
|
213
|
+
const tilmeld = (0, enforceTilmeld_1.enforceTilmeld)(this);
|
|
176
214
|
let groups = [];
|
|
177
215
|
const entities = await this.$nymph.getEntities({ class: tilmeld.Group }, {
|
|
178
216
|
type: '&',
|
|
@@ -187,39 +225,22 @@ class Group extends AbleObject_1.default {
|
|
|
187
225
|
}
|
|
188
226
|
return groups;
|
|
189
227
|
}
|
|
190
|
-
$
|
|
191
|
-
const tilmeld = this
|
|
192
|
-
let
|
|
193
|
-
let
|
|
194
|
-
|
|
195
|
-
do {
|
|
196
|
-
entity = this.$nymph.driver.getEntitySync({ class: tilmeld.Group, offset }, {
|
|
197
|
-
type: '&',
|
|
198
|
-
equal: ['enabled', true],
|
|
199
|
-
ref: ['parent', this],
|
|
200
|
-
});
|
|
201
|
-
if (entity != null) {
|
|
202
|
-
groups = entity.$getDescendantsSync(true).concat(groups);
|
|
203
|
-
}
|
|
204
|
-
offset++;
|
|
205
|
-
} while (entity != null);
|
|
206
|
-
if (andSelf) {
|
|
207
|
-
groups.push(this);
|
|
208
|
-
}
|
|
209
|
-
return groups;
|
|
210
|
-
}
|
|
211
|
-
$getLevel() {
|
|
212
|
-
const tilmeld = this.$nymph.tilmeld;
|
|
213
|
-
let group = tilmeld.Group.factorySync(this.guid ?? undefined);
|
|
228
|
+
async $getLevel() {
|
|
229
|
+
const tilmeld = (0, enforceTilmeld_1.enforceTilmeld)(this);
|
|
230
|
+
let group = await tilmeld.Group.factory(this.guid ?? undefined);
|
|
231
|
+
let parent = group.parent;
|
|
232
|
+
await parent?.$wake();
|
|
214
233
|
let level = 0;
|
|
215
|
-
while (
|
|
234
|
+
while (parent != null && parent.cdate != null && level < 1024) {
|
|
216
235
|
level++;
|
|
217
|
-
group =
|
|
236
|
+
group = parent;
|
|
237
|
+
parent = group.parent;
|
|
238
|
+
await parent?.$wake();
|
|
218
239
|
}
|
|
219
240
|
return level;
|
|
220
241
|
}
|
|
221
242
|
async $getUsers(descendants = false, limit, offset) {
|
|
222
|
-
const tilmeld = this
|
|
243
|
+
const tilmeld = (0, enforceTilmeld_1.enforceTilmeld)(this);
|
|
223
244
|
let groups = [];
|
|
224
245
|
if (descendants) {
|
|
225
246
|
groups = await this.$getDescendants();
|
|
@@ -248,7 +269,7 @@ class Group extends AbleObject_1.default {
|
|
|
248
269
|
});
|
|
249
270
|
}
|
|
250
271
|
async $checkGroupname() {
|
|
251
|
-
const tilmeld = this
|
|
272
|
+
const tilmeld = (0, enforceTilmeld_1.enforceTilmeld)(this);
|
|
252
273
|
if (!tilmeld.config.emailUsernames) {
|
|
253
274
|
if (this.$data.groupname == null || !this.$data.groupname.length) {
|
|
254
275
|
return { result: false, message: 'Please specify a groupname.' };
|
|
@@ -311,7 +332,7 @@ class Group extends AbleObject_1.default {
|
|
|
311
332
|
}
|
|
312
333
|
}
|
|
313
334
|
async $checkEmail() {
|
|
314
|
-
const tilmeld = this
|
|
335
|
+
const tilmeld = (0, enforceTilmeld_1.enforceTilmeld)(this);
|
|
315
336
|
if (this.$data.email === '') {
|
|
316
337
|
return { result: true, message: '' };
|
|
317
338
|
}
|
|
@@ -344,7 +365,7 @@ class Group extends AbleObject_1.default {
|
|
|
344
365
|
};
|
|
345
366
|
}
|
|
346
367
|
async $save() {
|
|
347
|
-
const tilmeld = this
|
|
368
|
+
const tilmeld = (0, enforceTilmeld_1.enforceTilmeld)(this);
|
|
348
369
|
if (this.$data.groupname == null || !this.$data.groupname.trim().length) {
|
|
349
370
|
return false;
|
|
350
371
|
}
|
|
@@ -386,6 +407,7 @@ class Group extends AbleObject_1.default {
|
|
|
386
407
|
this.$data.abilities = (0, lodash_1.difference)(this.$data.abilities ?? [], [
|
|
387
408
|
'system/admin',
|
|
388
409
|
'tilmeld/admin',
|
|
410
|
+
'tilmeld/switch',
|
|
389
411
|
null,
|
|
390
412
|
undefined,
|
|
391
413
|
]);
|
|
@@ -399,10 +421,12 @@ class Group extends AbleObject_1.default {
|
|
|
399
421
|
throw new errors_1.BadEmailError(emCheck.message);
|
|
400
422
|
}
|
|
401
423
|
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
424
|
+
const parent = this.$data.parent;
|
|
425
|
+
await parent?.$wake();
|
|
426
|
+
if (parent &&
|
|
427
|
+
(parent.cdate == null ||
|
|
428
|
+
this.$is(parent) ||
|
|
429
|
+
(await parent.$isDescendant(this)))) {
|
|
406
430
|
throw new errors_1.BadDataError("Group parent can't be itself or descendant of itself.");
|
|
407
431
|
}
|
|
408
432
|
try {
|
|
@@ -435,15 +459,15 @@ class Group extends AbleObject_1.default {
|
|
|
435
459
|
return false;
|
|
436
460
|
}
|
|
437
461
|
async $delete() {
|
|
438
|
-
let tilmeld = this
|
|
439
|
-
if (!tilmeld.gatekeeper('tilmeld/admin')) {
|
|
462
|
+
let tilmeld = (0, enforceTilmeld_1.enforceTilmeld)(this);
|
|
463
|
+
if (!(await tilmeld.gatekeeper('tilmeld/admin'))) {
|
|
440
464
|
throw new errors_1.BadDataError("You don't have the authority to delete groups.");
|
|
441
465
|
}
|
|
442
466
|
const transaction = 'tilmeld-delete-' + this.guid;
|
|
443
467
|
const nymph = this.$nymph;
|
|
444
468
|
const tnymph = await nymph.startTransaction(transaction);
|
|
445
469
|
this.$nymph = tnymph;
|
|
446
|
-
tilmeld = this
|
|
470
|
+
tilmeld = (0, enforceTilmeld_1.enforceTilmeld)(this);
|
|
447
471
|
const descendants = await this.$getDescendants();
|
|
448
472
|
if (descendants.length) {
|
|
449
473
|
for (let curGroup of descendants) {
|
|
@@ -494,7 +518,6 @@ class Group extends AbleObject_1.default {
|
|
|
494
518
|
return success;
|
|
495
519
|
}
|
|
496
520
|
}
|
|
497
|
-
exports.default = Group;
|
|
498
521
|
Group.ETYPE = 'tilmeld_group';
|
|
499
522
|
Group.class = 'Group';
|
|
500
523
|
Group.DEFAULT_PRIVATE_DATA = ['email', 'phone', 'abilities', 'user'];
|
|
@@ -504,4 +527,5 @@ Group.clientEnabledStaticMethods = [
|
|
|
504
527
|
'getSecondaryGroups',
|
|
505
528
|
];
|
|
506
529
|
Group.searchRestrictedData = [...Group.DEFAULT_PRIVATE_DATA];
|
|
530
|
+
exports.default = Group;
|
|
507
531
|
//# sourceMappingURL=Group.js.map
|