@tomei/sso 0.36.0 → 0.37.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/src/components/user-group/user-group.d.ts +4 -0
- package/dist/src/components/user-group/user-group.js +95 -0
- package/dist/src/components/user-group/user-group.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/user-group/user-group.ts +210 -2
@@ -1,4 +1,6 @@
|
|
1
1
|
import { ObjectBase } from '@tomei/general';
|
2
|
+
import { LoginUser, User } from '../../components/login-user';
|
3
|
+
import { Group } from '../../components/group';
|
2
4
|
export declare class UserGroup extends ObjectBase {
|
3
5
|
ObjectType: string;
|
4
6
|
TableName: string;
|
@@ -21,4 +23,6 @@ export declare class UserGroup extends ObjectBase {
|
|
21
23
|
private static _Repository;
|
22
24
|
private constructor();
|
23
25
|
static init(dbTransaction: any, UserGroupId?: number): Promise<UserGroup>;
|
26
|
+
create(loginUser: LoginUser, dbTransaction: any, group: Group, user: User): Promise<UserGroup>;
|
27
|
+
static findOne(dbTransaction: any, loginUser: LoginUser, GroupCode: string, UserId: number): Promise<UserGroup>;
|
24
28
|
}
|
@@ -12,6 +12,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.UserGroup = void 0;
|
13
13
|
const general_1 = require("@tomei/general");
|
14
14
|
const user_group_repository_1 = require("./user-group.repository");
|
15
|
+
const config_1 = require("@tomei/config");
|
16
|
+
const activity_history_1 = require("@tomei/activity-history");
|
15
17
|
class UserGroup extends general_1.ObjectBase {
|
16
18
|
get CreatedAt() {
|
17
19
|
return this._CreatedAt;
|
@@ -29,6 +31,8 @@ class UserGroup extends general_1.ObjectBase {
|
|
29
31
|
super();
|
30
32
|
this.ObjectType = 'UserGroup';
|
31
33
|
this.TableName = 'sso_UserGroup';
|
34
|
+
this.InheritGroupPrivilegeYN = 'Y';
|
35
|
+
this.InheritGroupSystemAccessYN = 'Y';
|
32
36
|
if (userGroupAttr) {
|
33
37
|
this.UserGroupId = userGroupAttr.UserGroupId;
|
34
38
|
this.UserId = userGroupAttr.UserId;
|
@@ -77,6 +81,97 @@ class UserGroup extends general_1.ObjectBase {
|
|
77
81
|
}
|
78
82
|
});
|
79
83
|
}
|
84
|
+
create(loginUser, dbTransaction, group, user) {
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
86
|
+
try {
|
87
|
+
const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
88
|
+
const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'USER_GROUP_CREATE');
|
89
|
+
if (!isPrivileged) {
|
90
|
+
throw new general_1.ClassError('UserGroup', 'UserGroupErrMsg0X', 'User does not have privilege to create user group.');
|
91
|
+
}
|
92
|
+
if (!group.GroupCode) {
|
93
|
+
throw new general_1.ClassError('UserGroup', 'UserGroupErrMsg02', 'GroupCode is required.');
|
94
|
+
}
|
95
|
+
if (!user.UserId) {
|
96
|
+
throw new general_1.ClassError('UserGroup', 'UserGroupErrMsg03', 'UserId is required.');
|
97
|
+
}
|
98
|
+
const userGroup = yield UserGroup.findOne(dbTransaction, loginUser, group.GroupCode, user.UserId);
|
99
|
+
if (userGroup) {
|
100
|
+
return userGroup;
|
101
|
+
}
|
102
|
+
this.UserId = user.UserId;
|
103
|
+
this.GroupCode = group.GroupCode;
|
104
|
+
this.Status = 'Active';
|
105
|
+
this._CreatedById = loginUser.UserId;
|
106
|
+
this._CreatedAt = new Date();
|
107
|
+
this._UpdatedById = loginUser.UserId;
|
108
|
+
this._UpdatedAt = new Date();
|
109
|
+
const userData = yield UserGroup._Repository.create({
|
110
|
+
UserId: this.UserId,
|
111
|
+
GroupCode: this.GroupCode,
|
112
|
+
Status: this.Status,
|
113
|
+
CreatedById: this._CreatedById,
|
114
|
+
CreatedAt: this._CreatedAt,
|
115
|
+
UpdatedById: this._UpdatedById,
|
116
|
+
UpdatedAt: this._UpdatedAt,
|
117
|
+
InheritGroupPrivilegeYN: this.InheritGroupPrivilegeYN,
|
118
|
+
InheritGroupSystemAccessYN: this.InheritGroupSystemAccessYN,
|
119
|
+
}, {
|
120
|
+
transaction: dbTransaction,
|
121
|
+
});
|
122
|
+
this.UserGroupId = userData.UserGroupId;
|
123
|
+
const EntityValueAfter = {
|
124
|
+
UserGroupId: this.UserGroupId,
|
125
|
+
UserId: this.UserId,
|
126
|
+
GroupCode: this.GroupCode,
|
127
|
+
Status: this.Status,
|
128
|
+
CreatedById: this._CreatedById,
|
129
|
+
CreatedAt: this._CreatedAt,
|
130
|
+
UpdatedById: this._UpdatedById,
|
131
|
+
UpdatedAt: this._UpdatedAt,
|
132
|
+
InheritGroupPrivilegeYN: this.InheritGroupPrivilegeYN,
|
133
|
+
InheritGroupSystemAccessYN: this.InheritGroupSystemAccessYN,
|
134
|
+
};
|
135
|
+
const activity = new activity_history_1.Activity();
|
136
|
+
activity.Action = activity_history_1.ActionEnum.ADD;
|
137
|
+
activity.Description = 'Assign user to group.';
|
138
|
+
activity.EntityType = 'UserGroup';
|
139
|
+
activity.EntityId = this.UserGroupId.toString();
|
140
|
+
activity.EntityValueBefore = JSON.stringify({});
|
141
|
+
activity.EntityValueAfter = JSON.stringify(EntityValueAfter);
|
142
|
+
yield activity.create(loginUser.ObjectId, dbTransaction);
|
143
|
+
return this;
|
144
|
+
}
|
145
|
+
catch (error) {
|
146
|
+
throw error;
|
147
|
+
}
|
148
|
+
});
|
149
|
+
}
|
150
|
+
static findOne(dbTransaction, loginUser, GroupCode, UserId) {
|
151
|
+
return __awaiter(this, void 0, void 0, function* () {
|
152
|
+
try {
|
153
|
+
const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
154
|
+
const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'USER_GROUP_VIEW');
|
155
|
+
if (!isPrivileged) {
|
156
|
+
throw new general_1.ClassError('UserGroup', 'UserGroupErrMsg0X', 'User does not have privilege to view user group.');
|
157
|
+
}
|
158
|
+
const userGroupAttr = yield UserGroup._Repository.findOne({
|
159
|
+
where: {
|
160
|
+
UserId,
|
161
|
+
GroupCode,
|
162
|
+
},
|
163
|
+
transaction: dbTransaction,
|
164
|
+
});
|
165
|
+
if (userGroupAttr) {
|
166
|
+
return new UserGroup(userGroupAttr.get({ plain: true }));
|
167
|
+
}
|
168
|
+
return null;
|
169
|
+
}
|
170
|
+
catch (error) {
|
171
|
+
throw error;
|
172
|
+
}
|
173
|
+
});
|
174
|
+
}
|
80
175
|
}
|
81
176
|
exports.UserGroup = UserGroup;
|
82
177
|
UserGroup._Repository = new user_group_repository_1.UserGroupRepository();
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"user-group.js","sourceRoot":"","sources":["../../../../src/components/user-group/user-group.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAAwD;AACxD,mEAA8D;
|
1
|
+
{"version":3,"file":"user-group.js","sourceRoot":"","sources":["../../../../src/components/user-group/user-group.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAAwD;AACxD,mEAA8D;AAI9D,0CAAkD;AAClD,8DAA+D;AAE/D,MAAa,SAAU,SAAQ,oBAAU;IAgBvC,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAID,YAAoB,aAA8B;QAChD,KAAK,EAAE,CAAC;QAlCV,eAAU,GAAG,WAAW,CAAC;QACzB,cAAS,GAAG,eAAe,CAAC;QAM5B,4BAAuB,GAAG,GAAG,CAAC;QAC9B,+BAA0B,GAAG,GAAG,CAAC;QA2B/B,IAAI,aAAa,EAAE;YACjB,IAAI,CAAC,WAAW,GAAG,aAAa,CAAC,WAAW,CAAC;YAC7C,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC;YACnC,IAAI,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