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