@tomei/sso 0.33.6 → 0.33.8
Sign up to get free protection for your applications and to get access to all the features.
- package/.commitlintrc.json +22 -22
- package/.eslintrc +16 -16
- package/.eslintrc.js +35 -35
- package/.gitlab-ci.yml +16 -16
- package/.husky/commit-msg +15 -15
- package/.husky/pre-commit +7 -7
- package/.prettierrc +4 -4
- package/Jenkinsfile +57 -57
- package/README.md +23 -23
- package/__tests__/unit/components/group/group.spec.ts +79 -79
- package/__tests__/unit/components/group-object-privilege/group-object-privilege.spec.ts +88 -88
- package/__tests__/unit/components/group-privilege/group-privilege.spec.ts +68 -68
- package/__tests__/unit/components/group-reporting-user/group-reporting-user.spec.ts +66 -66
- package/__tests__/unit/components/group-system-access/group-system-access.spec.ts +83 -83
- package/__tests__/unit/components/login-user/l.spec.ts +746 -746
- package/__tests__/unit/components/login-user/login.spec.ts +1064 -1064
- package/__tests__/unit/components/password-hash/password-hash.service.spec.ts +31 -31
- package/__tests__/unit/components/system/system.spec.ts +254 -254
- package/__tests__/unit/components/system-privilege/system-privilege.spec.ts +83 -83
- package/__tests__/unit/components/user-group/user-group.spec.ts +86 -86
- package/__tests__/unit/components/user-object-privilege/user-object-privilege.spec.ts +78 -78
- package/__tests__/unit/components/user-privilege/user-privilege.spec.ts +72 -72
- package/__tests__/unit/components/user-system-access/user-system-access.spec.ts +89 -89
- package/__tests__/unit/redis-client/redis.service.spec.ts +23 -23
- package/__tests__/unit/session/session.service.spec.ts +47 -47
- package/__tests__/unit/system-privilege/system-privilage.spec.ts +91 -91
- package/coverage/clover.xml +1452 -1452
- package/coverage/coverage-final.json +47 -47
- package/coverage/lcov-report/base.css +224 -224
- package/coverage/lcov-report/block-navigation.js +87 -87
- package/coverage/lcov-report/components/group/group.repository.ts.html +117 -117
- package/coverage/lcov-report/components/group/group.ts.html +327 -327
- package/coverage/lcov-report/components/group/index.html +130 -130
- package/coverage/lcov-report/components/group-object-privilege/group-object-privilege.repository.ts.html +117 -117
- package/coverage/lcov-report/components/group-object-privilege/group-object-privilege.ts.html +321 -321
- package/coverage/lcov-report/components/group-object-privilege/index.html +130 -130
- package/coverage/lcov-report/components/group-privilege/group-privilege.repository.ts.html +117 -117
- package/coverage/lcov-report/components/group-privilege/group-privilege.ts.html +303 -303
- package/coverage/lcov-report/components/group-privilege/index.html +130 -130
- package/coverage/lcov-report/components/group-reporting-user/group-reporting-user.repository.ts.html +117 -117
- package/coverage/lcov-report/components/group-reporting-user/group-reporting-user.ts.html +327 -327
- package/coverage/lcov-report/components/group-reporting-user/index.html +130 -130
- package/coverage/lcov-report/components/group-system-access/group-system-access.repository.ts.html +117 -117
- package/coverage/lcov-report/components/group-system-access/group-system-access.ts.html +309 -309
- package/coverage/lcov-report/components/group-system-access/index.html +130 -130
- package/coverage/lcov-report/components/login-history/index.html +115 -115
- package/coverage/lcov-report/components/login-history/login-history.repository.ts.html +117 -117
- package/coverage/lcov-report/components/login-user/index.html +130 -130
- package/coverage/lcov-report/components/login-user/login-user.ts.html +5007 -5007
- package/coverage/lcov-report/components/login-user/user.repository.ts.html +117 -117
- package/coverage/lcov-report/components/password-hash/index.html +115 -115
- package/coverage/lcov-report/components/password-hash/password-hash.service.ts.html +126 -126
- package/coverage/lcov-report/components/system/index.html +130 -130
- package/coverage/lcov-report/components/system/system.repository.ts.html +117 -117
- package/coverage/lcov-report/components/system/system.ts.html +909 -909
- package/coverage/lcov-report/components/system-privilege/index.html +130 -130
- package/coverage/lcov-report/components/system-privilege/system-privilege.repository.ts.html +120 -120
- package/coverage/lcov-report/components/system-privilege/system-privilege.ts.html +390 -390
- package/coverage/lcov-report/components/user-group/index.html +130 -130
- package/coverage/lcov-report/components/user-group/user-group.repository.ts.html +117 -117
- package/coverage/lcov-report/components/user-group/user-group.ts.html +354 -354
- package/coverage/lcov-report/components/user-object-privilege/index.html +130 -130
- package/coverage/lcov-report/components/user-object-privilege/user-object-privilege.repository.ts.html +117 -117
- package/coverage/lcov-report/components/user-object-privilege/user-object-privilege.ts.html +312 -312
- package/coverage/lcov-report/components/user-privilege/index.html +130 -130
- package/coverage/lcov-report/components/user-privilege/user-privilege.repository.ts.html +117 -117
- package/coverage/lcov-report/components/user-privilege/user-privilege.ts.html +306 -306
- package/coverage/lcov-report/components/user-system-access/index.html +130 -130
- package/coverage/lcov-report/components/user-system-access/user-system-access.repository.ts.html +117 -117
- package/coverage/lcov-report/components/user-system-access/user-system-access.ts.html +312 -312
- package/coverage/lcov-report/enum/group-type.enum.ts.html +108 -108
- package/coverage/lcov-report/enum/index.html +160 -160
- package/coverage/lcov-report/enum/index.ts.html +93 -93
- package/coverage/lcov-report/enum/user-status.enum.ts.html +105 -105
- package/coverage/lcov-report/enum/yn.enum.ts.html +96 -96
- package/coverage/lcov-report/index.html +370 -370
- package/coverage/lcov-report/models/group-object-privilege.entity.ts.html +333 -333
- package/coverage/lcov-report/models/group-privilege.entity.ts.html +315 -315
- package/coverage/lcov-report/models/group-reporting-user.entity.ts.html +339 -339
- package/coverage/lcov-report/models/group-system-access.entity.ts.html +324 -324
- package/coverage/lcov-report/models/group.entity.ts.html +435 -435
- package/coverage/lcov-report/models/index.html +310 -310
- package/coverage/lcov-report/models/login-history.entity.ts.html +252 -252
- package/coverage/lcov-report/models/staff.entity.ts.html +411 -411
- package/coverage/lcov-report/models/system-privilege.entity.ts.html +354 -354
- package/coverage/lcov-report/models/system.entity.ts.html +423 -423
- package/coverage/lcov-report/models/user-group.entity.ts.html +354 -354
- package/coverage/lcov-report/models/user-object-privilege.entity.ts.html +330 -330
- package/coverage/lcov-report/models/user-privilege.entity.ts.html +315 -315
- package/coverage/lcov-report/models/user-system-access.entity.ts.html +315 -315
- package/coverage/lcov-report/models/user.entity.ts.html +522 -522
- package/coverage/lcov-report/prettify.css +1 -1
- package/coverage/lcov-report/prettify.js +2 -2
- package/coverage/lcov-report/redis-client/index.html +115 -115
- package/coverage/lcov-report/redis-client/redis.service.ts.html +240 -240
- package/coverage/lcov-report/session/index.html +115 -115
- package/coverage/lcov-report/session/session.service.ts.html +246 -246
- package/coverage/lcov-report/sorter.js +196 -196
- package/coverage/lcov.info +2490 -2490
- package/coverage/test-report.xml +128 -128
- package/create-sso-user.sql +39 -39
- package/dist/__tests__/unit/components/group-privilege/group-privilege.test.d.ts +1 -0
- package/dist/__tests__/unit/components/group-privilege/group-privilege.test.js +71 -0
- package/dist/__tests__/unit/components/group-privilege/group-privilege.test.js.map +1 -0
- package/dist/__tests__/unit/components/login-user/login-user.spec.d.ts +0 -0
- package/dist/__tests__/unit/components/login-user/login-user.spec.js +6 -0
- package/dist/__tests__/unit/components/login-user/login-user.spec.js.map +1 -0
- package/dist/src/components/group/group.d.ts +27 -0
- package/dist/src/components/group/group.js +432 -4
- package/dist/src/components/group/group.js.map +1 -1
- package/dist/src/components/group-object-privilege/group-object-privilege.d.ts +3 -0
- package/dist/src/components/group-object-privilege/group-object-privilege.js +106 -0
- package/dist/src/components/group-object-privilege/group-object-privilege.js.map +1 -1
- package/dist/src/components/group-object-privilege/group-object-privilege.repository.d.ts +1 -0
- package/dist/src/components/group-object-privilege/group-object-privilege.repository.js +22 -0
- package/dist/src/components/group-object-privilege/group-object-privilege.repository.js.map +1 -1
- package/dist/src/components/group-privilege/group-privilege.d.ts +2 -0
- package/dist/src/components/group-privilege/group-privilege.js +10 -0
- package/dist/src/components/group-privilege/group-privilege.js.map +1 -1
- package/dist/src/components/group-privilege/group-privilege.repository.d.ts +1 -0
- package/dist/src/components/group-privilege/group-privilege.repository.js +22 -0
- package/dist/src/components/group-privilege/group-privilege.repository.js.map +1 -1
- package/dist/src/components/login-user/login-user.d.ts +1 -1
- package/dist/src/components/system-privilege/system-privilege.d.ts +7 -0
- package/dist/src/components/system-privilege/system-privilege.js +54 -1
- package/dist/src/components/system-privilege/system-privilege.js.map +1 -1
- package/dist/src/components/user-object-privilege/user-object-privilege.js.map +1 -1
- package/dist/src/interfaces/group-object-privilege.interface.d.ts +1 -1
- package/dist/src/interfaces/group-privilege.interface.d.ts +1 -1
- package/dist/src/interfaces/system-privilege-search.interface.d.ts +5 -0
- package/dist/src/interfaces/system-privilege-search.interface.js +3 -0
- package/dist/src/interfaces/system-privilege-search.interface.js.map +1 -0
- package/dist/src/models/group-object-privilege.entity.js +1 -0
- package/dist/src/models/group-object-privilege.entity.js.map +1 -1
- package/dist/src/models/group-privilege.entity.js +1 -0
- package/dist/src/models/group-privilege.entity.js.map +1 -1
- package/dist/src/models/group-reporting-user.entity.js +1 -0
- package/dist/src/models/group-reporting-user.entity.js.map +1 -1
- package/dist/src/models/user-object-privilege.entity.js +1 -0
- package/dist/src/models/user-object-privilege.entity.js.map +1 -1
- package/dist/src/models/user-privilege.entity.js +1 -0
- package/dist/src/models/user-privilege.entity.js.map +1 -1
- package/dist/src/models/user-system-access.entity.js +1 -0
- package/dist/src/models/user-system-access.entity.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/jest.config.js +14 -14
- package/migrations/20240314080602-create-user-table.js +108 -108
- package/migrations/20240314080603-create-user-group-table.js +85 -85
- package/migrations/20240314080604-create-user-user-group-table.js +55 -55
- package/migrations/20240314080605-create-login-history-table.js +53 -53
- package/migrations/20240527064925-create-system-table.js +78 -78
- package/migrations/20240527064926-create-system-privilege-table.js +67 -67
- package/migrations/20240527065342-create-group-table.js +89 -89
- package/migrations/20240527065633-create-group-reporting-user-table.js +76 -76
- package/migrations/20240528011551-create-group-system-access-table.js +72 -72
- package/migrations/20240528023018-user-system-access-table.js +75 -75
- package/migrations/20240528032229-user-privilege-table.js +75 -75
- package/migrations/20240528063003-create-group-privilege-table.js +75 -75
- package/migrations/20240528063051-create-group-object-privilege-table.js +84 -84
- package/migrations/20240528063107-create-user-object-privilege-table.js +83 -83
- package/package.json +89 -89
- package/sampledotenv +7 -7
- package/sonar-project.properties +22 -22
- package/src/components/group/group.ts +1456 -747
- package/src/components/group-object-privilege/group-object-privilege.repository.ts +15 -2
- package/src/components/group-object-privilege/group-object-privilege.ts +183 -0
- package/src/components/group-privilege/group-privilege.repository.ts +12 -2
- package/src/components/group-privilege/group-privilege.ts +11 -0
- package/src/components/system-privilege/system-privilege.ts +86 -2
- package/src/components/user-object-privilege/user-object-privilege.ts +1 -0
- package/src/interfaces/group-object-privilege.interface.ts +14 -14
- package/src/interfaces/group-privilege.interface.ts +1 -1
- package/src/interfaces/system-privilege-search.interface.ts +5 -0
- package/src/models/group-object-privilege.entity.ts +1 -0
- package/src/models/group-privilege.entity.ts +1 -0
- package/src/models/group-reporting-user.entity.ts +1 -0
- package/src/models/group-system-access.entity.ts +81 -81
- package/src/models/user-object-privilege.entity.ts +1 -0
- package/src/models/user-privilege.entity.ts +1 -0
- package/src/models/user-system-access.entity.ts +1 -0
- package/tsconfig.build.json +5 -5
- package/tsconfig.json +22 -22
@@ -1,747 +1,1456 @@
|
|
1
|
-
import { ClassError, ObjectBase } from '@tomei/general';
|
2
|
-
import { GroupRepository } from './group.repository';
|
3
|
-
import { IGroupAttr } from '../../interfaces/group.interface';
|
4
|
-
import { GroupTypeEnum } from 'enum';
|
5
|
-
import { LoginUser } from '../login-user/login-user';
|
6
|
-
import { IGroupSearchAttr } from '../../interfaces/group-search-attr.interface';
|
7
|
-
import { ApplicationConfig } from '@tomei/config';
|
8
|
-
import { Op } from 'sequelize';
|
9
|
-
import { ActionEnum, Activity } from '@tomei/activity-history';
|
10
|
-
import { GroupSystemAccessRepository } from '../group-system-access/group-system-access.repository';
|
11
|
-
import SystemModel from '../../models/system.entity';
|
12
|
-
import { GroupSystemAccess } from '../group-system-access';
|
13
|
-
import { RedisService } from '../../redis-client/redis.service';
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
this.
|
73
|
-
this.
|
74
|
-
this.
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
}
|
139
|
-
|
140
|
-
if (
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
);
|
188
|
-
}
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
'
|
194
|
-
'
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
'
|
202
|
-
'
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
if (
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
if (
|
235
|
-
throw new ClassError(
|
236
|
-
'Group',
|
237
|
-
'
|
238
|
-
'
|
239
|
-
);
|
240
|
-
}
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
newGroup
|
255
|
-
newGroup.
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
currentGroup.
|
395
|
-
|
396
|
-
|
397
|
-
currentGroup.
|
398
|
-
currentGroup.
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
}
|
506
|
-
|
507
|
-
|
508
|
-
options
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
currentGroupSystemAccess?.rows[0]?.
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
}
|
1
|
+
import { ClassError, ObjectBase } from '@tomei/general';
|
2
|
+
import { GroupRepository } from './group.repository';
|
3
|
+
import { IGroupAttr } from '../../interfaces/group.interface';
|
4
|
+
import { GroupTypeEnum } from 'enum';
|
5
|
+
import { LoginUser } from '../login-user/login-user';
|
6
|
+
import { IGroupSearchAttr } from '../../interfaces/group-search-attr.interface';
|
7
|
+
import { ApplicationConfig } from '@tomei/config';
|
8
|
+
import { Op } from 'sequelize';
|
9
|
+
import { ActionEnum, Activity } from '@tomei/activity-history';
|
10
|
+
import { GroupSystemAccessRepository } from '../group-system-access/group-system-access.repository';
|
11
|
+
import SystemModel from '../../models/system.entity';
|
12
|
+
import { GroupSystemAccess } from '../group-system-access';
|
13
|
+
import { RedisService } from '../../redis-client/redis.service';
|
14
|
+
import SystemPrivilegeModel from '../../models/system-privilege.entity';
|
15
|
+
import { GroupPrivilegeRepository } from '../group-privilege/group-privilege.repository';
|
16
|
+
import { SystemPrivilege } from '../system-privilege/system-privilege';
|
17
|
+
import GroupPrivilegeModel from '../../models/group-privilege.entity';
|
18
|
+
import { GroupObjectPrivilegeRepository } from '../group-object-privilege/group-object-privilege.repository';
|
19
|
+
import { GroupObjectPrivilege } from '../group-object-privilege/group-object-privilege';
|
20
|
+
import { GroupPrivilege } from '../group-privilege/group-privilege';
|
21
|
+
|
22
|
+
export class Group extends ObjectBase {
|
23
|
+
ObjectId: string;
|
24
|
+
ObjectName: string;
|
25
|
+
TableName: 'sso_Group';
|
26
|
+
ObjectType = 'Group';
|
27
|
+
|
28
|
+
Name: string;
|
29
|
+
Description: string;
|
30
|
+
Type: GroupTypeEnum;
|
31
|
+
ParentGroupCode: string;
|
32
|
+
InheritParentPrivilegeYN: string;
|
33
|
+
InheritParentSystemAccessYN: string;
|
34
|
+
Status: string;
|
35
|
+
ParentGroup?: any;
|
36
|
+
private _CreatedById: number;
|
37
|
+
private _CreatedAt: Date;
|
38
|
+
private _UpdatedById: number;
|
39
|
+
private _UpdatedAt: Date;
|
40
|
+
private static _Repo = new GroupRepository();
|
41
|
+
private static _GroupSystemAccessRepo = new GroupSystemAccessRepository();
|
42
|
+
private static _GroupPrivilegeRepo = new GroupPrivilegeRepository();
|
43
|
+
private static _GroupObjectPrivilegeRepo = new GroupObjectPrivilegeRepository();
|
44
|
+
private static _RedisService: RedisService;
|
45
|
+
get GroupCode(): string {
|
46
|
+
return this.ObjectId;
|
47
|
+
}
|
48
|
+
|
49
|
+
set GroupCode(value: string) {
|
50
|
+
this.ObjectId = value;
|
51
|
+
}
|
52
|
+
|
53
|
+
get CreatedById(): number {
|
54
|
+
return this._CreatedById;
|
55
|
+
}
|
56
|
+
|
57
|
+
get CreatedAt(): Date {
|
58
|
+
return this._CreatedAt;
|
59
|
+
}
|
60
|
+
|
61
|
+
get UpdatedById(): number {
|
62
|
+
return this._UpdatedById;
|
63
|
+
}
|
64
|
+
|
65
|
+
get UpdatedAt(): Date {
|
66
|
+
return this._UpdatedAt;
|
67
|
+
}
|
68
|
+
|
69
|
+
private constructor(groupAttr?: IGroupAttr) {
|
70
|
+
super();
|
71
|
+
if (groupAttr) {
|
72
|
+
this.GroupCode = groupAttr.GroupCode;
|
73
|
+
this.Name = groupAttr.Name;
|
74
|
+
this.Description = groupAttr?.Description;
|
75
|
+
this.Type = groupAttr?.Type;
|
76
|
+
this.ParentGroupCode = groupAttr?.ParentGroupCode;
|
77
|
+
this.InheritParentPrivilegeYN = groupAttr?.InheritParentPrivilegeYN;
|
78
|
+
this.InheritParentSystemAccessYN = groupAttr?.InheritParentSystemAccessYN;
|
79
|
+
this.Status = groupAttr?.Status;
|
80
|
+
this._CreatedById = groupAttr.CreatedById;
|
81
|
+
this._CreatedAt = groupAttr.CreatedAt;
|
82
|
+
this._UpdatedById = groupAttr.UpdatedById;
|
83
|
+
this._UpdatedAt = groupAttr.UpdatedAt;
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
public static async init(dbTransaction: any, GroupCode?: string) {
|
88
|
+
try {
|
89
|
+
Group._RedisService = await RedisService.init();
|
90
|
+
if (GroupCode) {
|
91
|
+
const group = await Group._Repo.findByPk(GroupCode, {
|
92
|
+
transaction: dbTransaction,
|
93
|
+
});
|
94
|
+
if (group) {
|
95
|
+
return new Group(group);
|
96
|
+
} else {
|
97
|
+
throw Error('Group not found');
|
98
|
+
}
|
99
|
+
}
|
100
|
+
return new Group();
|
101
|
+
} catch (error) {
|
102
|
+
throw new ClassError(
|
103
|
+
'Group',
|
104
|
+
'GroupErrMsg01',
|
105
|
+
'Failed To Initialize Group',
|
106
|
+
);
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
public static async findAll(
|
111
|
+
page: number,
|
112
|
+
row: number,
|
113
|
+
dbTransaction: any,
|
114
|
+
loginUser: LoginUser,
|
115
|
+
search?: IGroupSearchAttr,
|
116
|
+
) {
|
117
|
+
//This method will list all group based on the query params.
|
118
|
+
//Part 1: Privilege Checking
|
119
|
+
const systemCode = ApplicationConfig.getComponentConfigValue('system-code');
|
120
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
121
|
+
systemCode,
|
122
|
+
'GROUP_LIST',
|
123
|
+
);
|
124
|
+
|
125
|
+
if (!isPrivileged) {
|
126
|
+
throw new ClassError(
|
127
|
+
'Group',
|
128
|
+
'GroupErrMsg04',
|
129
|
+
'User is not privileged to list group',
|
130
|
+
);
|
131
|
+
}
|
132
|
+
|
133
|
+
//Part 2: Retrieve listing
|
134
|
+
const queryObj: any = {};
|
135
|
+
|
136
|
+
let options: any = {
|
137
|
+
transaction: dbTransaction,
|
138
|
+
};
|
139
|
+
|
140
|
+
if (page && row) {
|
141
|
+
options = {
|
142
|
+
...options,
|
143
|
+
limit: row,
|
144
|
+
offset: row * (page - 1),
|
145
|
+
order: [['CreatedAt', 'DESC']],
|
146
|
+
};
|
147
|
+
}
|
148
|
+
|
149
|
+
if (search) {
|
150
|
+
Object.entries(search).forEach(([key, value]) => {
|
151
|
+
queryObj[key] = {
|
152
|
+
[Op.substring]: value,
|
153
|
+
};
|
154
|
+
});
|
155
|
+
|
156
|
+
options = {
|
157
|
+
...options,
|
158
|
+
where: queryObj,
|
159
|
+
};
|
160
|
+
|
161
|
+
const result = await Group._Repo.findAllWithPagination(options);
|
162
|
+
|
163
|
+
//Map the result to Group instance
|
164
|
+
return {
|
165
|
+
Count: result.count,
|
166
|
+
Groups: result.rows.map(
|
167
|
+
(group) => new Group(group.get({ plain: true })),
|
168
|
+
),
|
169
|
+
};
|
170
|
+
}
|
171
|
+
}
|
172
|
+
|
173
|
+
public static async create(
|
174
|
+
loginUser: LoginUser,
|
175
|
+
dbTransaction: any,
|
176
|
+
group: Group,
|
177
|
+
) {
|
178
|
+
try {
|
179
|
+
//Part 1: Privilege Checking
|
180
|
+
const systemCode =
|
181
|
+
ApplicationConfig.getComponentConfigValue('system-code');
|
182
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
183
|
+
systemCode,
|
184
|
+
'GROUP_CREATE',
|
185
|
+
);
|
186
|
+
if (!isPrivileged) {
|
187
|
+
throw new Error('You do not have permission to create group');
|
188
|
+
}
|
189
|
+
|
190
|
+
//Part 2: Validation
|
191
|
+
if (!group.GroupCode) {
|
192
|
+
throw new ClassError(
|
193
|
+
'Group',
|
194
|
+
'GroupErrMsg02',
|
195
|
+
'Group Code is required',
|
196
|
+
);
|
197
|
+
}
|
198
|
+
|
199
|
+
if (!group.Name) {
|
200
|
+
throw new ClassError(
|
201
|
+
'Group',
|
202
|
+
'GroupErrMsg02',
|
203
|
+
'Group Name is required',
|
204
|
+
);
|
205
|
+
}
|
206
|
+
|
207
|
+
if (!group.Type) {
|
208
|
+
throw new ClassError(
|
209
|
+
'Group',
|
210
|
+
'GroupErrMsg02',
|
211
|
+
'Group Type is required',
|
212
|
+
);
|
213
|
+
}
|
214
|
+
|
215
|
+
//Check if group code is unique
|
216
|
+
const existingGroupCode = await Group._Repo.findByPk(group.GroupCode, {
|
217
|
+
transaction: dbTransaction,
|
218
|
+
});
|
219
|
+
|
220
|
+
if (existingGroupCode) {
|
221
|
+
throw new ClassError(
|
222
|
+
'Group',
|
223
|
+
'GroupErrMsg03',
|
224
|
+
'Duplicate GroupCode found.',
|
225
|
+
);
|
226
|
+
}
|
227
|
+
|
228
|
+
//Validate parent group code if passed. Call Group._Repo.findByPk
|
229
|
+
if (group.ParentGroupCode) {
|
230
|
+
const parentGroup = await Group._Repo.findByPk(group.ParentGroupCode, {
|
231
|
+
transaction: dbTransaction,
|
232
|
+
});
|
233
|
+
|
234
|
+
if (!parentGroup) {
|
235
|
+
throw new ClassError(
|
236
|
+
'Group',
|
237
|
+
'GroupErrMsg04',
|
238
|
+
'ParentGroupCode is not found.',
|
239
|
+
);
|
240
|
+
}
|
241
|
+
|
242
|
+
//If Params.group.GroupCode = Params.group?.ParentGroupCode, throw new ClassError
|
243
|
+
if (group.GroupCode === group.ParentGroupCode) {
|
244
|
+
throw new ClassError(
|
245
|
+
'Group',
|
246
|
+
'GroupErrMsg05',
|
247
|
+
'GroupCode and ParentGroupCode cannot be the same.',
|
248
|
+
);
|
249
|
+
}
|
250
|
+
}
|
251
|
+
|
252
|
+
//Part 3: Create Group
|
253
|
+
//Initialise new Group instance and populate
|
254
|
+
const newGroup = new Group(group);
|
255
|
+
newGroup.ObjectId = group.GroupCode;
|
256
|
+
newGroup.Name = group.Name;
|
257
|
+
newGroup.Type = group.Type;
|
258
|
+
newGroup.Description = group.Description;
|
259
|
+
newGroup.ParentGroupCode = group.ParentGroupCode;
|
260
|
+
newGroup.InheritParentPrivilegeYN = group.InheritParentPrivilegeYN;
|
261
|
+
newGroup.InheritParentSystemAccessYN = group.InheritParentSystemAccessYN;
|
262
|
+
newGroup.Status = 'Active';
|
263
|
+
newGroup._CreatedById = loginUser.UserId;
|
264
|
+
newGroup._UpdatedById = loginUser.UserId;
|
265
|
+
|
266
|
+
//Call Group._Repo create method
|
267
|
+
const entityGroupAfter = {
|
268
|
+
GroupCode: newGroup.ObjectId,
|
269
|
+
Name: newGroup.Name,
|
270
|
+
Type: newGroup.Type,
|
271
|
+
Description: newGroup.Description,
|
272
|
+
ParentGroupCode: newGroup.ParentGroupCode,
|
273
|
+
InheritParentPrivilegeYN: newGroup.InheritParentPrivilegeYN,
|
274
|
+
InheritParentSystemAccessYN: newGroup.InheritParentSystemAccessYN,
|
275
|
+
Status: newGroup.Status,
|
276
|
+
CreatedById: newGroup._CreatedById,
|
277
|
+
UpdatedById: newGroup._UpdatedById,
|
278
|
+
CreatedAt: newGroup._CreatedAt,
|
279
|
+
UpdatedAt: newGroup._UpdatedAt,
|
280
|
+
};
|
281
|
+
|
282
|
+
await Group._Repo.create(entityGroupAfter, {
|
283
|
+
transaction: dbTransaction,
|
284
|
+
});
|
285
|
+
|
286
|
+
//Part 4: Record Create Group Activity and return newGroup
|
287
|
+
|
288
|
+
const entityValueBefore = {};
|
289
|
+
|
290
|
+
//Instantiate new activity
|
291
|
+
const activity = new Activity();
|
292
|
+
activity.ActivityId = activity.createId();
|
293
|
+
activity.Action = ActionEnum.ADD;
|
294
|
+
activity.Description = 'Create Group';
|
295
|
+
activity.EntityType = 'Group';
|
296
|
+
activity.EntityId = newGroup.ObjectId;
|
297
|
+
activity.EntityValueBefore = JSON.stringify(entityValueBefore);
|
298
|
+
activity.EntityValueAfter = JSON.stringify(entityGroupAfter);
|
299
|
+
|
300
|
+
//Call Activity.create method
|
301
|
+
await activity.create(loginUser.ObjectId, dbTransaction);
|
302
|
+
|
303
|
+
return newGroup;
|
304
|
+
} catch (error) {
|
305
|
+
throw error;
|
306
|
+
}
|
307
|
+
}
|
308
|
+
|
309
|
+
protected static async checkDuplicateGroupCode(
|
310
|
+
dbTransaction: any,
|
311
|
+
GroupCode,
|
312
|
+
) {
|
313
|
+
const isGroupCodeExist = await Group._Repo.findOne({
|
314
|
+
where: { GroupCode },
|
315
|
+
transaction: dbTransaction,
|
316
|
+
});
|
317
|
+
|
318
|
+
if (isGroupCodeExist) {
|
319
|
+
throw new ClassError(
|
320
|
+
'Group',
|
321
|
+
'GroupErrMsg07',
|
322
|
+
'GroupCode already exists.',
|
323
|
+
);
|
324
|
+
}
|
325
|
+
}
|
326
|
+
|
327
|
+
public async update(
|
328
|
+
loginUser: LoginUser,
|
329
|
+
dbTransaction: any,
|
330
|
+
group: {
|
331
|
+
GroupCode: string;
|
332
|
+
NewGroupCode?: string;
|
333
|
+
Name?: string;
|
334
|
+
Description?: string;
|
335
|
+
Type?: GroupTypeEnum;
|
336
|
+
ParentGroupCode?: string;
|
337
|
+
InheritParentPrivilegeYN?: string;
|
338
|
+
InheritParentSystemAccessYN?: string;
|
339
|
+
Status?: string;
|
340
|
+
},
|
341
|
+
) {
|
342
|
+
//Part 1: Privilege Checking
|
343
|
+
const systemCode = ApplicationConfig.getComponentConfigValue('system-code');
|
344
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
345
|
+
systemCode,
|
346
|
+
'GROUP_UPDATE',
|
347
|
+
);
|
348
|
+
|
349
|
+
if (!isPrivileged) {
|
350
|
+
throw new ClassError(
|
351
|
+
'Group',
|
352
|
+
'GroupErrMsg06',
|
353
|
+
'You do not have the privilege to update Group',
|
354
|
+
);
|
355
|
+
}
|
356
|
+
try {
|
357
|
+
const currentGroup = await Group.init(dbTransaction, group.GroupCode);
|
358
|
+
if (group.NewGroupCode) {
|
359
|
+
await Group.checkDuplicateGroupCode(dbTransaction, group.NewGroupCode);
|
360
|
+
}
|
361
|
+
|
362
|
+
if (
|
363
|
+
group.ParentGroupCode &&
|
364
|
+
currentGroup.ParentGroupCode !== group.ParentGroupCode
|
365
|
+
) {
|
366
|
+
const parentGroup = await Group.init(
|
367
|
+
dbTransaction,
|
368
|
+
group.ParentGroupCode,
|
369
|
+
);
|
370
|
+
if (!parentGroup) {
|
371
|
+
throw new ClassError(
|
372
|
+
'Group',
|
373
|
+
'GroupErrMsg08',
|
374
|
+
'Parent Group Code not found',
|
375
|
+
);
|
376
|
+
}
|
377
|
+
}
|
378
|
+
|
379
|
+
const entityValueBefore = {
|
380
|
+
GroupCode: currentGroup.GroupCode,
|
381
|
+
Name: currentGroup.Name,
|
382
|
+
Type: currentGroup.Type,
|
383
|
+
Description: currentGroup.Description,
|
384
|
+
ParentGroupCode: currentGroup.ParentGroupCode,
|
385
|
+
InheritParentPrivilegeYN: currentGroup.InheritParentPrivilegeYN,
|
386
|
+
InheritParentSystemAccessYN: currentGroup.InheritParentSystemAccessYN,
|
387
|
+
Status: currentGroup.Status,
|
388
|
+
CreatedById: currentGroup._CreatedById,
|
389
|
+
UpdatedById: currentGroup._UpdatedById,
|
390
|
+
CreatedAt: currentGroup._CreatedAt,
|
391
|
+
UpdatedAt: currentGroup._UpdatedAt,
|
392
|
+
};
|
393
|
+
|
394
|
+
currentGroup.GroupCode = group?.NewGroupCode || currentGroup.GroupCode;
|
395
|
+
currentGroup.Name = group?.Name || currentGroup.Name;
|
396
|
+
currentGroup.Type = group?.Type || currentGroup.Type;
|
397
|
+
currentGroup.Description = group?.Description || currentGroup.Description;
|
398
|
+
currentGroup.ParentGroupCode =
|
399
|
+
group?.ParentGroupCode || currentGroup.ParentGroupCode;
|
400
|
+
currentGroup.InheritParentPrivilegeYN =
|
401
|
+
group?.InheritParentPrivilegeYN ||
|
402
|
+
currentGroup.InheritParentPrivilegeYN;
|
403
|
+
currentGroup.InheritParentSystemAccessYN =
|
404
|
+
group?.InheritParentSystemAccessYN ||
|
405
|
+
currentGroup.InheritParentSystemAccessYN;
|
406
|
+
currentGroup.Status = group?.Status || currentGroup.Status;
|
407
|
+
currentGroup._UpdatedById = loginUser.UserId;
|
408
|
+
currentGroup._UpdatedAt = new Date();
|
409
|
+
|
410
|
+
await Group._Repo.update(
|
411
|
+
{
|
412
|
+
GroupCode: currentGroup.GroupCode,
|
413
|
+
Name: currentGroup.Name,
|
414
|
+
Type: currentGroup.Type,
|
415
|
+
Description: currentGroup.Description,
|
416
|
+
ParentGroupCode: currentGroup.ParentGroupCode,
|
417
|
+
InheritParentPrivilegeYN: currentGroup.InheritParentPrivilegeYN,
|
418
|
+
InheritParentSystemAccessYN: currentGroup.InheritParentSystemAccessYN,
|
419
|
+
Status: currentGroup.Status,
|
420
|
+
UpdatedById: currentGroup._UpdatedById,
|
421
|
+
UpdatedAt: currentGroup._UpdatedAt,
|
422
|
+
},
|
423
|
+
{
|
424
|
+
where: {
|
425
|
+
GroupCode: group.GroupCode,
|
426
|
+
},
|
427
|
+
transaction: dbTransaction,
|
428
|
+
},
|
429
|
+
);
|
430
|
+
|
431
|
+
const entityValueAfter = {
|
432
|
+
GroupCode: currentGroup.GroupCode,
|
433
|
+
Name: currentGroup.Name,
|
434
|
+
Type: currentGroup.Type,
|
435
|
+
Description: currentGroup.Description,
|
436
|
+
ParentGroupCode: currentGroup.ParentGroupCode,
|
437
|
+
InheritParentPrivilegeYN: currentGroup.InheritParentPrivilegeYN,
|
438
|
+
InheritParentSystemAccessYN: currentGroup.InheritParentSystemAccessYN,
|
439
|
+
Status: currentGroup.Status,
|
440
|
+
CreatedById: currentGroup._CreatedById,
|
441
|
+
UpdatedById: currentGroup._UpdatedById,
|
442
|
+
CreatedAt: currentGroup._CreatedAt,
|
443
|
+
UpdatedAt: currentGroup._UpdatedAt,
|
444
|
+
};
|
445
|
+
|
446
|
+
const activity = new Activity();
|
447
|
+
activity.ActivityId = activity.createId();
|
448
|
+
activity.Action = ActionEnum.UPDATE;
|
449
|
+
activity.Description = `Update Group ${group.Type}`;
|
450
|
+
activity.EntityType = 'Group';
|
451
|
+
activity.EntityId = group.GroupCode;
|
452
|
+
activity.EntityValueBefore = JSON.stringify(entityValueBefore);
|
453
|
+
activity.EntityValueAfter = JSON.stringify(entityValueAfter);
|
454
|
+
await activity.create(loginUser.ObjectId, dbTransaction);
|
455
|
+
|
456
|
+
return currentGroup;
|
457
|
+
} catch (error) {
|
458
|
+
throw error;
|
459
|
+
}
|
460
|
+
}
|
461
|
+
|
462
|
+
public static async getSystemAccesses(
|
463
|
+
loginUser: LoginUser,
|
464
|
+
dbTransaction: any,
|
465
|
+
GroupCode: string,
|
466
|
+
Page: number,
|
467
|
+
Rows: number,
|
468
|
+
Search: {
|
469
|
+
SystemCode?: string;
|
470
|
+
Status?: string;
|
471
|
+
},
|
472
|
+
) {
|
473
|
+
// Part 1: Privilege Checking
|
474
|
+
const systemCode = ApplicationConfig.getComponentConfigValue('system-code');
|
475
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
476
|
+
systemCode,
|
477
|
+
'SYSTEM_ACCESS_VIEW',
|
478
|
+
);
|
479
|
+
|
480
|
+
if (!isPrivileged) {
|
481
|
+
throw new ClassError(
|
482
|
+
'Group',
|
483
|
+
'GroupErrMsg06',
|
484
|
+
'You do not have the privilege to view system access',
|
485
|
+
);
|
486
|
+
}
|
487
|
+
|
488
|
+
try {
|
489
|
+
// Part 2: Validation
|
490
|
+
await Group.init(dbTransaction, GroupCode);
|
491
|
+
|
492
|
+
// Part 3: Retrieve System Access and returns
|
493
|
+
const queryObj: any = { GroupCode: GroupCode };
|
494
|
+
|
495
|
+
if (Search) {
|
496
|
+
Object.entries(Search).forEach(([key, value]) => {
|
497
|
+
queryObj[key] = value;
|
498
|
+
});
|
499
|
+
}
|
500
|
+
|
501
|
+
let options: any = {
|
502
|
+
where: queryObj,
|
503
|
+
distinct: true,
|
504
|
+
transaction: dbTransaction,
|
505
|
+
};
|
506
|
+
|
507
|
+
if (Page && Rows) {
|
508
|
+
options = {
|
509
|
+
...options,
|
510
|
+
limit: Rows,
|
511
|
+
offset: Rows * (Page - 1),
|
512
|
+
order: [['CreatedAt', 'DESC']],
|
513
|
+
};
|
514
|
+
}
|
515
|
+
|
516
|
+
const systemAccess = await Group._GroupSystemAccessRepo.findAndCountAll(
|
517
|
+
options,
|
518
|
+
);
|
519
|
+
return systemAccess;
|
520
|
+
} catch (error) {
|
521
|
+
return error;
|
522
|
+
}
|
523
|
+
}
|
524
|
+
|
525
|
+
private static async getInheritedSystemAccess(
|
526
|
+
dbTransaction: any,
|
527
|
+
group: Group,
|
528
|
+
): Promise<any[]> {
|
529
|
+
const options: any = {
|
530
|
+
where: {
|
531
|
+
GroupCode: group.GroupCode,
|
532
|
+
Status: 'Active',
|
533
|
+
},
|
534
|
+
include: [
|
535
|
+
{
|
536
|
+
model: SystemModel,
|
537
|
+
},
|
538
|
+
],
|
539
|
+
transaction: dbTransaction,
|
540
|
+
};
|
541
|
+
let systemAccess = await Group._GroupSystemAccessRepo.findAll(options);
|
542
|
+
|
543
|
+
if (group.InheritParentSystemAccessYN === 'Y' && group.ParentGroupCode) {
|
544
|
+
const parentGroup = await Group.init(
|
545
|
+
dbTransaction,
|
546
|
+
group.ParentGroupCode,
|
547
|
+
);
|
548
|
+
const parentSystemAccesses = await this.getInheritedSystemAccess(
|
549
|
+
dbTransaction,
|
550
|
+
parentGroup,
|
551
|
+
);
|
552
|
+
systemAccess = systemAccess.concat(parentSystemAccesses);
|
553
|
+
}
|
554
|
+
return systemAccess;
|
555
|
+
}
|
556
|
+
|
557
|
+
public static async getParentSystemAccesses(
|
558
|
+
loginUser: LoginUser,
|
559
|
+
dbTransaction: any,
|
560
|
+
GroupCode: string,
|
561
|
+
) {
|
562
|
+
// Part 1: Privilege Checking
|
563
|
+
const systemCode = ApplicationConfig.getComponentConfigValue('system-code');
|
564
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
565
|
+
systemCode,
|
566
|
+
'SYSTEM_ACCESS_VIEW',
|
567
|
+
);
|
568
|
+
|
569
|
+
if (!isPrivileged) {
|
570
|
+
throw new ClassError(
|
571
|
+
'Group',
|
572
|
+
'GroupErrMsg06',
|
573
|
+
'You do not have the privilege to view system access',
|
574
|
+
);
|
575
|
+
}
|
576
|
+
|
577
|
+
try {
|
578
|
+
const group = await Group.init(dbTransaction, GroupCode);
|
579
|
+
if (group.InheritParentSystemAccessYN !== 'Y' && !group.ParentGroupCode) {
|
580
|
+
return [];
|
581
|
+
} else {
|
582
|
+
const parentGroup = await Group.init(
|
583
|
+
dbTransaction,
|
584
|
+
group.ParentGroupCode,
|
585
|
+
);
|
586
|
+
const inheritSystemAccess = await Group.getInheritedSystemAccess(
|
587
|
+
dbTransaction,
|
588
|
+
parentGroup,
|
589
|
+
);
|
590
|
+
return inheritSystemAccess;
|
591
|
+
}
|
592
|
+
} catch (error) {
|
593
|
+
throw error;
|
594
|
+
}
|
595
|
+
}
|
596
|
+
|
597
|
+
public static async addSystemAccesses(
|
598
|
+
loginUser: LoginUser,
|
599
|
+
dbTransaction: any,
|
600
|
+
GroupCode: string,
|
601
|
+
SystemCodes: string[],
|
602
|
+
) {
|
603
|
+
// Part 1: Privilege Checking
|
604
|
+
const systemCode = ApplicationConfig.getComponentConfigValue('system-code');
|
605
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
606
|
+
systemCode,
|
607
|
+
'SYSTEM_ACCESS_CREATE',
|
608
|
+
);
|
609
|
+
|
610
|
+
if (!isPrivileged) {
|
611
|
+
throw new ClassError(
|
612
|
+
'Group',
|
613
|
+
'GroupErrMsg07',
|
614
|
+
'You do not have the privilege to create system access',
|
615
|
+
);
|
616
|
+
}
|
617
|
+
|
618
|
+
try {
|
619
|
+
if (SystemCodes.length > 0) {
|
620
|
+
for (const element of SystemCodes) {
|
621
|
+
const CurrentGroupSystemAccess = await Group.getSystemAccesses(
|
622
|
+
loginUser,
|
623
|
+
dbTransaction,
|
624
|
+
GroupCode,
|
625
|
+
1,
|
626
|
+
Number.MAX_SAFE_INTEGER,
|
627
|
+
{ SystemCode: element },
|
628
|
+
);
|
629
|
+
|
630
|
+
if (CurrentGroupSystemAccess?.count > 0) {
|
631
|
+
throw new ClassError(
|
632
|
+
'Group',
|
633
|
+
'GroupErrMsg08',
|
634
|
+
'System access already exists',
|
635
|
+
);
|
636
|
+
}
|
637
|
+
|
638
|
+
const groupSystemAccess = await GroupSystemAccess.init(dbTransaction);
|
639
|
+
groupSystemAccess.createId();
|
640
|
+
groupSystemAccess.GroupCode = GroupCode;
|
641
|
+
groupSystemAccess.SystemCode = element;
|
642
|
+
groupSystemAccess.Status = 'Active';
|
643
|
+
groupSystemAccess.CreatedById = +loginUser.ObjectId;
|
644
|
+
groupSystemAccess.CreatedAt = new Date();
|
645
|
+
groupSystemAccess.UpdatedById = +loginUser.ObjectId;
|
646
|
+
groupSystemAccess.UpdatedAt = new Date();
|
647
|
+
|
648
|
+
const EntityValueAfter = {
|
649
|
+
GroupCode: groupSystemAccess.GroupCode,
|
650
|
+
SystemCode: groupSystemAccess.SystemCode,
|
651
|
+
Status: groupSystemAccess.Status,
|
652
|
+
CreatedById: groupSystemAccess.CreatedById,
|
653
|
+
CreatedAt: groupSystemAccess.CreatedAt,
|
654
|
+
UpdatedById: groupSystemAccess.UpdatedById,
|
655
|
+
UpdatedAt: groupSystemAccess.UpdatedAt,
|
656
|
+
};
|
657
|
+
|
658
|
+
const systemAccess = await Group._GroupSystemAccessRepo.create(
|
659
|
+
EntityValueAfter,
|
660
|
+
{
|
661
|
+
transaction: dbTransaction,
|
662
|
+
},
|
663
|
+
);
|
664
|
+
|
665
|
+
const activity = new Activity();
|
666
|
+
activity.ActivityId = activity.createId();
|
667
|
+
activity.Action = ActionEnum.ADD;
|
668
|
+
activity.Description = 'Create Group System Access';
|
669
|
+
activity.EntityType = 'GroupSystemAccess';
|
670
|
+
activity.EntityId = systemAccess.GroupSystemAccessId?.toString();
|
671
|
+
activity.EntityValueBefore = JSON.stringify({});
|
672
|
+
activity.EntityValueAfter = JSON.stringify(EntityValueAfter);
|
673
|
+
|
674
|
+
await activity.create(loginUser.ObjectId, dbTransaction);
|
675
|
+
}
|
676
|
+
|
677
|
+
return { Message: 'Successfully added.' };
|
678
|
+
}
|
679
|
+
} catch (error) {
|
680
|
+
throw error;
|
681
|
+
}
|
682
|
+
}
|
683
|
+
|
684
|
+
public static async deleteSystemAccess(
|
685
|
+
loginUser: LoginUser,
|
686
|
+
dbTransaction: any,
|
687
|
+
GroupCode: string,
|
688
|
+
SystemCode: string,
|
689
|
+
) {
|
690
|
+
// Part 1: Privilege Checking
|
691
|
+
const systemCode = ApplicationConfig.getComponentConfigValue('system-code');
|
692
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
693
|
+
systemCode,
|
694
|
+
'SYSTEM_ACCESS_DELETE',
|
695
|
+
);
|
696
|
+
|
697
|
+
if (!isPrivileged) {
|
698
|
+
throw new ClassError(
|
699
|
+
'Group',
|
700
|
+
'GroupErrMsg08',
|
701
|
+
'You do not have the privilege to delete system access',
|
702
|
+
);
|
703
|
+
}
|
704
|
+
|
705
|
+
try {
|
706
|
+
const currentGroupSystemAccess = await Group.getSystemAccesses(
|
707
|
+
loginUser,
|
708
|
+
dbTransaction,
|
709
|
+
GroupCode,
|
710
|
+
1,
|
711
|
+
Number.MAX_SAFE_INTEGER,
|
712
|
+
{ SystemCode: SystemCode },
|
713
|
+
);
|
714
|
+
|
715
|
+
if (currentGroupSystemAccess.count < 1) {
|
716
|
+
throw new ClassError(
|
717
|
+
'Group',
|
718
|
+
'GroupErrMsg10',
|
719
|
+
'No associated system access found.',
|
720
|
+
);
|
721
|
+
}
|
722
|
+
|
723
|
+
await Group._GroupSystemAccessRepo.delete(
|
724
|
+
GroupCode,
|
725
|
+
SystemCode,
|
726
|
+
dbTransaction,
|
727
|
+
);
|
728
|
+
|
729
|
+
const EntityValueBefore = {
|
730
|
+
GroupCode: currentGroupSystemAccess?.rows[0]?.GroupCode,
|
731
|
+
SystemCode: currentGroupSystemAccess?.rows[0]?.SystemCode,
|
732
|
+
Status: currentGroupSystemAccess?.rows[0]?.Status,
|
733
|
+
CreatedById: currentGroupSystemAccess?.rows[0]?.CreatedById,
|
734
|
+
CreatedAt: currentGroupSystemAccess?.rows[0]?.CreatedAt,
|
735
|
+
UpdatedById: currentGroupSystemAccess?.rows[0]?.UpdatedById,
|
736
|
+
UpdatedAt: currentGroupSystemAccess?.rows[0]?.UpdatedAt,
|
737
|
+
};
|
738
|
+
|
739
|
+
const activity = new Activity();
|
740
|
+
activity.ActivityId = activity.createId();
|
741
|
+
activity.Action = ActionEnum.DELETE;
|
742
|
+
activity.Description = 'Delete Group System Access';
|
743
|
+
activity.EntityType = 'GroupSystemAccess';
|
744
|
+
activity.EntityId =
|
745
|
+
currentGroupSystemAccess?.rows[0]?.GroupSystemAccessId?.toString();
|
746
|
+
activity.EntityValueBefore = JSON.stringify(EntityValueBefore);
|
747
|
+
activity.EntityValueAfter = JSON.stringify({});
|
748
|
+
|
749
|
+
await activity.create(loginUser.ObjectId, dbTransaction);
|
750
|
+
|
751
|
+
return { Message: 'System access removed.', SystemCode: SystemCode };
|
752
|
+
} catch (error) {
|
753
|
+
throw error;
|
754
|
+
}
|
755
|
+
}
|
756
|
+
|
757
|
+
public static async getSystemPrivileges(
|
758
|
+
loginUser: LoginUser,
|
759
|
+
dbTransaction: any,
|
760
|
+
GroupCode: string,
|
761
|
+
search?: {
|
762
|
+
SystemCode?: string;
|
763
|
+
Status?: string;
|
764
|
+
},
|
765
|
+
) {
|
766
|
+
try {
|
767
|
+
//Part 1: Privilege Checking
|
768
|
+
const systemCode = ApplicationConfig.getComponentConfigValue('system-code');
|
769
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
770
|
+
systemCode,
|
771
|
+
'GROUP_PRIVILEGE_VIEW',
|
772
|
+
);
|
773
|
+
|
774
|
+
if (!isPrivileged) {
|
775
|
+
throw new ClassError(
|
776
|
+
'Group',
|
777
|
+
'GroupErrMsg11',
|
778
|
+
'You do not have the privilege to view group privileges',
|
779
|
+
);
|
780
|
+
}
|
781
|
+
|
782
|
+
//Set group to instantiation of existing Group
|
783
|
+
await Group.init(dbTransaction, GroupCode);
|
784
|
+
|
785
|
+
//Part 3: Retrieve Group Own Privilege
|
786
|
+
//Retrieve group data and it's privileged by calling Group._Repo.findAll
|
787
|
+
let where: any = {
|
788
|
+
GroupCode,
|
789
|
+
};
|
790
|
+
|
791
|
+
let systemWhere: any = {};
|
792
|
+
|
793
|
+
if (search) {
|
794
|
+
if (search.Status) {
|
795
|
+
where = {
|
796
|
+
...where,
|
797
|
+
Status: search.Status,
|
798
|
+
};
|
799
|
+
}
|
800
|
+
|
801
|
+
if (search.SystemCode) {
|
802
|
+
systemWhere = {
|
803
|
+
SystemCode: {
|
804
|
+
[Op.substring]: search.SystemCode,
|
805
|
+
},
|
806
|
+
};
|
807
|
+
}
|
808
|
+
}
|
809
|
+
|
810
|
+
const groupOwnPrivileges = await Group._GroupPrivilegeRepo.findAll({
|
811
|
+
where,
|
812
|
+
include: [
|
813
|
+
{
|
814
|
+
model: SystemPrivilegeModel,
|
815
|
+
where: systemWhere,
|
816
|
+
},
|
817
|
+
],
|
818
|
+
transaction: dbTransaction,
|
819
|
+
});
|
820
|
+
|
821
|
+
//Create variable called privileges and Map the SystemPrivilege data retrieved from 3.1 into SystemPrivilege object and push it to the privileges variables
|
822
|
+
let privileges: SystemPrivilege[] = [];
|
823
|
+
|
824
|
+
for (const groupPrivilege of groupOwnPrivileges) {
|
825
|
+
const systemPrivilege = await SystemPrivilege.init(
|
826
|
+
dbTransaction,
|
827
|
+
);
|
828
|
+
systemPrivilege.setAttributes(groupPrivilege.Privilege.get({ plain: true }));
|
829
|
+
privileges.push(systemPrivilege);
|
830
|
+
}
|
831
|
+
|
832
|
+
return privileges;
|
833
|
+
} catch (error) {
|
834
|
+
throw error;
|
835
|
+
}
|
836
|
+
}
|
837
|
+
|
838
|
+
public static async getInheritedSystemPrivileges(
|
839
|
+
dbTransaction: any,
|
840
|
+
GroupCode: string,
|
841
|
+
search?: {
|
842
|
+
SystemCode?: string;
|
843
|
+
Status?: string;
|
844
|
+
PrivilegeCode?: string;
|
845
|
+
},
|
846
|
+
): Promise<SystemPrivilege[]> {
|
847
|
+
try {
|
848
|
+
//Retrieve group data and it's privileges by calling Group._Repo.findAll
|
849
|
+
let where: any = {
|
850
|
+
GroupCode,
|
851
|
+
};
|
852
|
+
|
853
|
+
let groupPrivilegeWhere: any = {};
|
854
|
+
let systemPrivilegeWhere: any = {};
|
855
|
+
|
856
|
+
if (search) {
|
857
|
+
if (search.Status) {
|
858
|
+
groupPrivilegeWhere = {
|
859
|
+
Status: search.Status,
|
860
|
+
};
|
861
|
+
}
|
862
|
+
|
863
|
+
if (search.SystemCode) {
|
864
|
+
systemPrivilegeWhere = {
|
865
|
+
SystemCode: {
|
866
|
+
[Op.substring]: search.SystemCode,
|
867
|
+
},
|
868
|
+
};
|
869
|
+
}
|
870
|
+
}
|
871
|
+
const group = await Group._Repo.findOne({
|
872
|
+
where: where,
|
873
|
+
include: [
|
874
|
+
{
|
875
|
+
model: GroupPrivilegeModel,
|
876
|
+
where: groupPrivilegeWhere,
|
877
|
+
include: [
|
878
|
+
{
|
879
|
+
model: SystemPrivilegeModel,
|
880
|
+
where: systemPrivilegeWhere,
|
881
|
+
},
|
882
|
+
],
|
883
|
+
},
|
884
|
+
],
|
885
|
+
transaction: dbTransaction,
|
886
|
+
});
|
887
|
+
|
888
|
+
//Retrieve group object privileges by calling LoginUser._GroupObjectPrivilegeRepo.findAll
|
889
|
+
let objectWhere: any = {
|
890
|
+
GroupCode,
|
891
|
+
};
|
892
|
+
let systemWhere: any = {};
|
893
|
+
if (search) {
|
894
|
+
Object.entries(search).forEach(([key, value]) => {
|
895
|
+
if (key === 'SystemCode') {
|
896
|
+
systemWhere[key] = {
|
897
|
+
[Op.substring]: value,
|
898
|
+
};
|
899
|
+
} else {
|
900
|
+
objectWhere[key] = {
|
901
|
+
[Op.substring]: value,
|
902
|
+
};
|
903
|
+
}
|
904
|
+
});
|
905
|
+
}
|
906
|
+
const groupObjectPrivileges = await Group._GroupObjectPrivilegeRepo.findAll({
|
907
|
+
where: objectWhere,
|
908
|
+
include: [
|
909
|
+
{
|
910
|
+
model: SystemPrivilegeModel,
|
911
|
+
where: systemWhere,
|
912
|
+
},
|
913
|
+
],
|
914
|
+
transaction: dbTransaction,
|
915
|
+
});
|
916
|
+
|
917
|
+
//Map to SystemPrivilege object
|
918
|
+
let privileges: SystemPrivilege[] = [];
|
919
|
+
for (const groupPrivilege of group.GroupPrivileges) {
|
920
|
+
const systemPrivilege = await SystemPrivilege.init(dbTransaction);
|
921
|
+
systemPrivilege.setAttributes(groupPrivilege.Privilege.get({ plain: true }));
|
922
|
+
privileges.push(systemPrivilege);
|
923
|
+
}
|
924
|
+
|
925
|
+
for (const groupObjectPrivilege of groupObjectPrivileges) {
|
926
|
+
const systemPrivilege = await SystemPrivilege.init(dbTransaction);
|
927
|
+
systemPrivilege.setAttributes(groupObjectPrivilege.Privilege.get({ plain: true }));
|
928
|
+
privileges.push(systemPrivilege);
|
929
|
+
}
|
930
|
+
|
931
|
+
//Part 2: Retrieve Privileges Inherited from Parent Group
|
932
|
+
//if group data retrieved from 1.1 have InheritParentPrivilegeYN == "Y" and ParentGroupCode value is not empty. Call this method again
|
933
|
+
if (group.InheritParentPrivilegeYN === 'Y' && group.ParentGroupCode) {
|
934
|
+
const inheritedPrivileges = await Group.getInheritedSystemPrivileges(
|
935
|
+
dbTransaction,
|
936
|
+
group.ParentGroupCode,
|
937
|
+
search,
|
938
|
+
);
|
939
|
+
privileges = privileges.concat(inheritedPrivileges);
|
940
|
+
}
|
941
|
+
|
942
|
+
//format to make sure no duplicate
|
943
|
+
const uniquePrivileges = Array.from(new Set(privileges.map(a => a.PrivilegeCode)))
|
944
|
+
.map(PrivilegeCode => {
|
945
|
+
return privileges.find(a => a.PrivilegeCode === PrivilegeCode);
|
946
|
+
});
|
947
|
+
|
948
|
+
return uniquePrivileges;
|
949
|
+
} catch (error) {
|
950
|
+
throw error;
|
951
|
+
}
|
952
|
+
}
|
953
|
+
|
954
|
+
public static async getParentSystemPrivileges(
|
955
|
+
loginUser: LoginUser,
|
956
|
+
dbTransaction: any,
|
957
|
+
GroupCode: string,
|
958
|
+
search?: {
|
959
|
+
SystemCode?: string;
|
960
|
+
Status?: string;
|
961
|
+
PrivilegeCode?: string;
|
962
|
+
},
|
963
|
+
): Promise<SystemPrivilege[]> {
|
964
|
+
try {
|
965
|
+
//Part 1: Privilege Checking
|
966
|
+
const systemCode = ApplicationConfig.getComponentConfigValue('system-code');
|
967
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
968
|
+
systemCode,
|
969
|
+
'GROUP_PRIVILEGE_VIEW',
|
970
|
+
);
|
971
|
+
|
972
|
+
if (!isPrivileged) {
|
973
|
+
throw new ClassError(
|
974
|
+
'Group',
|
975
|
+
'GroupErrMsg11',
|
976
|
+
'You do not have the privilege to view group privileges',
|
977
|
+
);
|
978
|
+
}
|
979
|
+
|
980
|
+
//Part 2: Validation
|
981
|
+
//Set group to instantiation of existing Group
|
982
|
+
const group = await Group.init(dbTransaction, GroupCode);
|
983
|
+
//Check if group.InheritParentPrivilegeYN == "Y" and ParentGroupCode value is not empty. if no then return an empty array
|
984
|
+
if (group.InheritParentPrivilegeYN !== 'Y' && !group.ParentGroupCode) {
|
985
|
+
return [];
|
986
|
+
}
|
987
|
+
|
988
|
+
//Part 3: Retrieve Group Own Privilege
|
989
|
+
//Retrieve group data and it's privileged by calling Group.getIheritedSystemPrivileges
|
990
|
+
const privileges = await Group.getInheritedSystemPrivileges(
|
991
|
+
dbTransaction,
|
992
|
+
group.ParentGroupCode,
|
993
|
+
search,
|
994
|
+
);
|
995
|
+
|
996
|
+
return privileges;
|
997
|
+
} catch (error) {
|
998
|
+
throw error;
|
999
|
+
}
|
1000
|
+
}
|
1001
|
+
|
1002
|
+
public static async assignGroupObjectPrivilege(
|
1003
|
+
loginUser: LoginUser,
|
1004
|
+
dbTransaction: any,
|
1005
|
+
GroupCode: string,
|
1006
|
+
GroupObjectPrivileges: GroupObjectPrivilege[]
|
1007
|
+
): Promise<string> {
|
1008
|
+
try {
|
1009
|
+
//Part 1: Privilege Checking
|
1010
|
+
const systemCode = ApplicationConfig.getComponentConfigValue('system-code');
|
1011
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
1012
|
+
systemCode,
|
1013
|
+
'GROUP_OBJECT_PRIVILEGE_ASSIGN',
|
1014
|
+
);
|
1015
|
+
|
1016
|
+
if (!isPrivileged) {
|
1017
|
+
throw new ClassError(
|
1018
|
+
'Group',
|
1019
|
+
'GroupErrMsg12',
|
1020
|
+
'You do not have the privilege to assign group object privilege',
|
1021
|
+
);
|
1022
|
+
}
|
1023
|
+
|
1024
|
+
//Part 2: Validation
|
1025
|
+
//Initialise group with group init
|
1026
|
+
const group = await Group.init(dbTransaction, GroupCode);
|
1027
|
+
//Retrieve all group system access by calling Group.getSystemAccesses
|
1028
|
+
const groupSystemAccesses = await Group.getSystemAccesses(
|
1029
|
+
loginUser,
|
1030
|
+
dbTransaction,
|
1031
|
+
GroupCode,
|
1032
|
+
1,
|
1033
|
+
Number.MAX_SAFE_INTEGER,
|
1034
|
+
{},
|
1035
|
+
);
|
1036
|
+
|
1037
|
+
//If Group.InheritParentSystemAccess == "Y" and Group.ParentGroupCode exist, initialise parent group
|
1038
|
+
let parentGroupSystemAccesses: any = {};
|
1039
|
+
if (group.InheritParentSystemAccessYN === 'Y' && group.ParentGroupCode) {
|
1040
|
+
//Retrieve all parent group system access by calling Group.getSystemAccesses
|
1041
|
+
parentGroupSystemAccesses = await Group.getSystemAccesses(
|
1042
|
+
loginUser,
|
1043
|
+
dbTransaction,
|
1044
|
+
group.ParentGroupCode,
|
1045
|
+
1,
|
1046
|
+
Number.MAX_SAFE_INTEGER,
|
1047
|
+
{},
|
1048
|
+
);
|
1049
|
+
}
|
1050
|
+
|
1051
|
+
// For each Params.GroupObjectPrivileges.
|
1052
|
+
for (const groupObjectPrivilege of GroupObjectPrivileges) {
|
1053
|
+
//Initialise existing System privilege
|
1054
|
+
const systemPrivilege = await SystemPrivilege.init(dbTransaction, groupObjectPrivilege.PrivilegeCode);
|
1055
|
+
//Check whether the system codes used by that privilege is exist inside the group system access
|
1056
|
+
const combinedSystemAccesses = {
|
1057
|
+
...groupSystemAccesses.rows,
|
1058
|
+
...parentGroupSystemAccesses.rows,
|
1059
|
+
};
|
1060
|
+
const systemAccess = combinedSystemAccesses.find(
|
1061
|
+
(systemAccess) => systemAccess.SystemCode === systemPrivilege.SystemCode,
|
1062
|
+
);
|
1063
|
+
if (!systemAccess) {
|
1064
|
+
throw new ClassError(
|
1065
|
+
'Group',
|
1066
|
+
'GroupErrMsg13',
|
1067
|
+
'Failed to assign privilege ' + groupObjectPrivilege.PrivilegeCode + ' due to non-existent system access.',
|
1068
|
+
);
|
1069
|
+
}
|
1070
|
+
|
1071
|
+
//Check whether the group object privilege already exist by using Group._GroupObjectPrivilegesRepo.findOne
|
1072
|
+
const groupObjectPrivilegeData = await Group._GroupObjectPrivilegeRepo.findOne({
|
1073
|
+
where: {
|
1074
|
+
GroupCode,
|
1075
|
+
PrivilegeCode: groupObjectPrivilege.PrivilegeCode,
|
1076
|
+
ObjectId: groupObjectPrivilege.ObjectId,
|
1077
|
+
ObjectType: groupObjectPrivilege.ObjectType,
|
1078
|
+
},
|
1079
|
+
transaction: dbTransaction,
|
1080
|
+
});
|
1081
|
+
//If GroupObjectPrivilege record exist. Skip this loop and proceed to the next privilege code
|
1082
|
+
if (groupObjectPrivilegeData) {
|
1083
|
+
continue;
|
1084
|
+
} else {
|
1085
|
+
//Call GroupObjectPrivilege.create
|
1086
|
+
await GroupObjectPrivilege.create(
|
1087
|
+
loginUser,
|
1088
|
+
dbTransaction,
|
1089
|
+
groupObjectPrivilege,
|
1090
|
+
);
|
1091
|
+
}
|
1092
|
+
}
|
1093
|
+
|
1094
|
+
return 'Successfully added.';
|
1095
|
+
} catch (error) {
|
1096
|
+
throw error;
|
1097
|
+
}
|
1098
|
+
}
|
1099
|
+
|
1100
|
+
public static async getGroubObjectPrivileges(
|
1101
|
+
loginUser: LoginUser,
|
1102
|
+
dbTransaction: any,
|
1103
|
+
GroupCode: string,
|
1104
|
+
search?: {
|
1105
|
+
PrivilegeCode?: string;
|
1106
|
+
ObjectType?: string;
|
1107
|
+
ObjectId?: string;
|
1108
|
+
SystemCode?: string;
|
1109
|
+
}
|
1110
|
+
): Promise<SystemPrivilege[]> {
|
1111
|
+
try {
|
1112
|
+
// Part 1: Privilege Checking
|
1113
|
+
const systemCode = ApplicationConfig.getComponentConfigValue('system-code');
|
1114
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
1115
|
+
systemCode,
|
1116
|
+
'GROUP_PRIVILEGE_VIEW',
|
1117
|
+
);
|
1118
|
+
|
1119
|
+
if (!isPrivileged) {
|
1120
|
+
throw new ClassError(
|
1121
|
+
'Group',
|
1122
|
+
'GroupErrMsg11',
|
1123
|
+
'You do not have the privilege to view group privileges',
|
1124
|
+
);
|
1125
|
+
}
|
1126
|
+
|
1127
|
+
// Part 2: Validation
|
1128
|
+
// Set group to instantiation of existing Group
|
1129
|
+
await Group.init(dbTransaction, GroupCode);
|
1130
|
+
|
1131
|
+
// Part 3: Retrieve Group Own Privilege
|
1132
|
+
// Retrieve group object privileges by calling LoginUser._GroupObjectPrivilegeRepo.findAll
|
1133
|
+
let where: any = {
|
1134
|
+
GroupCode,
|
1135
|
+
};
|
1136
|
+
|
1137
|
+
let systemWhere: any = {};
|
1138
|
+
|
1139
|
+
if (search) {
|
1140
|
+
Object.entries(search).forEach(([key, value]) => {
|
1141
|
+
if (key === 'SystemCode') {
|
1142
|
+
systemWhere[key] = {
|
1143
|
+
[Op.substring]: value,
|
1144
|
+
};
|
1145
|
+
} else {
|
1146
|
+
where[key] = {
|
1147
|
+
[Op.substring]: value,
|
1148
|
+
};
|
1149
|
+
}
|
1150
|
+
});
|
1151
|
+
}
|
1152
|
+
|
1153
|
+
const groupObjectPrivileges = await Group._GroupObjectPrivilegeRepo.findAll({
|
1154
|
+
where,
|
1155
|
+
include: [
|
1156
|
+
{
|
1157
|
+
model: SystemPrivilegeModel,
|
1158
|
+
where: systemWhere,
|
1159
|
+
},
|
1160
|
+
],
|
1161
|
+
transaction: dbTransaction,
|
1162
|
+
});
|
1163
|
+
// Create variable called privileges and Map the SystemPrivilege data retrieved from 3.1 into SystemPrivilege object and push it to the privileges variables
|
1164
|
+
let privileges: SystemPrivilege[] = [];
|
1165
|
+
for (const groupObjectPrivilege of groupObjectPrivileges) {
|
1166
|
+
const systemPrivilege = await SystemPrivilege.init(
|
1167
|
+
dbTransaction,
|
1168
|
+
);
|
1169
|
+
systemPrivilege.setAttributes(groupObjectPrivilege.Privilege.get({ plain: true }));
|
1170
|
+
privileges.push(systemPrivilege);
|
1171
|
+
}
|
1172
|
+
|
1173
|
+
//Remove duplicate
|
1174
|
+
const uniquePrivileges = Array.from(new Set(privileges.map(a => a.PrivilegeCode)))
|
1175
|
+
.map(PrivilegeCode => {
|
1176
|
+
return privileges.find(a => a.PrivilegeCode === PrivilegeCode);
|
1177
|
+
});
|
1178
|
+
|
1179
|
+
// Create the result based on the spec on return then returns it.
|
1180
|
+
return uniquePrivileges;
|
1181
|
+
} catch (error) {
|
1182
|
+
throw error;
|
1183
|
+
}
|
1184
|
+
}
|
1185
|
+
|
1186
|
+
public static async assignGroupPrivileges(
|
1187
|
+
loginUser: LoginUser,
|
1188
|
+
dbTransaction: any,
|
1189
|
+
GroupCode: string,
|
1190
|
+
PrivilegeCodes: string[],
|
1191
|
+
) {
|
1192
|
+
try {
|
1193
|
+
// Part 1: Privilege Checking
|
1194
|
+
const systemCode = ApplicationConfig.getComponentConfigValue('system-code');
|
1195
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
1196
|
+
systemCode,
|
1197
|
+
'GROUP_PRIVILEGE_ASSIGN',
|
1198
|
+
);
|
1199
|
+
|
1200
|
+
if (!isPrivileged) {
|
1201
|
+
throw new ClassError(
|
1202
|
+
'Group',
|
1203
|
+
'GroupErrMsg06',
|
1204
|
+
'You do not have the privilege to assign group privileges',
|
1205
|
+
);
|
1206
|
+
}
|
1207
|
+
|
1208
|
+
// Part 2: Validation, Create and Record Activity
|
1209
|
+
// Initialise group with group init
|
1210
|
+
|
1211
|
+
const group = await Group.init(dbTransaction, GroupCode);
|
1212
|
+
|
1213
|
+
// Retrieve all group system access by calling Group.getSystemAccess
|
1214
|
+
const groupSystemAccesses = await Group.getSystemAccesses(
|
1215
|
+
loginUser,
|
1216
|
+
dbTransaction,
|
1217
|
+
GroupCode,
|
1218
|
+
1,
|
1219
|
+
Number.MAX_SAFE_INTEGER,
|
1220
|
+
{},
|
1221
|
+
);
|
1222
|
+
|
1223
|
+
// If Group.InheritParentSystemAccess == "Y" and Group.ParentGroupCode exist
|
1224
|
+
let parentGroupSystemAccesses: any = {};
|
1225
|
+
if (group.InheritParentSystemAccessYN === 'Y' && group.ParentGroupCode) {
|
1226
|
+
// Retrieve all parent group system access by calling Group.getSystemAccess
|
1227
|
+
parentGroupSystemAccesses = await Group.getSystemAccesses(
|
1228
|
+
loginUser,
|
1229
|
+
dbTransaction,
|
1230
|
+
group.ParentGroupCode,
|
1231
|
+
1,
|
1232
|
+
Number.MAX_SAFE_INTEGER,
|
1233
|
+
{},
|
1234
|
+
);
|
1235
|
+
}
|
1236
|
+
|
1237
|
+
// For each Params.PrivilegesCodes.
|
1238
|
+
for (const PrivilegeCode of PrivilegeCodes) {
|
1239
|
+
// Initialise existing System privilege by calling SystemPrivilege.init
|
1240
|
+
const systemPrivilege = await SystemPrivilege.init(dbTransaction, PrivilegeCode);
|
1241
|
+
//Check whether the system codes used by that privilege is exist inside the group system access retrieved from step 2.2 & 2.4. If system code does not exist in group system access, throw a new ClassError by passing:
|
1242
|
+
// Classname: "Group"
|
1243
|
+
// MessageCode: "GroupErrMsg0X"
|
1244
|
+
// Message: "Failed to assign privilege <PrivilegeCode> due to non-existent system access."
|
1245
|
+
const combinedSystemAccesses = {
|
1246
|
+
...groupSystemAccesses.rows,
|
1247
|
+
...parentGroupSystemAccesses.rows,
|
1248
|
+
};
|
1249
|
+
const systemAccess = combinedSystemAccesses.find(
|
1250
|
+
(systemAccess) => systemAccess.SystemCode === systemPrivilege.SystemCode,
|
1251
|
+
);
|
1252
|
+
if (!systemAccess) {
|
1253
|
+
throw new ClassError(
|
1254
|
+
'Group',
|
1255
|
+
'GroupErrMsg13',
|
1256
|
+
'Failed to assign privilege ' + PrivilegeCode + ' due to non-existent system access.',
|
1257
|
+
);
|
1258
|
+
}
|
1259
|
+
|
1260
|
+
//Check whether the group privilege exist by using Group._GroupPrivilegesRepo.findOne
|
1261
|
+
const groupPrivilege = await Group._GroupPrivilegeRepo.findOne({
|
1262
|
+
where: {
|
1263
|
+
GroupCode,
|
1264
|
+
PrivilegeCode,
|
1265
|
+
},
|
1266
|
+
transaction: dbTransaction,
|
1267
|
+
});
|
1268
|
+
|
1269
|
+
//If GroupPrivilege record exist and status is "Active". Skip this loop and proceed to the next privilege code
|
1270
|
+
if (groupPrivilege && groupPrivilege.Status === 'Active') {
|
1271
|
+
continue;
|
1272
|
+
}
|
1273
|
+
|
1274
|
+
let entityValueBefore = {};
|
1275
|
+
let entityValueAfter = {};
|
1276
|
+
let action = ActionEnum.ADD;
|
1277
|
+
let description = 'Create Group Privilege';
|
1278
|
+
let entityId = null;
|
1279
|
+
//If GroupPrivilege record exist and status is not "Active" do the following:
|
1280
|
+
if (groupPrivilege && groupPrivilege.Status !== 'Active') {
|
1281
|
+
//Set this GroupPrivilege entity as EntityValueBefore
|
1282
|
+
entityValueBefore = {
|
1283
|
+
GroupCode: groupPrivilege.GroupCode,
|
1284
|
+
PrivilegeCode: groupPrivilege.PrivilegeCode,
|
1285
|
+
Status: groupPrivilege.Status,
|
1286
|
+
CreatedById: groupPrivilege.CreatedById,
|
1287
|
+
CreatedAt: groupPrivilege.CreatedAt,
|
1288
|
+
UpdatedById: groupPrivilege.UpdatedById,
|
1289
|
+
UpdatedAt: groupPrivilege.UpdatedAt,
|
1290
|
+
};
|
1291
|
+
|
1292
|
+
//Update the status to active using Group._GroupPrivilegesRepo.Update.
|
1293
|
+
const updatedPayload = {
|
1294
|
+
Status: 'Active',
|
1295
|
+
UpdatedById: loginUser.UserId,
|
1296
|
+
UpdatedAt: new Date(),
|
1297
|
+
};
|
1298
|
+
await Group._GroupPrivilegeRepo.update(
|
1299
|
+
updatedPayload,
|
1300
|
+
{
|
1301
|
+
where: {
|
1302
|
+
GroupCode,
|
1303
|
+
PrivilegeCode,
|
1304
|
+
},
|
1305
|
+
transaction: dbTransaction,
|
1306
|
+
},
|
1307
|
+
);
|
1308
|
+
|
1309
|
+
//Set updated GroupPrivilege as EntityValueAfter
|
1310
|
+
entityValueAfter = {
|
1311
|
+
GroupCode: groupPrivilege.GroupCode,
|
1312
|
+
PrivilegeCode: groupPrivilege.PrivilegeCode,
|
1313
|
+
Status: updatedPayload.Status,
|
1314
|
+
CreatedById: groupPrivilege.CreatedById,
|
1315
|
+
CreatedAt: groupPrivilege.CreatedAt,
|
1316
|
+
UpdatedById: updatedPayload.UpdatedById,
|
1317
|
+
UpdatedAt: updatedPayload.UpdatedAt,
|
1318
|
+
};
|
1319
|
+
|
1320
|
+
//Instantiate new activity from Activity class
|
1321
|
+
action = ActionEnum.UPDATE;
|
1322
|
+
description = 'Update Group Privilege';
|
1323
|
+
entityId = groupPrivilege.GroupPrivilegeId;
|
1324
|
+
} else {
|
1325
|
+
//If GroupPrivilege record does not exist, do the following:
|
1326
|
+
//Initialise empty GroupPrivilege.
|
1327
|
+
const newGroupPrivilege = await GroupPrivilege.init(dbTransaction);
|
1328
|
+
//Set the attributes
|
1329
|
+
newGroupPrivilege.setAttributes({
|
1330
|
+
GroupCode,
|
1331
|
+
PrivilegeCode,
|
1332
|
+
Status: 'Active',
|
1333
|
+
CreatedById: loginUser.UserId,
|
1334
|
+
CreatedAt: new Date(),
|
1335
|
+
UpdatedById: loginUser.UserId,
|
1336
|
+
UpdatedAt: new Date(),
|
1337
|
+
});
|
1338
|
+
|
1339
|
+
// Set EntityValueAfter to above instance.
|
1340
|
+
entityValueAfter = {
|
1341
|
+
GroupCode: newGroupPrivilege.GroupCode,
|
1342
|
+
PrivilegeCode: newGroupPrivilege.PrivilegeCode,
|
1343
|
+
Status: newGroupPrivilege.Status,
|
1344
|
+
CreatedById: newGroupPrivilege.CreatedById,
|
1345
|
+
CreatedAt: newGroupPrivilege.CreatedAt,
|
1346
|
+
UpdatedById: newGroupPrivilege.UpdatedById,
|
1347
|
+
UpdatedAt: newGroupPrivilege.UpdatedAt,
|
1348
|
+
};
|
1349
|
+
|
1350
|
+
//Call Group._GroupPrivilegesRepo.create
|
1351
|
+
const groupPrivilege = await Group._GroupPrivilegeRepo.create(entityValueAfter, {
|
1352
|
+
transaction: dbTransaction,
|
1353
|
+
});
|
1354
|
+
action = ActionEnum.ADD;
|
1355
|
+
description = 'Create Group Privilege';
|
1356
|
+
entityId = groupPrivilege.GroupPrivilegeId;
|
1357
|
+
}
|
1358
|
+
|
1359
|
+
//Instantiate new activity from Activity class, call createId() method, then set:
|
1360
|
+
const activity = new Activity();
|
1361
|
+
activity.ActivityId = activity.createId();
|
1362
|
+
activity.Action = action;
|
1363
|
+
activity.Description = description;
|
1364
|
+
activity.EntityType = 'GroupPrivilege';
|
1365
|
+
activity.EntityId = entityId;
|
1366
|
+
activity.EntityValueBefore = JSON.stringify(entityValueBefore);
|
1367
|
+
activity.EntityValueAfter = JSON.stringify(entityValueAfter);
|
1368
|
+
|
1369
|
+
//Call new activity create method
|
1370
|
+
await activity.create(loginUser.ObjectId, dbTransaction);
|
1371
|
+
}
|
1372
|
+
|
1373
|
+
return 'Successfully added.';
|
1374
|
+
} catch (error) {
|
1375
|
+
throw error;
|
1376
|
+
}
|
1377
|
+
}
|
1378
|
+
|
1379
|
+
public static async deleteGroupPrivilege(
|
1380
|
+
loginUser: LoginUser,
|
1381
|
+
dbTransaction: any,
|
1382
|
+
GroupCode: string,
|
1383
|
+
PrivilegeCodes: string[],
|
1384
|
+
) {
|
1385
|
+
try {
|
1386
|
+
// Part 1: Privilege Checking
|
1387
|
+
const systemCode = ApplicationConfig.getComponentConfigValue('system-code');
|
1388
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
1389
|
+
systemCode,
|
1390
|
+
'GROUP_PRIVILEGE_DELETE',
|
1391
|
+
);
|
1392
|
+
|
1393
|
+
if (!isPrivileged) {
|
1394
|
+
throw new ClassError(
|
1395
|
+
'Group',
|
1396
|
+
'GroupErrMsg06',
|
1397
|
+
'You do not have the privilege to delete group privileges',
|
1398
|
+
);
|
1399
|
+
}
|
1400
|
+
|
1401
|
+
// Part 2: Validation, Create and Record Activity
|
1402
|
+
// For each Params.PrivilegesCodes.
|
1403
|
+
for (const PrivilegeCode of PrivilegeCodes) {
|
1404
|
+
//Check whether the record exist in database by calling Group._GroupPrivilegeRepo.findOne
|
1405
|
+
const groupPrivilege = await Group._GroupPrivilegeRepo.findOne({
|
1406
|
+
where: {
|
1407
|
+
GroupCode,
|
1408
|
+
PrivilegeCode,
|
1409
|
+
},
|
1410
|
+
transaction: dbTransaction,
|
1411
|
+
});
|
1412
|
+
|
1413
|
+
//If the record does not exist, throw a new ClassError
|
1414
|
+
if (!groupPrivilege) {
|
1415
|
+
throw new ClassError(
|
1416
|
+
'Group',
|
1417
|
+
'GroupErrMsg14',
|
1418
|
+
'GroupPrivilege not found.',
|
1419
|
+
);
|
1420
|
+
}
|
1421
|
+
|
1422
|
+
//Set the EntityValueBefore to the GroupPrivilegesValue from step 1.c.
|
1423
|
+
const entityValueBefore = {
|
1424
|
+
GroupCode: groupPrivilege.GroupCode,
|
1425
|
+
PrivilegeCode: groupPrivilege.PrivilegeCode,
|
1426
|
+
Status: groupPrivilege.Status,
|
1427
|
+
CreatedById: groupPrivilege.CreatedById,
|
1428
|
+
CreatedAt: groupPrivilege.CreatedAt,
|
1429
|
+
UpdatedById: groupPrivilege.UpdatedById,
|
1430
|
+
UpdatedAt: groupPrivilege.UpdatedAt,
|
1431
|
+
};
|
1432
|
+
|
1433
|
+
//Call Group._GroupPrivilegeRepo.delete
|
1434
|
+
await Group._GroupPrivilegeRepo.delete(
|
1435
|
+
GroupCode,
|
1436
|
+
PrivilegeCode,
|
1437
|
+
dbTransaction,
|
1438
|
+
);
|
1439
|
+
// Instantiate new activity from Activity class, call createId() method, then set:
|
1440
|
+
const activity = new Activity();
|
1441
|
+
activity.ActivityId = activity.createId();
|
1442
|
+
activity.Action = ActionEnum.DELETE;
|
1443
|
+
activity.Description = 'DELETE Group Privilege';
|
1444
|
+
activity.EntityType = 'GroupPrivilege';
|
1445
|
+
activity.EntityId = groupPrivilege.GroupPrivilegeId.toString();
|
1446
|
+
activity.EntityValueBefore = JSON.stringify(entityValueBefore);
|
1447
|
+
activity.EntityValueAfter = JSON.stringify({});
|
1448
|
+
//Call new activity create method
|
1449
|
+
await activity.create(loginUser.ObjectId, dbTransaction);
|
1450
|
+
}
|
1451
|
+
return 'Successfully deleted.';
|
1452
|
+
} catch (error) {
|
1453
|
+
throw error;
|
1454
|
+
}
|
1455
|
+
}
|
1456
|
+
}
|