@abpjs/identity-pro 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +165 -0
- package/README.md +402 -0
- package/dist/index.d.mts +805 -0
- package/dist/index.d.ts +805 -0
- package/dist/index.js +1910 -0
- package/dist/index.mjs +1909 -0
- package/package.json +90 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1910 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
ClaimModal: () => ClaimModal,
|
|
24
|
+
ClaimsComponent: () => ClaimsComponent,
|
|
25
|
+
IDENTITY_POLICIES: () => IDENTITY_POLICIES,
|
|
26
|
+
IDENTITY_ROUTES: () => IDENTITY_ROUTES,
|
|
27
|
+
IDENTITY_ROUTE_PATHS: () => IDENTITY_ROUTE_PATHS,
|
|
28
|
+
Identity: () => Identity,
|
|
29
|
+
IdentityService: () => IdentityService,
|
|
30
|
+
RolesComponent: () => RolesComponent,
|
|
31
|
+
UsersComponent: () => UsersComponent,
|
|
32
|
+
useClaims: () => useClaims,
|
|
33
|
+
useIdentity: () => useIdentity,
|
|
34
|
+
useRoles: () => useRoles,
|
|
35
|
+
useUsers: () => useUsers
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(index_exports);
|
|
38
|
+
|
|
39
|
+
// src/models/identity.ts
|
|
40
|
+
var Identity;
|
|
41
|
+
((Identity2) => {
|
|
42
|
+
let ClaimValueType;
|
|
43
|
+
((ClaimValueType2) => {
|
|
44
|
+
ClaimValueType2[ClaimValueType2["String"] = 0] = "String";
|
|
45
|
+
ClaimValueType2[ClaimValueType2["Int"] = 1] = "Int";
|
|
46
|
+
ClaimValueType2[ClaimValueType2["Boolean"] = 2] = "Boolean";
|
|
47
|
+
ClaimValueType2[ClaimValueType2["DateTime"] = 3] = "DateTime";
|
|
48
|
+
})(ClaimValueType = Identity2.ClaimValueType || (Identity2.ClaimValueType = {}));
|
|
49
|
+
})(Identity || (Identity = {}));
|
|
50
|
+
|
|
51
|
+
// src/services/identity.service.ts
|
|
52
|
+
var IdentityService = class {
|
|
53
|
+
constructor(rest) {
|
|
54
|
+
this.rest = rest;
|
|
55
|
+
}
|
|
56
|
+
// ========================
|
|
57
|
+
// Role Operations
|
|
58
|
+
// ========================
|
|
59
|
+
/**
|
|
60
|
+
* Get all roles with optional pagination/filtering (v0.9.0)
|
|
61
|
+
* @param params - Optional query parameters for pagination and filtering
|
|
62
|
+
* @returns Promise with paginated role response
|
|
63
|
+
*/
|
|
64
|
+
getRoles(params = {}) {
|
|
65
|
+
return this.rest.request({
|
|
66
|
+
method: "GET",
|
|
67
|
+
url: "/api/identity/roles",
|
|
68
|
+
params
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get a role by ID
|
|
73
|
+
* @param id - The role ID
|
|
74
|
+
* @returns Promise with the role item
|
|
75
|
+
*/
|
|
76
|
+
getRoleById(id) {
|
|
77
|
+
return this.rest.request({
|
|
78
|
+
method: "GET",
|
|
79
|
+
url: `/api/identity/roles/${id}`
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Delete a role
|
|
84
|
+
* @param id - The role ID to delete
|
|
85
|
+
* @returns Promise with the deleted role
|
|
86
|
+
*/
|
|
87
|
+
deleteRole(id) {
|
|
88
|
+
return this.rest.request({
|
|
89
|
+
method: "DELETE",
|
|
90
|
+
url: `/api/identity/roles/${id}`
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Create a new role
|
|
95
|
+
* @param body - The role data to create
|
|
96
|
+
* @returns Promise with the created role
|
|
97
|
+
*/
|
|
98
|
+
createRole(body) {
|
|
99
|
+
return this.rest.request({
|
|
100
|
+
method: "POST",
|
|
101
|
+
url: "/api/identity/roles",
|
|
102
|
+
body
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Update an existing role
|
|
107
|
+
* @param id - The role ID to update
|
|
108
|
+
* @param body - The updated role data
|
|
109
|
+
* @returns Promise with the updated role
|
|
110
|
+
*/
|
|
111
|
+
updateRole(id, body) {
|
|
112
|
+
return this.rest.request({
|
|
113
|
+
method: "PUT",
|
|
114
|
+
url: `/api/identity/roles/${id}`,
|
|
115
|
+
body
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
// ========================
|
|
119
|
+
// User Operations
|
|
120
|
+
// ========================
|
|
121
|
+
/**
|
|
122
|
+
* Get users with pagination and filtering
|
|
123
|
+
* @param params - Query parameters for pagination and filtering
|
|
124
|
+
* @returns Promise with paginated user response
|
|
125
|
+
*/
|
|
126
|
+
getUsers(params = {}) {
|
|
127
|
+
return this.rest.request({
|
|
128
|
+
method: "GET",
|
|
129
|
+
url: "/api/identity/users",
|
|
130
|
+
params
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Get a user by ID
|
|
135
|
+
* @param id - The user ID
|
|
136
|
+
* @returns Promise with the user item
|
|
137
|
+
*/
|
|
138
|
+
getUserById(id) {
|
|
139
|
+
return this.rest.request({
|
|
140
|
+
method: "GET",
|
|
141
|
+
url: `/api/identity/users/${id}`
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Get roles assigned to a user
|
|
146
|
+
* @param id - The user ID
|
|
147
|
+
* @returns Promise with the user's roles
|
|
148
|
+
*/
|
|
149
|
+
getUserRoles(id) {
|
|
150
|
+
return this.rest.request({
|
|
151
|
+
method: "GET",
|
|
152
|
+
url: `/api/identity/users/${id}/roles`
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Delete a user
|
|
157
|
+
* @param id - The user ID to delete
|
|
158
|
+
* @returns Promise resolving when complete
|
|
159
|
+
*/
|
|
160
|
+
deleteUser(id) {
|
|
161
|
+
return this.rest.request({
|
|
162
|
+
method: "DELETE",
|
|
163
|
+
url: `/api/identity/users/${id}`
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Create a new user
|
|
168
|
+
* @param body - The user data to create
|
|
169
|
+
* @returns Promise with the created user
|
|
170
|
+
*/
|
|
171
|
+
createUser(body) {
|
|
172
|
+
return this.rest.request({
|
|
173
|
+
method: "POST",
|
|
174
|
+
url: "/api/identity/users",
|
|
175
|
+
body
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Update an existing user
|
|
180
|
+
* @param id - The user ID to update
|
|
181
|
+
* @param body - The updated user data
|
|
182
|
+
* @returns Promise with the updated user
|
|
183
|
+
*/
|
|
184
|
+
updateUser(id, body) {
|
|
185
|
+
return this.rest.request({
|
|
186
|
+
method: "PUT",
|
|
187
|
+
url: `/api/identity/users/${id}`,
|
|
188
|
+
body
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
// ========================
|
|
192
|
+
// Pro: Claim Type Operations
|
|
193
|
+
// ========================
|
|
194
|
+
/**
|
|
195
|
+
* Get all claim type names for dropdowns
|
|
196
|
+
* Pro feature since 0.7.2
|
|
197
|
+
* @returns Promise with claim type names
|
|
198
|
+
*/
|
|
199
|
+
getClaimTypeNames() {
|
|
200
|
+
return this.rest.request({
|
|
201
|
+
method: "GET",
|
|
202
|
+
url: "/api/identity/claim-types/all"
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Get claim types with pagination
|
|
207
|
+
* Pro feature since 0.7.2
|
|
208
|
+
* @param params - Query parameters for pagination and filtering
|
|
209
|
+
* @returns Promise with paginated claim types response
|
|
210
|
+
*/
|
|
211
|
+
getClaimTypes(params = {}) {
|
|
212
|
+
return this.rest.request({
|
|
213
|
+
method: "GET",
|
|
214
|
+
url: "/api/identity/claim-types",
|
|
215
|
+
params
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Get a claim type by ID
|
|
220
|
+
* Pro feature since 0.7.2
|
|
221
|
+
* @param id - The claim type ID
|
|
222
|
+
* @returns Promise with the claim type
|
|
223
|
+
*/
|
|
224
|
+
getClaimTypeById(id) {
|
|
225
|
+
return this.rest.request({
|
|
226
|
+
method: "GET",
|
|
227
|
+
url: `/api/identity/claim-types/${id}`
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Create a new claim type
|
|
232
|
+
* Pro feature since 0.7.2
|
|
233
|
+
* @param body - The claim type data
|
|
234
|
+
* @returns Promise with the created claim type
|
|
235
|
+
*/
|
|
236
|
+
createClaimType(body) {
|
|
237
|
+
return this.rest.request({
|
|
238
|
+
method: "POST",
|
|
239
|
+
url: "/api/identity/claim-types",
|
|
240
|
+
body
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Update an existing claim type
|
|
245
|
+
* Pro feature since 0.7.2
|
|
246
|
+
* @param body - The claim type data (must include id)
|
|
247
|
+
* @returns Promise with the updated claim type
|
|
248
|
+
*/
|
|
249
|
+
updateClaimType(body) {
|
|
250
|
+
return this.rest.request({
|
|
251
|
+
method: "PUT",
|
|
252
|
+
url: `/api/identity/claim-types/${body.id}`,
|
|
253
|
+
body
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Delete a claim type
|
|
258
|
+
* Pro feature since 0.7.2
|
|
259
|
+
* @param id - The claim type ID to delete
|
|
260
|
+
* @returns Promise resolving when complete
|
|
261
|
+
*/
|
|
262
|
+
deleteClaimType(id) {
|
|
263
|
+
return this.rest.request({
|
|
264
|
+
method: "DELETE",
|
|
265
|
+
url: `/api/identity/claim-types/${id}`
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
// ========================
|
|
269
|
+
// Pro: User/Role Claims
|
|
270
|
+
// ========================
|
|
271
|
+
/**
|
|
272
|
+
* Get claims for a user or role
|
|
273
|
+
* Pro feature since 0.7.2
|
|
274
|
+
* @param body - Object with id and type ('users' | 'roles')
|
|
275
|
+
* @returns Promise with claim requests
|
|
276
|
+
*/
|
|
277
|
+
getClaims(body) {
|
|
278
|
+
return this.rest.request({
|
|
279
|
+
method: "GET",
|
|
280
|
+
url: `/api/identity/${body.type}/${body.id}/claims`
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Update claims for a user or role
|
|
285
|
+
* Pro feature since 0.7.2
|
|
286
|
+
* @param body - Object with id, type, and claims array
|
|
287
|
+
* @returns Promise resolving when complete
|
|
288
|
+
*/
|
|
289
|
+
updateClaims(body) {
|
|
290
|
+
return this.rest.request({
|
|
291
|
+
method: "PUT",
|
|
292
|
+
url: `/api/identity/${body.type}/${body.id}/claims`,
|
|
293
|
+
body: body.claims
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
// src/hooks/useRoles.ts
|
|
299
|
+
var import_react = require("react");
|
|
300
|
+
var import_core = require("@abpjs/core");
|
|
301
|
+
function useRoles() {
|
|
302
|
+
const restService = (0, import_core.useRestService)();
|
|
303
|
+
const service = (0, import_react.useMemo)(() => new IdentityService(restService), [restService]);
|
|
304
|
+
const [roles, setRoles] = (0, import_react.useState)([]);
|
|
305
|
+
const [totalCount, setTotalCount] = (0, import_react.useState)(0);
|
|
306
|
+
const [selectedRole, setSelectedRole] = (0, import_react.useState)(null);
|
|
307
|
+
const [isLoading, setIsLoading] = (0, import_react.useState)(false);
|
|
308
|
+
const [error, setError] = (0, import_react.useState)(null);
|
|
309
|
+
const [sortKey, setSortKey] = (0, import_react.useState)("name");
|
|
310
|
+
const [sortOrder, setSortOrder] = (0, import_react.useState)("");
|
|
311
|
+
const fetchRoles = (0, import_react.useCallback)(async (params) => {
|
|
312
|
+
setIsLoading(true);
|
|
313
|
+
setError(null);
|
|
314
|
+
try {
|
|
315
|
+
const response = await service.getRoles(params);
|
|
316
|
+
setRoles(response.items || []);
|
|
317
|
+
setTotalCount(response.totalCount || 0);
|
|
318
|
+
setIsLoading(false);
|
|
319
|
+
return { success: true };
|
|
320
|
+
} catch (err) {
|
|
321
|
+
const errorMessage = err instanceof Error ? err.message : "Failed to fetch roles";
|
|
322
|
+
setError(errorMessage);
|
|
323
|
+
setIsLoading(false);
|
|
324
|
+
return { success: false, error: errorMessage };
|
|
325
|
+
}
|
|
326
|
+
}, [service]);
|
|
327
|
+
const getRoleById = (0, import_react.useCallback)(
|
|
328
|
+
async (id) => {
|
|
329
|
+
setIsLoading(true);
|
|
330
|
+
setError(null);
|
|
331
|
+
try {
|
|
332
|
+
const role = await service.getRoleById(id);
|
|
333
|
+
setSelectedRole(role);
|
|
334
|
+
setIsLoading(false);
|
|
335
|
+
return { success: true };
|
|
336
|
+
} catch (err) {
|
|
337
|
+
const errorMessage = err instanceof Error ? err.message : "Failed to fetch role";
|
|
338
|
+
setError(errorMessage);
|
|
339
|
+
setIsLoading(false);
|
|
340
|
+
return { success: false, error: errorMessage };
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
[service]
|
|
344
|
+
);
|
|
345
|
+
const createRole = (0, import_react.useCallback)(
|
|
346
|
+
async (role) => {
|
|
347
|
+
setIsLoading(true);
|
|
348
|
+
setError(null);
|
|
349
|
+
try {
|
|
350
|
+
await service.createRole(role);
|
|
351
|
+
await fetchRoles();
|
|
352
|
+
return { success: true };
|
|
353
|
+
} catch (err) {
|
|
354
|
+
const errorMessage = err instanceof Error ? err.message : "Failed to create role";
|
|
355
|
+
setError(errorMessage);
|
|
356
|
+
setIsLoading(false);
|
|
357
|
+
return { success: false, error: errorMessage };
|
|
358
|
+
}
|
|
359
|
+
},
|
|
360
|
+
[service, fetchRoles]
|
|
361
|
+
);
|
|
362
|
+
const updateRole = (0, import_react.useCallback)(
|
|
363
|
+
async (id, role) => {
|
|
364
|
+
setIsLoading(true);
|
|
365
|
+
setError(null);
|
|
366
|
+
try {
|
|
367
|
+
await service.updateRole(id, role);
|
|
368
|
+
await fetchRoles();
|
|
369
|
+
return { success: true };
|
|
370
|
+
} catch (err) {
|
|
371
|
+
const errorMessage = err instanceof Error ? err.message : "Failed to update role";
|
|
372
|
+
setError(errorMessage);
|
|
373
|
+
setIsLoading(false);
|
|
374
|
+
return { success: false, error: errorMessage };
|
|
375
|
+
}
|
|
376
|
+
},
|
|
377
|
+
[service, fetchRoles]
|
|
378
|
+
);
|
|
379
|
+
const deleteRole = (0, import_react.useCallback)(
|
|
380
|
+
async (id) => {
|
|
381
|
+
setIsLoading(true);
|
|
382
|
+
setError(null);
|
|
383
|
+
try {
|
|
384
|
+
await service.deleteRole(id);
|
|
385
|
+
await fetchRoles();
|
|
386
|
+
return { success: true };
|
|
387
|
+
} catch (err) {
|
|
388
|
+
const errorMessage = err instanceof Error ? err.message : "Failed to delete role";
|
|
389
|
+
setError(errorMessage);
|
|
390
|
+
setIsLoading(false);
|
|
391
|
+
return { success: false, error: errorMessage };
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
[service, fetchRoles]
|
|
395
|
+
);
|
|
396
|
+
const reset = (0, import_react.useCallback)(() => {
|
|
397
|
+
setRoles([]);
|
|
398
|
+
setTotalCount(0);
|
|
399
|
+
setSelectedRole(null);
|
|
400
|
+
setIsLoading(false);
|
|
401
|
+
setError(null);
|
|
402
|
+
}, []);
|
|
403
|
+
return {
|
|
404
|
+
roles,
|
|
405
|
+
totalCount,
|
|
406
|
+
selectedRole,
|
|
407
|
+
isLoading,
|
|
408
|
+
error,
|
|
409
|
+
sortKey,
|
|
410
|
+
sortOrder,
|
|
411
|
+
fetchRoles,
|
|
412
|
+
getRoleById,
|
|
413
|
+
createRole,
|
|
414
|
+
updateRole,
|
|
415
|
+
deleteRole,
|
|
416
|
+
setSelectedRole,
|
|
417
|
+
setSortKey,
|
|
418
|
+
setSortOrder,
|
|
419
|
+
reset
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// src/hooks/useUsers.ts
|
|
424
|
+
var import_react2 = require("react");
|
|
425
|
+
var import_core2 = require("@abpjs/core");
|
|
426
|
+
var DEFAULT_PAGE_QUERY = {
|
|
427
|
+
sorting: "userName",
|
|
428
|
+
skipCount: 0,
|
|
429
|
+
maxResultCount: 10
|
|
430
|
+
};
|
|
431
|
+
function useUsers() {
|
|
432
|
+
const restService = (0, import_core2.useRestService)();
|
|
433
|
+
const service = (0, import_react2.useMemo)(() => new IdentityService(restService), [restService]);
|
|
434
|
+
const [users, setUsers] = (0, import_react2.useState)([]);
|
|
435
|
+
const [totalCount, setTotalCount] = (0, import_react2.useState)(0);
|
|
436
|
+
const [selectedUser, setSelectedUser] = (0, import_react2.useState)(null);
|
|
437
|
+
const [selectedUserRoles, setSelectedUserRoles] = (0, import_react2.useState)([]);
|
|
438
|
+
const [isLoading, setIsLoading] = (0, import_react2.useState)(false);
|
|
439
|
+
const [error, setError] = (0, import_react2.useState)(null);
|
|
440
|
+
const [pageQuery, setPageQuery] = (0, import_react2.useState)(DEFAULT_PAGE_QUERY);
|
|
441
|
+
const [sortKey, setSortKey] = (0, import_react2.useState)("userName");
|
|
442
|
+
const [sortOrder, setSortOrder] = (0, import_react2.useState)("");
|
|
443
|
+
const fetchUsers = (0, import_react2.useCallback)(
|
|
444
|
+
async (params) => {
|
|
445
|
+
setIsLoading(true);
|
|
446
|
+
setError(null);
|
|
447
|
+
const queryParams = params || pageQuery;
|
|
448
|
+
try {
|
|
449
|
+
const response = await service.getUsers(queryParams);
|
|
450
|
+
setUsers(response.items || []);
|
|
451
|
+
setTotalCount(response.totalCount || 0);
|
|
452
|
+
setIsLoading(false);
|
|
453
|
+
return { success: true };
|
|
454
|
+
} catch (err) {
|
|
455
|
+
const errorMessage = err instanceof Error ? err.message : "Failed to fetch users";
|
|
456
|
+
setError(errorMessage);
|
|
457
|
+
setIsLoading(false);
|
|
458
|
+
return { success: false, error: errorMessage };
|
|
459
|
+
}
|
|
460
|
+
},
|
|
461
|
+
[service, pageQuery]
|
|
462
|
+
);
|
|
463
|
+
const getUserById = (0, import_react2.useCallback)(
|
|
464
|
+
async (id) => {
|
|
465
|
+
setIsLoading(true);
|
|
466
|
+
setError(null);
|
|
467
|
+
try {
|
|
468
|
+
const user = await service.getUserById(id);
|
|
469
|
+
setSelectedUser(user);
|
|
470
|
+
setIsLoading(false);
|
|
471
|
+
return { success: true };
|
|
472
|
+
} catch (err) {
|
|
473
|
+
const errorMessage = err instanceof Error ? err.message : "Failed to fetch user";
|
|
474
|
+
setError(errorMessage);
|
|
475
|
+
setIsLoading(false);
|
|
476
|
+
return { success: false, error: errorMessage };
|
|
477
|
+
}
|
|
478
|
+
},
|
|
479
|
+
[service]
|
|
480
|
+
);
|
|
481
|
+
const getUserRoles = (0, import_react2.useCallback)(
|
|
482
|
+
async (id) => {
|
|
483
|
+
setIsLoading(true);
|
|
484
|
+
setError(null);
|
|
485
|
+
try {
|
|
486
|
+
const response = await service.getUserRoles(id);
|
|
487
|
+
setSelectedUserRoles(response.items || []);
|
|
488
|
+
setIsLoading(false);
|
|
489
|
+
return { success: true };
|
|
490
|
+
} catch (err) {
|
|
491
|
+
const errorMessage = err instanceof Error ? err.message : "Failed to fetch user roles";
|
|
492
|
+
setError(errorMessage);
|
|
493
|
+
setIsLoading(false);
|
|
494
|
+
return { success: false, error: errorMessage };
|
|
495
|
+
}
|
|
496
|
+
},
|
|
497
|
+
[service]
|
|
498
|
+
);
|
|
499
|
+
const createUser = (0, import_react2.useCallback)(
|
|
500
|
+
async (user) => {
|
|
501
|
+
setIsLoading(true);
|
|
502
|
+
setError(null);
|
|
503
|
+
try {
|
|
504
|
+
await service.createUser(user);
|
|
505
|
+
await fetchUsers();
|
|
506
|
+
return { success: true };
|
|
507
|
+
} catch (err) {
|
|
508
|
+
const errorMessage = err instanceof Error ? err.message : "Failed to create user";
|
|
509
|
+
setError(errorMessage);
|
|
510
|
+
setIsLoading(false);
|
|
511
|
+
return { success: false, error: errorMessage };
|
|
512
|
+
}
|
|
513
|
+
},
|
|
514
|
+
[service, fetchUsers]
|
|
515
|
+
);
|
|
516
|
+
const updateUser = (0, import_react2.useCallback)(
|
|
517
|
+
async (id, user) => {
|
|
518
|
+
setIsLoading(true);
|
|
519
|
+
setError(null);
|
|
520
|
+
try {
|
|
521
|
+
await service.updateUser(id, user);
|
|
522
|
+
await fetchUsers();
|
|
523
|
+
return { success: true };
|
|
524
|
+
} catch (err) {
|
|
525
|
+
const errorMessage = err instanceof Error ? err.message : "Failed to update user";
|
|
526
|
+
setError(errorMessage);
|
|
527
|
+
setIsLoading(false);
|
|
528
|
+
return { success: false, error: errorMessage };
|
|
529
|
+
}
|
|
530
|
+
},
|
|
531
|
+
[service, fetchUsers]
|
|
532
|
+
);
|
|
533
|
+
const deleteUser = (0, import_react2.useCallback)(
|
|
534
|
+
async (id) => {
|
|
535
|
+
setIsLoading(true);
|
|
536
|
+
setError(null);
|
|
537
|
+
try {
|
|
538
|
+
await service.deleteUser(id);
|
|
539
|
+
await fetchUsers();
|
|
540
|
+
return { success: true };
|
|
541
|
+
} catch (err) {
|
|
542
|
+
const errorMessage = err instanceof Error ? err.message : "Failed to delete user";
|
|
543
|
+
setError(errorMessage);
|
|
544
|
+
setIsLoading(false);
|
|
545
|
+
return { success: false, error: errorMessage };
|
|
546
|
+
}
|
|
547
|
+
},
|
|
548
|
+
[service, fetchUsers]
|
|
549
|
+
);
|
|
550
|
+
const reset = (0, import_react2.useCallback)(() => {
|
|
551
|
+
setUsers([]);
|
|
552
|
+
setTotalCount(0);
|
|
553
|
+
setSelectedUser(null);
|
|
554
|
+
setSelectedUserRoles([]);
|
|
555
|
+
setIsLoading(false);
|
|
556
|
+
setError(null);
|
|
557
|
+
setPageQuery(DEFAULT_PAGE_QUERY);
|
|
558
|
+
}, []);
|
|
559
|
+
return {
|
|
560
|
+
users,
|
|
561
|
+
totalCount,
|
|
562
|
+
selectedUser,
|
|
563
|
+
selectedUserRoles,
|
|
564
|
+
isLoading,
|
|
565
|
+
error,
|
|
566
|
+
pageQuery,
|
|
567
|
+
sortKey,
|
|
568
|
+
sortOrder,
|
|
569
|
+
fetchUsers,
|
|
570
|
+
getUserById,
|
|
571
|
+
getUserRoles,
|
|
572
|
+
createUser,
|
|
573
|
+
updateUser,
|
|
574
|
+
deleteUser,
|
|
575
|
+
setSelectedUser,
|
|
576
|
+
setPageQuery,
|
|
577
|
+
setSortKey,
|
|
578
|
+
setSortOrder,
|
|
579
|
+
reset
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
// src/hooks/useIdentity.ts
|
|
584
|
+
var import_react3 = require("react");
|
|
585
|
+
function useIdentity() {
|
|
586
|
+
const rolesHook = useRoles();
|
|
587
|
+
const usersHook = useUsers();
|
|
588
|
+
const isLoading = (0, import_react3.useMemo)(
|
|
589
|
+
() => rolesHook.isLoading || usersHook.isLoading,
|
|
590
|
+
[rolesHook.isLoading, usersHook.isLoading]
|
|
591
|
+
);
|
|
592
|
+
const error = (0, import_react3.useMemo)(
|
|
593
|
+
() => rolesHook.error || usersHook.error,
|
|
594
|
+
[rolesHook.error, usersHook.error]
|
|
595
|
+
);
|
|
596
|
+
const resetAll = (0, import_react3.useCallback)(() => {
|
|
597
|
+
rolesHook.reset();
|
|
598
|
+
usersHook.reset();
|
|
599
|
+
}, [rolesHook, usersHook]);
|
|
600
|
+
return {
|
|
601
|
+
roles: rolesHook,
|
|
602
|
+
users: usersHook,
|
|
603
|
+
isLoading,
|
|
604
|
+
error,
|
|
605
|
+
resetAll
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
// src/hooks/useClaims.ts
|
|
610
|
+
var import_react4 = require("react");
|
|
611
|
+
var import_core3 = require("@abpjs/core");
|
|
612
|
+
function useClaims() {
|
|
613
|
+
const restService = (0, import_core3.useRestService)();
|
|
614
|
+
const service = (0, import_react4.useMemo)(() => new IdentityService(restService), [restService]);
|
|
615
|
+
const [claimTypes, setClaimTypes] = (0, import_react4.useState)([]);
|
|
616
|
+
const [totalCount, setTotalCount] = (0, import_react4.useState)(0);
|
|
617
|
+
const [claimTypeNames, setClaimTypeNames] = (0, import_react4.useState)([]);
|
|
618
|
+
const [selectedClaimType, setSelectedClaimType] = (0, import_react4.useState)(null);
|
|
619
|
+
const [isLoading, setIsLoading] = (0, import_react4.useState)(false);
|
|
620
|
+
const [error, setError] = (0, import_react4.useState)(null);
|
|
621
|
+
const [sortKey, setSortKey] = (0, import_react4.useState)("name");
|
|
622
|
+
const [sortOrder, setSortOrder] = (0, import_react4.useState)("");
|
|
623
|
+
const fetchClaimTypes = (0, import_react4.useCallback)(async (params) => {
|
|
624
|
+
setIsLoading(true);
|
|
625
|
+
setError(null);
|
|
626
|
+
try {
|
|
627
|
+
const response = await service.getClaimTypes(params);
|
|
628
|
+
setClaimTypes(response.items || []);
|
|
629
|
+
setTotalCount(response.totalCount || 0);
|
|
630
|
+
setIsLoading(false);
|
|
631
|
+
return { success: true };
|
|
632
|
+
} catch (err) {
|
|
633
|
+
const errorMessage = err instanceof Error ? err.message : "Failed to fetch claim types";
|
|
634
|
+
setError(errorMessage);
|
|
635
|
+
setIsLoading(false);
|
|
636
|
+
return { success: false, error: errorMessage };
|
|
637
|
+
}
|
|
638
|
+
}, [service]);
|
|
639
|
+
const fetchClaimTypeNames = (0, import_react4.useCallback)(async () => {
|
|
640
|
+
setIsLoading(true);
|
|
641
|
+
setError(null);
|
|
642
|
+
try {
|
|
643
|
+
const response = await service.getClaimTypeNames();
|
|
644
|
+
setClaimTypeNames(response || []);
|
|
645
|
+
setIsLoading(false);
|
|
646
|
+
return { success: true };
|
|
647
|
+
} catch (err) {
|
|
648
|
+
const errorMessage = err instanceof Error ? err.message : "Failed to fetch claim type names";
|
|
649
|
+
setError(errorMessage);
|
|
650
|
+
setIsLoading(false);
|
|
651
|
+
return { success: false, error: errorMessage };
|
|
652
|
+
}
|
|
653
|
+
}, [service]);
|
|
654
|
+
const getClaimTypeById = (0, import_react4.useCallback)(
|
|
655
|
+
async (id) => {
|
|
656
|
+
setIsLoading(true);
|
|
657
|
+
setError(null);
|
|
658
|
+
try {
|
|
659
|
+
const claimType = await service.getClaimTypeById(id);
|
|
660
|
+
setSelectedClaimType(claimType);
|
|
661
|
+
setIsLoading(false);
|
|
662
|
+
return { success: true };
|
|
663
|
+
} catch (err) {
|
|
664
|
+
const errorMessage = err instanceof Error ? err.message : "Failed to fetch claim type";
|
|
665
|
+
setError(errorMessage);
|
|
666
|
+
setIsLoading(false);
|
|
667
|
+
return { success: false, error: errorMessage };
|
|
668
|
+
}
|
|
669
|
+
},
|
|
670
|
+
[service]
|
|
671
|
+
);
|
|
672
|
+
const createClaimType = (0, import_react4.useCallback)(
|
|
673
|
+
async (claimType) => {
|
|
674
|
+
setIsLoading(true);
|
|
675
|
+
setError(null);
|
|
676
|
+
try {
|
|
677
|
+
await service.createClaimType(claimType);
|
|
678
|
+
await fetchClaimTypes();
|
|
679
|
+
return { success: true };
|
|
680
|
+
} catch (err) {
|
|
681
|
+
const errorMessage = err instanceof Error ? err.message : "Failed to create claim type";
|
|
682
|
+
setError(errorMessage);
|
|
683
|
+
setIsLoading(false);
|
|
684
|
+
return { success: false, error: errorMessage };
|
|
685
|
+
}
|
|
686
|
+
},
|
|
687
|
+
[service, fetchClaimTypes]
|
|
688
|
+
);
|
|
689
|
+
const updateClaimType = (0, import_react4.useCallback)(
|
|
690
|
+
async (claimType) => {
|
|
691
|
+
setIsLoading(true);
|
|
692
|
+
setError(null);
|
|
693
|
+
try {
|
|
694
|
+
await service.updateClaimType(claimType);
|
|
695
|
+
await fetchClaimTypes();
|
|
696
|
+
return { success: true };
|
|
697
|
+
} catch (err) {
|
|
698
|
+
const errorMessage = err instanceof Error ? err.message : "Failed to update claim type";
|
|
699
|
+
setError(errorMessage);
|
|
700
|
+
setIsLoading(false);
|
|
701
|
+
return { success: false, error: errorMessage };
|
|
702
|
+
}
|
|
703
|
+
},
|
|
704
|
+
[service, fetchClaimTypes]
|
|
705
|
+
);
|
|
706
|
+
const deleteClaimType = (0, import_react4.useCallback)(
|
|
707
|
+
async (id) => {
|
|
708
|
+
setIsLoading(true);
|
|
709
|
+
setError(null);
|
|
710
|
+
try {
|
|
711
|
+
await service.deleteClaimType(id);
|
|
712
|
+
await fetchClaimTypes();
|
|
713
|
+
return { success: true };
|
|
714
|
+
} catch (err) {
|
|
715
|
+
const errorMessage = err instanceof Error ? err.message : "Failed to delete claim type";
|
|
716
|
+
setError(errorMessage);
|
|
717
|
+
setIsLoading(false);
|
|
718
|
+
return { success: false, error: errorMessage };
|
|
719
|
+
}
|
|
720
|
+
},
|
|
721
|
+
[service, fetchClaimTypes]
|
|
722
|
+
);
|
|
723
|
+
const getClaims = (0, import_react4.useCallback)(
|
|
724
|
+
async (id, type) => {
|
|
725
|
+
try {
|
|
726
|
+
return await service.getClaims({ id, type });
|
|
727
|
+
} catch (err) {
|
|
728
|
+
const errorMessage = err instanceof Error ? err.message : "Failed to fetch claims";
|
|
729
|
+
setError(errorMessage);
|
|
730
|
+
return [];
|
|
731
|
+
}
|
|
732
|
+
},
|
|
733
|
+
[service]
|
|
734
|
+
);
|
|
735
|
+
const updateClaims = (0, import_react4.useCallback)(
|
|
736
|
+
async (id, type, claims) => {
|
|
737
|
+
setIsLoading(true);
|
|
738
|
+
setError(null);
|
|
739
|
+
try {
|
|
740
|
+
await service.updateClaims({ id, type, claims });
|
|
741
|
+
setIsLoading(false);
|
|
742
|
+
return { success: true };
|
|
743
|
+
} catch (err) {
|
|
744
|
+
const errorMessage = err instanceof Error ? err.message : "Failed to update claims";
|
|
745
|
+
setError(errorMessage);
|
|
746
|
+
setIsLoading(false);
|
|
747
|
+
return { success: false, error: errorMessage };
|
|
748
|
+
}
|
|
749
|
+
},
|
|
750
|
+
[service]
|
|
751
|
+
);
|
|
752
|
+
const reset = (0, import_react4.useCallback)(() => {
|
|
753
|
+
setClaimTypes([]);
|
|
754
|
+
setTotalCount(0);
|
|
755
|
+
setClaimTypeNames([]);
|
|
756
|
+
setSelectedClaimType(null);
|
|
757
|
+
setIsLoading(false);
|
|
758
|
+
setError(null);
|
|
759
|
+
}, []);
|
|
760
|
+
return {
|
|
761
|
+
claimTypes,
|
|
762
|
+
totalCount,
|
|
763
|
+
claimTypeNames,
|
|
764
|
+
selectedClaimType,
|
|
765
|
+
isLoading,
|
|
766
|
+
error,
|
|
767
|
+
sortKey,
|
|
768
|
+
sortOrder,
|
|
769
|
+
fetchClaimTypes,
|
|
770
|
+
fetchClaimTypeNames,
|
|
771
|
+
getClaimTypeById,
|
|
772
|
+
createClaimType,
|
|
773
|
+
updateClaimType,
|
|
774
|
+
deleteClaimType,
|
|
775
|
+
setSelectedClaimType,
|
|
776
|
+
setSortKey,
|
|
777
|
+
setSortOrder,
|
|
778
|
+
reset,
|
|
779
|
+
getClaims,
|
|
780
|
+
updateClaims
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
// src/components/Roles/RolesComponent.tsx
|
|
785
|
+
var import_react5 = require("react");
|
|
786
|
+
var import_core4 = require("@abpjs/core");
|
|
787
|
+
var import_theme_shared = require("@abpjs/theme-shared");
|
|
788
|
+
var import_permission_management = require("@abpjs/permission-management");
|
|
789
|
+
var import_react6 = require("@chakra-ui/react");
|
|
790
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
791
|
+
var DEFAULT_FORM_STATE = {
|
|
792
|
+
name: "",
|
|
793
|
+
isDefault: false,
|
|
794
|
+
isPublic: false
|
|
795
|
+
};
|
|
796
|
+
function RolesComponent({
|
|
797
|
+
onRoleCreated,
|
|
798
|
+
onRoleUpdated,
|
|
799
|
+
onRoleDeleted
|
|
800
|
+
}) {
|
|
801
|
+
const { t } = (0, import_core4.useLocalization)();
|
|
802
|
+
const confirmation = (0, import_theme_shared.useConfirmation)();
|
|
803
|
+
const {
|
|
804
|
+
roles,
|
|
805
|
+
selectedRole,
|
|
806
|
+
isLoading,
|
|
807
|
+
error,
|
|
808
|
+
fetchRoles,
|
|
809
|
+
getRoleById,
|
|
810
|
+
createRole,
|
|
811
|
+
updateRole,
|
|
812
|
+
deleteRole,
|
|
813
|
+
setSelectedRole
|
|
814
|
+
} = useRoles();
|
|
815
|
+
const [isModalOpen, setIsModalOpen] = (0, import_react5.useState)(false);
|
|
816
|
+
const [formState, setFormState] = (0, import_react5.useState)(DEFAULT_FORM_STATE);
|
|
817
|
+
const [isSubmitting, setIsSubmitting] = (0, import_react5.useState)(false);
|
|
818
|
+
const [isPermissionModalOpen, setIsPermissionModalOpen] = (0, import_react5.useState)(false);
|
|
819
|
+
const [permissionProviderKey, setPermissionProviderKey] = (0, import_react5.useState)("");
|
|
820
|
+
const [searchTerm, setSearchTerm] = (0, import_react5.useState)("");
|
|
821
|
+
(0, import_react5.useEffect)(() => {
|
|
822
|
+
fetchRoles();
|
|
823
|
+
}, [fetchRoles]);
|
|
824
|
+
const filteredRoles = roles.filter(
|
|
825
|
+
(role) => !searchTerm || role.name.toLowerCase().includes(searchTerm.toLowerCase())
|
|
826
|
+
);
|
|
827
|
+
const handleAdd = (0, import_react5.useCallback)(() => {
|
|
828
|
+
setSelectedRole(null);
|
|
829
|
+
setFormState(DEFAULT_FORM_STATE);
|
|
830
|
+
setIsModalOpen(true);
|
|
831
|
+
}, [setSelectedRole]);
|
|
832
|
+
const handleEdit = (0, import_react5.useCallback)(
|
|
833
|
+
async (id) => {
|
|
834
|
+
const result = await getRoleById(id);
|
|
835
|
+
if (result.success && selectedRole) {
|
|
836
|
+
setFormState({
|
|
837
|
+
name: selectedRole.name || "",
|
|
838
|
+
isDefault: selectedRole.isDefault || false,
|
|
839
|
+
isPublic: selectedRole.isPublic || false
|
|
840
|
+
});
|
|
841
|
+
setIsModalOpen(true);
|
|
842
|
+
}
|
|
843
|
+
},
|
|
844
|
+
[getRoleById, selectedRole]
|
|
845
|
+
);
|
|
846
|
+
(0, import_react5.useEffect)(() => {
|
|
847
|
+
if (selectedRole) {
|
|
848
|
+
setFormState({
|
|
849
|
+
name: selectedRole.name || "",
|
|
850
|
+
isDefault: selectedRole.isDefault || false,
|
|
851
|
+
isPublic: selectedRole.isPublic || false
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
}, [selectedRole]);
|
|
855
|
+
const handleDelete = (0, import_react5.useCallback)(
|
|
856
|
+
async (id, name) => {
|
|
857
|
+
const status = await confirmation.warn(
|
|
858
|
+
t("AbpIdentity::RoleDeletionConfirmationMessage", name),
|
|
859
|
+
t("AbpIdentity::AreYouSure")
|
|
860
|
+
);
|
|
861
|
+
if (status === import_theme_shared.Toaster.Status.confirm) {
|
|
862
|
+
const result = await deleteRole(id);
|
|
863
|
+
if (result.success) {
|
|
864
|
+
onRoleDeleted?.(id);
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
},
|
|
868
|
+
[confirmation, t, deleteRole, onRoleDeleted]
|
|
869
|
+
);
|
|
870
|
+
const handleOpenPermissions = (0, import_react5.useCallback)((roleName) => {
|
|
871
|
+
setPermissionProviderKey(roleName);
|
|
872
|
+
setIsPermissionModalOpen(true);
|
|
873
|
+
}, []);
|
|
874
|
+
const handleSubmit = (0, import_react5.useCallback)(async () => {
|
|
875
|
+
if (!formState.name.trim()) return;
|
|
876
|
+
setIsSubmitting(true);
|
|
877
|
+
const roleData = {
|
|
878
|
+
name: formState.name.trim(),
|
|
879
|
+
isDefault: formState.isDefault,
|
|
880
|
+
isPublic: formState.isPublic
|
|
881
|
+
};
|
|
882
|
+
let result;
|
|
883
|
+
if (selectedRole?.id) {
|
|
884
|
+
result = await updateRole(selectedRole.id, roleData);
|
|
885
|
+
if (result.success) {
|
|
886
|
+
onRoleUpdated?.({ ...selectedRole, ...roleData });
|
|
887
|
+
}
|
|
888
|
+
} else {
|
|
889
|
+
result = await createRole(roleData);
|
|
890
|
+
if (result.success) {
|
|
891
|
+
onRoleCreated?.({ ...roleData, id: "", isStatic: false, concurrencyStamp: "" });
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
setIsSubmitting(false);
|
|
895
|
+
if (result.success) {
|
|
896
|
+
setIsModalOpen(false);
|
|
897
|
+
setFormState(DEFAULT_FORM_STATE);
|
|
898
|
+
setSelectedRole(null);
|
|
899
|
+
}
|
|
900
|
+
}, [formState, selectedRole, updateRole, createRole, onRoleCreated, onRoleUpdated, setSelectedRole]);
|
|
901
|
+
const handleModalClose = (0, import_react5.useCallback)(() => {
|
|
902
|
+
setIsModalOpen(false);
|
|
903
|
+
setFormState(DEFAULT_FORM_STATE);
|
|
904
|
+
setSelectedRole(null);
|
|
905
|
+
}, [setSelectedRole]);
|
|
906
|
+
const handleInputChange = (0, import_react5.useCallback)(
|
|
907
|
+
(field, value) => {
|
|
908
|
+
setFormState((prev) => ({ ...prev, [field]: value }));
|
|
909
|
+
},
|
|
910
|
+
[]
|
|
911
|
+
);
|
|
912
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react6.Box, { id: "identity-roles-wrapper", className: "card", p: 4, children: [
|
|
913
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react6.Flex, { justify: "space-between", align: "center", mb: 4, children: [
|
|
914
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react6.Text, { fontSize: "xl", fontWeight: "bold", children: t("AbpIdentity::Roles") }),
|
|
915
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_theme_shared.Button, { colorPalette: "blue", onClick: handleAdd, children: t("AbpIdentity::NewRole") })
|
|
916
|
+
] }),
|
|
917
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react6.Box, { mb: 4, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
918
|
+
import_react6.Input,
|
|
919
|
+
{
|
|
920
|
+
placeholder: t("AbpIdentity::Search"),
|
|
921
|
+
value: searchTerm,
|
|
922
|
+
onChange: (e) => setSearchTerm(e.target.value),
|
|
923
|
+
maxW: "300px"
|
|
924
|
+
}
|
|
925
|
+
) }),
|
|
926
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_theme_shared.Alert, { status: "error", mb: 4, children: error }),
|
|
927
|
+
isLoading && roles.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react6.Flex, { justify: "center", py: 8, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react6.Spinner, { size: "lg" }) }),
|
|
928
|
+
roles.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react6.Table.Root, { variant: "outline", children: [
|
|
929
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react6.Table.Header, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react6.Table.Row, { children: [
|
|
930
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react6.Table.ColumnHeader, { children: t("AbpIdentity::Actions") }),
|
|
931
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react6.Table.ColumnHeader, { children: t("AbpIdentity::RoleName") })
|
|
932
|
+
] }) }),
|
|
933
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react6.Table.Body, { children: filteredRoles.map((role) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react6.Table.Row, { children: [
|
|
934
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react6.Table.Cell, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react6.Menu.Root, { children: [
|
|
935
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react6.Menu.Trigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_theme_shared.Button, { size: "sm", colorPalette: "blue", children: t("AbpIdentity::Actions") }) }),
|
|
936
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react6.Menu.Positioner, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react6.Menu.Content, { children: [
|
|
937
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react6.Menu.Item, { value: "edit", onClick: () => handleEdit(role.id), children: t("AbpIdentity::Edit") }),
|
|
938
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react6.Menu.Item, { value: "permissions", onClick: () => handleOpenPermissions(role.name), children: t("AbpIdentity::Permissions") }),
|
|
939
|
+
!role.isStatic && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
940
|
+
import_react6.Menu.Item,
|
|
941
|
+
{
|
|
942
|
+
value: "delete",
|
|
943
|
+
color: "red.500",
|
|
944
|
+
onClick: () => handleDelete(role.id, role.name),
|
|
945
|
+
children: t("AbpIdentity::Delete")
|
|
946
|
+
}
|
|
947
|
+
)
|
|
948
|
+
] }) })
|
|
949
|
+
] }) }),
|
|
950
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react6.Table.Cell, { children: role.name })
|
|
951
|
+
] }, role.id)) })
|
|
952
|
+
] }),
|
|
953
|
+
!isLoading && roles.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react6.Text, { textAlign: "center", color: "gray.500", py: 8, children: t("AbpIdentity::NoRolesFound") }),
|
|
954
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
955
|
+
import_theme_shared.Modal,
|
|
956
|
+
{
|
|
957
|
+
visible: isModalOpen,
|
|
958
|
+
onVisibleChange: setIsModalOpen,
|
|
959
|
+
header: selectedRole?.id ? t("AbpIdentity::Edit") : t("AbpIdentity::NewRole"),
|
|
960
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
961
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_theme_shared.Button, { variant: "outline", onClick: handleModalClose, disabled: isSubmitting, children: t("AbpIdentity::Cancel") }),
|
|
962
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
963
|
+
import_theme_shared.Button,
|
|
964
|
+
{
|
|
965
|
+
colorPalette: "blue",
|
|
966
|
+
onClick: handleSubmit,
|
|
967
|
+
loading: isSubmitting,
|
|
968
|
+
disabled: !formState.name.trim(),
|
|
969
|
+
children: t("AbpIdentity::Save")
|
|
970
|
+
}
|
|
971
|
+
)
|
|
972
|
+
] }),
|
|
973
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react6.VStack, { gap: 4, align: "stretch", children: [
|
|
974
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_theme_shared.FormField, { label: t("AbpIdentity::RoleName"), required: true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
975
|
+
import_react6.Input,
|
|
976
|
+
{
|
|
977
|
+
value: formState.name,
|
|
978
|
+
onChange: (e) => handleInputChange("name", e.target.value),
|
|
979
|
+
maxLength: 256,
|
|
980
|
+
placeholder: t("AbpIdentity::RoleName")
|
|
981
|
+
}
|
|
982
|
+
) }),
|
|
983
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
984
|
+
import_theme_shared.Checkbox,
|
|
985
|
+
{
|
|
986
|
+
checked: formState.isDefault,
|
|
987
|
+
onChange: (e) => handleInputChange("isDefault", e.target.checked),
|
|
988
|
+
children: t("AbpIdentity::DisplayName:IsDefault")
|
|
989
|
+
}
|
|
990
|
+
),
|
|
991
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
992
|
+
import_theme_shared.Checkbox,
|
|
993
|
+
{
|
|
994
|
+
checked: formState.isPublic,
|
|
995
|
+
onChange: (e) => handleInputChange("isPublic", e.target.checked),
|
|
996
|
+
children: t("AbpIdentity::DisplayName:IsPublic")
|
|
997
|
+
}
|
|
998
|
+
)
|
|
999
|
+
] })
|
|
1000
|
+
}
|
|
1001
|
+
),
|
|
1002
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1003
|
+
import_permission_management.PermissionManagementModal,
|
|
1004
|
+
{
|
|
1005
|
+
visible: isPermissionModalOpen,
|
|
1006
|
+
onVisibleChange: setIsPermissionModalOpen,
|
|
1007
|
+
providerName: "R",
|
|
1008
|
+
providerKey: permissionProviderKey
|
|
1009
|
+
}
|
|
1010
|
+
)
|
|
1011
|
+
] });
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
// src/components/Users/UsersComponent.tsx
|
|
1015
|
+
var import_react7 = require("react");
|
|
1016
|
+
var import_core5 = require("@abpjs/core");
|
|
1017
|
+
var import_theme_shared2 = require("@abpjs/theme-shared");
|
|
1018
|
+
var import_permission_management2 = require("@abpjs/permission-management");
|
|
1019
|
+
var import_react8 = require("@chakra-ui/react");
|
|
1020
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
1021
|
+
var DEFAULT_FORM_STATE2 = {
|
|
1022
|
+
userName: "",
|
|
1023
|
+
name: "",
|
|
1024
|
+
surname: "",
|
|
1025
|
+
email: "",
|
|
1026
|
+
phoneNumber: "",
|
|
1027
|
+
password: "",
|
|
1028
|
+
lockoutEnabled: true,
|
|
1029
|
+
twoFactorEnabled: true,
|
|
1030
|
+
roleNames: []
|
|
1031
|
+
};
|
|
1032
|
+
function UsersComponent({
|
|
1033
|
+
onUserCreated,
|
|
1034
|
+
onUserUpdated,
|
|
1035
|
+
onUserDeleted
|
|
1036
|
+
}) {
|
|
1037
|
+
const { t } = (0, import_core5.useLocalization)();
|
|
1038
|
+
const confirmation = (0, import_theme_shared2.useConfirmation)();
|
|
1039
|
+
const {
|
|
1040
|
+
users,
|
|
1041
|
+
totalCount,
|
|
1042
|
+
selectedUser,
|
|
1043
|
+
selectedUserRoles,
|
|
1044
|
+
isLoading,
|
|
1045
|
+
error,
|
|
1046
|
+
pageQuery,
|
|
1047
|
+
fetchUsers,
|
|
1048
|
+
getUserById,
|
|
1049
|
+
getUserRoles,
|
|
1050
|
+
createUser,
|
|
1051
|
+
updateUser,
|
|
1052
|
+
deleteUser,
|
|
1053
|
+
setSelectedUser,
|
|
1054
|
+
setPageQuery
|
|
1055
|
+
} = useUsers();
|
|
1056
|
+
const { roles, fetchRoles } = useRoles();
|
|
1057
|
+
const [isModalOpen, setIsModalOpen] = (0, import_react7.useState)(false);
|
|
1058
|
+
const [formState, setFormState] = (0, import_react7.useState)(DEFAULT_FORM_STATE2);
|
|
1059
|
+
const [isSubmitting, setIsSubmitting] = (0, import_react7.useState)(false);
|
|
1060
|
+
const [isPermissionModalOpen, setIsPermissionModalOpen] = (0, import_react7.useState)(false);
|
|
1061
|
+
const [permissionProviderKey, setPermissionProviderKey] = (0, import_react7.useState)("");
|
|
1062
|
+
const [searchTerm, setSearchTerm] = (0, import_react7.useState)("");
|
|
1063
|
+
const [debouncedSearchTerm, setDebouncedSearchTerm] = (0, import_react7.useState)("");
|
|
1064
|
+
(0, import_react7.useEffect)(() => {
|
|
1065
|
+
fetchRoles();
|
|
1066
|
+
fetchUsers();
|
|
1067
|
+
}, [fetchRoles, fetchUsers]);
|
|
1068
|
+
(0, import_react7.useEffect)(() => {
|
|
1069
|
+
const timer = setTimeout(() => {
|
|
1070
|
+
setDebouncedSearchTerm(searchTerm);
|
|
1071
|
+
}, 300);
|
|
1072
|
+
return () => clearTimeout(timer);
|
|
1073
|
+
}, [searchTerm]);
|
|
1074
|
+
(0, import_react7.useEffect)(() => {
|
|
1075
|
+
const newQuery = {
|
|
1076
|
+
...pageQuery,
|
|
1077
|
+
filter: debouncedSearchTerm || void 0,
|
|
1078
|
+
skipCount: 0
|
|
1079
|
+
};
|
|
1080
|
+
setPageQuery(newQuery);
|
|
1081
|
+
fetchUsers(newQuery);
|
|
1082
|
+
}, [debouncedSearchTerm]);
|
|
1083
|
+
const selectedRoleNames = (0, import_react7.useMemo)(() => {
|
|
1084
|
+
return selectedUserRoles.map((role) => role.name);
|
|
1085
|
+
}, [selectedUserRoles]);
|
|
1086
|
+
const handleAdd = (0, import_react7.useCallback)(() => {
|
|
1087
|
+
setSelectedUser(null);
|
|
1088
|
+
setFormState(DEFAULT_FORM_STATE2);
|
|
1089
|
+
setIsModalOpen(true);
|
|
1090
|
+
}, [setSelectedUser]);
|
|
1091
|
+
const handleEdit = (0, import_react7.useCallback)(
|
|
1092
|
+
async (id) => {
|
|
1093
|
+
await Promise.all([getUserById(id), getUserRoles(id)]);
|
|
1094
|
+
setIsModalOpen(true);
|
|
1095
|
+
},
|
|
1096
|
+
[getUserById, getUserRoles]
|
|
1097
|
+
);
|
|
1098
|
+
(0, import_react7.useEffect)(() => {
|
|
1099
|
+
if (selectedUser) {
|
|
1100
|
+
setFormState({
|
|
1101
|
+
userName: selectedUser.userName || "",
|
|
1102
|
+
name: selectedUser.name || "",
|
|
1103
|
+
surname: selectedUser.surname || "",
|
|
1104
|
+
email: selectedUser.email || "",
|
|
1105
|
+
phoneNumber: selectedUser.phoneNumber || "",
|
|
1106
|
+
password: "",
|
|
1107
|
+
lockoutEnabled: selectedUser.lockoutEnabled ?? true,
|
|
1108
|
+
twoFactorEnabled: selectedUser.twoFactorEnabled ?? true,
|
|
1109
|
+
roleNames: selectedRoleNames
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
}, [selectedUser, selectedRoleNames]);
|
|
1113
|
+
const handleDelete = (0, import_react7.useCallback)(
|
|
1114
|
+
async (id, userName) => {
|
|
1115
|
+
const status = await confirmation.warn(
|
|
1116
|
+
t("AbpIdentity::UserDeletionConfirmationMessage", userName),
|
|
1117
|
+
t("AbpIdentity::AreYouSure")
|
|
1118
|
+
);
|
|
1119
|
+
if (status === import_theme_shared2.Toaster.Status.confirm) {
|
|
1120
|
+
const result = await deleteUser(id);
|
|
1121
|
+
if (result.success) {
|
|
1122
|
+
onUserDeleted?.(id);
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
},
|
|
1126
|
+
[confirmation, t, deleteUser, onUserDeleted]
|
|
1127
|
+
);
|
|
1128
|
+
const handleOpenPermissions = (0, import_react7.useCallback)((userId) => {
|
|
1129
|
+
setPermissionProviderKey(userId);
|
|
1130
|
+
setIsPermissionModalOpen(true);
|
|
1131
|
+
}, []);
|
|
1132
|
+
const handleSubmit = (0, import_react7.useCallback)(async () => {
|
|
1133
|
+
if (!formState.userName.trim() || !formState.email.trim()) return;
|
|
1134
|
+
if (!selectedUser?.id && !formState.password) return;
|
|
1135
|
+
setIsSubmitting(true);
|
|
1136
|
+
const userData = {
|
|
1137
|
+
userName: formState.userName.trim(),
|
|
1138
|
+
name: formState.name.trim(),
|
|
1139
|
+
surname: formState.surname.trim(),
|
|
1140
|
+
email: formState.email.trim(),
|
|
1141
|
+
phoneNumber: formState.phoneNumber.trim(),
|
|
1142
|
+
password: formState.password,
|
|
1143
|
+
lockoutEnabled: formState.lockoutEnabled,
|
|
1144
|
+
twoFactorEnabled: formState.twoFactorEnabled,
|
|
1145
|
+
roleNames: formState.roleNames
|
|
1146
|
+
};
|
|
1147
|
+
let result;
|
|
1148
|
+
if (selectedUser?.id) {
|
|
1149
|
+
result = await updateUser(selectedUser.id, userData);
|
|
1150
|
+
if (result.success) {
|
|
1151
|
+
onUserUpdated?.({
|
|
1152
|
+
...selectedUser,
|
|
1153
|
+
...userData
|
|
1154
|
+
});
|
|
1155
|
+
}
|
|
1156
|
+
} else {
|
|
1157
|
+
result = await createUser(userData);
|
|
1158
|
+
if (result.success) {
|
|
1159
|
+
onUserCreated?.({
|
|
1160
|
+
...userData,
|
|
1161
|
+
id: "",
|
|
1162
|
+
tenantId: "",
|
|
1163
|
+
emailConfirmed: false,
|
|
1164
|
+
phoneNumberConfirmed: false,
|
|
1165
|
+
isLockedOut: false,
|
|
1166
|
+
concurrencyStamp: ""
|
|
1167
|
+
});
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
setIsSubmitting(false);
|
|
1171
|
+
if (result.success) {
|
|
1172
|
+
setIsModalOpen(false);
|
|
1173
|
+
setFormState(DEFAULT_FORM_STATE2);
|
|
1174
|
+
setSelectedUser(null);
|
|
1175
|
+
}
|
|
1176
|
+
}, [formState, selectedUser, updateUser, createUser, onUserCreated, onUserUpdated, setSelectedUser]);
|
|
1177
|
+
const handleModalClose = (0, import_react7.useCallback)(() => {
|
|
1178
|
+
setIsModalOpen(false);
|
|
1179
|
+
setFormState(DEFAULT_FORM_STATE2);
|
|
1180
|
+
setSelectedUser(null);
|
|
1181
|
+
}, [setSelectedUser]);
|
|
1182
|
+
const handleInputChange = (0, import_react7.useCallback)(
|
|
1183
|
+
(field, value) => {
|
|
1184
|
+
setFormState((prev) => ({ ...prev, [field]: value }));
|
|
1185
|
+
},
|
|
1186
|
+
[]
|
|
1187
|
+
);
|
|
1188
|
+
const handleRoleChange = (0, import_react7.useCallback)((roleName, checked) => {
|
|
1189
|
+
setFormState((prev) => ({
|
|
1190
|
+
...prev,
|
|
1191
|
+
roleNames: checked ? [...prev.roleNames, roleName] : prev.roleNames.filter((name) => name !== roleName)
|
|
1192
|
+
}));
|
|
1193
|
+
}, []);
|
|
1194
|
+
const handlePageChange = (0, import_react7.useCallback)(
|
|
1195
|
+
(newSkipCount) => {
|
|
1196
|
+
const newQuery = { ...pageQuery, skipCount: newSkipCount };
|
|
1197
|
+
setPageQuery(newQuery);
|
|
1198
|
+
fetchUsers(newQuery);
|
|
1199
|
+
},
|
|
1200
|
+
[pageQuery, setPageQuery, fetchUsers]
|
|
1201
|
+
);
|
|
1202
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react8.Box, { id: "identity-users-wrapper", className: "card", p: 4, children: [
|
|
1203
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react8.Flex, { justify: "space-between", align: "center", mb: 4, children: [
|
|
1204
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react8.Text, { fontSize: "xl", fontWeight: "bold", children: t("AbpIdentity::Users") }),
|
|
1205
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_theme_shared2.Button, { colorPalette: "blue", onClick: handleAdd, children: t("AbpIdentity::NewUser") })
|
|
1206
|
+
] }),
|
|
1207
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react8.Box, { mb: 4, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1208
|
+
import_react8.Input,
|
|
1209
|
+
{
|
|
1210
|
+
placeholder: t("AbpIdentity::Search"),
|
|
1211
|
+
value: searchTerm,
|
|
1212
|
+
onChange: (e) => setSearchTerm(e.target.value),
|
|
1213
|
+
maxW: "300px"
|
|
1214
|
+
}
|
|
1215
|
+
) }),
|
|
1216
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_theme_shared2.Alert, { status: "error", mb: 4, children: error }),
|
|
1217
|
+
isLoading && users.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react8.Flex, { justify: "center", py: 8, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react8.Spinner, { size: "lg" }) }),
|
|
1218
|
+
users.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1219
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react8.Table.Root, { variant: "outline", children: [
|
|
1220
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react8.Table.Header, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react8.Table.Row, { children: [
|
|
1221
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react8.Table.ColumnHeader, { children: t("AbpIdentity::Actions") }),
|
|
1222
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react8.Table.ColumnHeader, { children: t("AbpIdentity::UserName") }),
|
|
1223
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react8.Table.ColumnHeader, { children: t("AbpIdentity::EmailAddress") }),
|
|
1224
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react8.Table.ColumnHeader, { children: t("AbpIdentity::PhoneNumber") })
|
|
1225
|
+
] }) }),
|
|
1226
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react8.Table.Body, { children: users.map((user) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react8.Table.Row, { children: [
|
|
1227
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react8.Table.Cell, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react8.Menu.Root, { children: [
|
|
1228
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react8.Menu.Trigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_theme_shared2.Button, { size: "sm", colorPalette: "blue", children: t("AbpIdentity::Actions") }) }),
|
|
1229
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react8.Menu.Positioner, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react8.Menu.Content, { children: [
|
|
1230
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react8.Menu.Item, { value: "edit", onClick: () => handleEdit(user.id), children: t("AbpIdentity::Edit") }),
|
|
1231
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react8.Menu.Item, { value: "permissions", onClick: () => handleOpenPermissions(user.id), children: t("AbpIdentity::Permissions") }),
|
|
1232
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1233
|
+
import_react8.Menu.Item,
|
|
1234
|
+
{
|
|
1235
|
+
value: "delete",
|
|
1236
|
+
color: "red.500",
|
|
1237
|
+
onClick: () => handleDelete(user.id, user.userName),
|
|
1238
|
+
children: t("AbpIdentity::Delete")
|
|
1239
|
+
}
|
|
1240
|
+
)
|
|
1241
|
+
] }) })
|
|
1242
|
+
] }) }),
|
|
1243
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react8.Table.Cell, { children: user.userName }),
|
|
1244
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react8.Table.Cell, { children: user.email }),
|
|
1245
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react8.Table.Cell, { children: user.phoneNumber })
|
|
1246
|
+
] }, user.id)) })
|
|
1247
|
+
] }),
|
|
1248
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react8.Flex, { justify: "space-between", align: "center", mt: 4, children: [
|
|
1249
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react8.Text, { color: "gray.600", children: [
|
|
1250
|
+
t("AbpIdentity::TotalCount"),
|
|
1251
|
+
": ",
|
|
1252
|
+
totalCount
|
|
1253
|
+
] }),
|
|
1254
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react8.Flex, { gap: 2, children: [
|
|
1255
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1256
|
+
import_theme_shared2.Button,
|
|
1257
|
+
{
|
|
1258
|
+
size: "sm",
|
|
1259
|
+
disabled: (pageQuery.skipCount || 0) === 0,
|
|
1260
|
+
onClick: () => handlePageChange(
|
|
1261
|
+
Math.max(0, (pageQuery.skipCount || 0) - (pageQuery.maxResultCount || 10))
|
|
1262
|
+
),
|
|
1263
|
+
children: t("AbpIdentity::Previous")
|
|
1264
|
+
}
|
|
1265
|
+
),
|
|
1266
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1267
|
+
import_theme_shared2.Button,
|
|
1268
|
+
{
|
|
1269
|
+
size: "sm",
|
|
1270
|
+
disabled: (pageQuery.skipCount || 0) + (pageQuery.maxResultCount || 10) >= totalCount,
|
|
1271
|
+
onClick: () => handlePageChange((pageQuery.skipCount || 0) + (pageQuery.maxResultCount || 10)),
|
|
1272
|
+
children: t("AbpIdentity::Next")
|
|
1273
|
+
}
|
|
1274
|
+
)
|
|
1275
|
+
] })
|
|
1276
|
+
] })
|
|
1277
|
+
] }),
|
|
1278
|
+
!isLoading && users.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react8.Text, { textAlign: "center", color: "gray.500", py: 8, children: t("AbpIdentity::NoUsersFound") }),
|
|
1279
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1280
|
+
import_theme_shared2.Modal,
|
|
1281
|
+
{
|
|
1282
|
+
visible: isModalOpen,
|
|
1283
|
+
onVisibleChange: setIsModalOpen,
|
|
1284
|
+
size: "lg",
|
|
1285
|
+
header: selectedUser?.id ? t("AbpIdentity::Edit") : t("AbpIdentity::NewUser"),
|
|
1286
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1287
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_theme_shared2.Button, { variant: "outline", onClick: handleModalClose, disabled: isSubmitting, children: t("AbpIdentity::Cancel") }),
|
|
1288
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1289
|
+
import_theme_shared2.Button,
|
|
1290
|
+
{
|
|
1291
|
+
colorPalette: "blue",
|
|
1292
|
+
onClick: handleSubmit,
|
|
1293
|
+
loading: isSubmitting,
|
|
1294
|
+
disabled: !formState.userName.trim() || !formState.email.trim() || !selectedUser?.id && !formState.password,
|
|
1295
|
+
children: t("AbpIdentity::Save")
|
|
1296
|
+
}
|
|
1297
|
+
)
|
|
1298
|
+
] }),
|
|
1299
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react8.Tabs.Root, { defaultValue: "info", children: [
|
|
1300
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react8.Tabs.List, { children: [
|
|
1301
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react8.Tabs.Trigger, { value: "info", children: t("AbpIdentity::UserInformations") }),
|
|
1302
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react8.Tabs.Trigger, { value: "roles", children: t("AbpIdentity::Roles") })
|
|
1303
|
+
] }),
|
|
1304
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react8.Tabs.Content, { value: "info", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react8.VStack, { gap: 4, align: "stretch", pt: 4, children: [
|
|
1305
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_theme_shared2.FormField, { label: t("AbpIdentity::UserName"), required: true, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1306
|
+
import_react8.Input,
|
|
1307
|
+
{
|
|
1308
|
+
value: formState.userName,
|
|
1309
|
+
onChange: (e) => handleInputChange("userName", e.target.value),
|
|
1310
|
+
maxLength: 256
|
|
1311
|
+
}
|
|
1312
|
+
) }),
|
|
1313
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react8.SimpleGrid, { columns: 2, gap: 4, children: [
|
|
1314
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_theme_shared2.FormField, { label: t("AbpIdentity::Name"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1315
|
+
import_react8.Input,
|
|
1316
|
+
{
|
|
1317
|
+
value: formState.name,
|
|
1318
|
+
onChange: (e) => handleInputChange("name", e.target.value),
|
|
1319
|
+
maxLength: 64
|
|
1320
|
+
}
|
|
1321
|
+
) }),
|
|
1322
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_theme_shared2.FormField, { label: t("AbpIdentity::DisplayName:Surname"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1323
|
+
import_react8.Input,
|
|
1324
|
+
{
|
|
1325
|
+
value: formState.surname,
|
|
1326
|
+
onChange: (e) => handleInputChange("surname", e.target.value),
|
|
1327
|
+
maxLength: 64
|
|
1328
|
+
}
|
|
1329
|
+
) })
|
|
1330
|
+
] }),
|
|
1331
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_theme_shared2.FormField, { label: t("AbpIdentity::Password"), required: !selectedUser?.id, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1332
|
+
import_react8.Input,
|
|
1333
|
+
{
|
|
1334
|
+
type: "password",
|
|
1335
|
+
value: formState.password,
|
|
1336
|
+
onChange: (e) => handleInputChange("password", e.target.value),
|
|
1337
|
+
autoComplete: "new-password",
|
|
1338
|
+
maxLength: 32,
|
|
1339
|
+
placeholder: selectedUser?.id ? t("AbpIdentity::LeaveBlankToKeepCurrent") : ""
|
|
1340
|
+
}
|
|
1341
|
+
) }),
|
|
1342
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_theme_shared2.FormField, { label: t("AbpIdentity::EmailAddress"), required: true, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1343
|
+
import_react8.Input,
|
|
1344
|
+
{
|
|
1345
|
+
type: "email",
|
|
1346
|
+
value: formState.email,
|
|
1347
|
+
onChange: (e) => handleInputChange("email", e.target.value),
|
|
1348
|
+
maxLength: 256
|
|
1349
|
+
}
|
|
1350
|
+
) }),
|
|
1351
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_theme_shared2.FormField, { label: t("AbpIdentity::PhoneNumber"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1352
|
+
import_react8.Input,
|
|
1353
|
+
{
|
|
1354
|
+
value: formState.phoneNumber,
|
|
1355
|
+
onChange: (e) => handleInputChange("phoneNumber", e.target.value),
|
|
1356
|
+
maxLength: 16
|
|
1357
|
+
}
|
|
1358
|
+
) }),
|
|
1359
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1360
|
+
import_theme_shared2.Checkbox,
|
|
1361
|
+
{
|
|
1362
|
+
checked: formState.lockoutEnabled,
|
|
1363
|
+
onChange: (e) => handleInputChange("lockoutEnabled", e.target.checked),
|
|
1364
|
+
children: t("AbpIdentity::DisplayName:LockoutEnabled")
|
|
1365
|
+
}
|
|
1366
|
+
),
|
|
1367
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1368
|
+
import_theme_shared2.Checkbox,
|
|
1369
|
+
{
|
|
1370
|
+
checked: formState.twoFactorEnabled,
|
|
1371
|
+
onChange: (e) => handleInputChange("twoFactorEnabled", e.target.checked),
|
|
1372
|
+
children: t("AbpIdentity::DisplayName:TwoFactorEnabled")
|
|
1373
|
+
}
|
|
1374
|
+
)
|
|
1375
|
+
] }) }),
|
|
1376
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react8.Tabs.Content, { value: "roles", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react8.VStack, { gap: 2, align: "stretch", pt: 4, children: [
|
|
1377
|
+
roles.map((role) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1378
|
+
import_theme_shared2.Checkbox,
|
|
1379
|
+
{
|
|
1380
|
+
checked: formState.roleNames.includes(role.name),
|
|
1381
|
+
onChange: (e) => handleRoleChange(role.name, e.target.checked),
|
|
1382
|
+
children: role.name
|
|
1383
|
+
},
|
|
1384
|
+
role.id
|
|
1385
|
+
)),
|
|
1386
|
+
roles.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react8.Text, { color: "gray.500", children: t("AbpIdentity::NoRolesFound") })
|
|
1387
|
+
] }) })
|
|
1388
|
+
] })
|
|
1389
|
+
}
|
|
1390
|
+
),
|
|
1391
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1392
|
+
import_permission_management2.PermissionManagementModal,
|
|
1393
|
+
{
|
|
1394
|
+
visible: isPermissionModalOpen,
|
|
1395
|
+
onVisibleChange: setIsPermissionModalOpen,
|
|
1396
|
+
providerName: "U",
|
|
1397
|
+
providerKey: permissionProviderKey
|
|
1398
|
+
}
|
|
1399
|
+
)
|
|
1400
|
+
] });
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
// src/components/Claims/ClaimsComponent.tsx
|
|
1404
|
+
var import_react9 = require("react");
|
|
1405
|
+
var import_core6 = require("@abpjs/core");
|
|
1406
|
+
var import_theme_shared3 = require("@abpjs/theme-shared");
|
|
1407
|
+
var import_react10 = require("@chakra-ui/react");
|
|
1408
|
+
var import_react11 = require("@chakra-ui/react");
|
|
1409
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
1410
|
+
var DEFAULT_FORM_STATE3 = {
|
|
1411
|
+
name: "",
|
|
1412
|
+
required: false,
|
|
1413
|
+
regex: "",
|
|
1414
|
+
regexDescription: "",
|
|
1415
|
+
description: "",
|
|
1416
|
+
valueType: 0
|
|
1417
|
+
};
|
|
1418
|
+
var VALUE_TYPE_OPTIONS = [
|
|
1419
|
+
{ value: 0, label: "String" },
|
|
1420
|
+
{ value: 1, label: "Int" },
|
|
1421
|
+
{ value: 2, label: "Boolean" },
|
|
1422
|
+
{ value: 3, label: "DateTime" }
|
|
1423
|
+
];
|
|
1424
|
+
function getValueTypeName(valueType) {
|
|
1425
|
+
const option = VALUE_TYPE_OPTIONS.find((opt) => opt.value === valueType);
|
|
1426
|
+
return option?.label || "String";
|
|
1427
|
+
}
|
|
1428
|
+
function ClaimsComponent({
|
|
1429
|
+
onClaimTypeCreated,
|
|
1430
|
+
onClaimTypeUpdated,
|
|
1431
|
+
onClaimTypeDeleted
|
|
1432
|
+
}) {
|
|
1433
|
+
const { t } = (0, import_core6.useLocalization)();
|
|
1434
|
+
const confirmation = (0, import_theme_shared3.useConfirmation)();
|
|
1435
|
+
const {
|
|
1436
|
+
claimTypes,
|
|
1437
|
+
selectedClaimType,
|
|
1438
|
+
isLoading,
|
|
1439
|
+
error,
|
|
1440
|
+
fetchClaimTypes,
|
|
1441
|
+
getClaimTypeById,
|
|
1442
|
+
createClaimType,
|
|
1443
|
+
updateClaimType,
|
|
1444
|
+
deleteClaimType,
|
|
1445
|
+
setSelectedClaimType
|
|
1446
|
+
} = useClaims();
|
|
1447
|
+
const [isModalOpen, setIsModalOpen] = (0, import_react9.useState)(false);
|
|
1448
|
+
const [formState, setFormState] = (0, import_react9.useState)(DEFAULT_FORM_STATE3);
|
|
1449
|
+
const [isSubmitting, setIsSubmitting] = (0, import_react9.useState)(false);
|
|
1450
|
+
const [searchTerm, setSearchTerm] = (0, import_react9.useState)("");
|
|
1451
|
+
(0, import_react9.useEffect)(() => {
|
|
1452
|
+
fetchClaimTypes();
|
|
1453
|
+
}, [fetchClaimTypes]);
|
|
1454
|
+
const filteredClaimTypes = claimTypes.filter(
|
|
1455
|
+
(claim) => !searchTerm || claim.name.toLowerCase().includes(searchTerm.toLowerCase())
|
|
1456
|
+
);
|
|
1457
|
+
const handleAdd = (0, import_react9.useCallback)(() => {
|
|
1458
|
+
setSelectedClaimType(null);
|
|
1459
|
+
setFormState(DEFAULT_FORM_STATE3);
|
|
1460
|
+
setIsModalOpen(true);
|
|
1461
|
+
}, [setSelectedClaimType]);
|
|
1462
|
+
const handleEdit = (0, import_react9.useCallback)(
|
|
1463
|
+
async (id) => {
|
|
1464
|
+
const result = await getClaimTypeById(id);
|
|
1465
|
+
if (result.success && selectedClaimType) {
|
|
1466
|
+
setFormState({
|
|
1467
|
+
name: selectedClaimType.name || "",
|
|
1468
|
+
required: selectedClaimType.required || false,
|
|
1469
|
+
regex: selectedClaimType.regex || "",
|
|
1470
|
+
regexDescription: selectedClaimType.regexDescription || "",
|
|
1471
|
+
description: selectedClaimType.description || "",
|
|
1472
|
+
valueType: selectedClaimType.valueType || 0
|
|
1473
|
+
});
|
|
1474
|
+
setIsModalOpen(true);
|
|
1475
|
+
}
|
|
1476
|
+
},
|
|
1477
|
+
[getClaimTypeById, selectedClaimType]
|
|
1478
|
+
);
|
|
1479
|
+
(0, import_react9.useEffect)(() => {
|
|
1480
|
+
if (selectedClaimType) {
|
|
1481
|
+
setFormState({
|
|
1482
|
+
name: selectedClaimType.name || "",
|
|
1483
|
+
required: selectedClaimType.required || false,
|
|
1484
|
+
regex: selectedClaimType.regex || "",
|
|
1485
|
+
regexDescription: selectedClaimType.regexDescription || "",
|
|
1486
|
+
description: selectedClaimType.description || "",
|
|
1487
|
+
valueType: selectedClaimType.valueType || 0
|
|
1488
|
+
});
|
|
1489
|
+
}
|
|
1490
|
+
}, [selectedClaimType]);
|
|
1491
|
+
const handleDelete = (0, import_react9.useCallback)(
|
|
1492
|
+
async (id, name) => {
|
|
1493
|
+
const status = await confirmation.warn(
|
|
1494
|
+
t("AbpIdentity::ClaimTypeDeletionConfirmationMessage", name) || `Are you sure you want to delete the claim type '${name}'?`,
|
|
1495
|
+
t("AbpIdentity::AreYouSure")
|
|
1496
|
+
);
|
|
1497
|
+
if (status === import_theme_shared3.Toaster.Status.confirm) {
|
|
1498
|
+
const result = await deleteClaimType(id);
|
|
1499
|
+
if (result.success) {
|
|
1500
|
+
onClaimTypeDeleted?.(id);
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
},
|
|
1504
|
+
[confirmation, t, deleteClaimType, onClaimTypeDeleted]
|
|
1505
|
+
);
|
|
1506
|
+
const handleSubmit = (0, import_react9.useCallback)(async () => {
|
|
1507
|
+
if (!formState.name.trim()) return;
|
|
1508
|
+
setIsSubmitting(true);
|
|
1509
|
+
const claimTypeData = {
|
|
1510
|
+
id: selectedClaimType?.id,
|
|
1511
|
+
name: formState.name.trim(),
|
|
1512
|
+
required: formState.required,
|
|
1513
|
+
isStatic: selectedClaimType?.isStatic || false,
|
|
1514
|
+
regex: formState.regex,
|
|
1515
|
+
regexDescription: formState.regexDescription,
|
|
1516
|
+
description: formState.description,
|
|
1517
|
+
valueType: formState.valueType
|
|
1518
|
+
};
|
|
1519
|
+
let result;
|
|
1520
|
+
if (selectedClaimType?.id) {
|
|
1521
|
+
result = await updateClaimType(claimTypeData);
|
|
1522
|
+
if (result.success) {
|
|
1523
|
+
onClaimTypeUpdated?.(claimTypeData);
|
|
1524
|
+
}
|
|
1525
|
+
} else {
|
|
1526
|
+
result = await createClaimType(claimTypeData);
|
|
1527
|
+
if (result.success) {
|
|
1528
|
+
onClaimTypeCreated?.(claimTypeData);
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
setIsSubmitting(false);
|
|
1532
|
+
if (result.success) {
|
|
1533
|
+
setIsModalOpen(false);
|
|
1534
|
+
setFormState(DEFAULT_FORM_STATE3);
|
|
1535
|
+
setSelectedClaimType(null);
|
|
1536
|
+
}
|
|
1537
|
+
}, [formState, selectedClaimType, updateClaimType, createClaimType, onClaimTypeCreated, onClaimTypeUpdated, setSelectedClaimType]);
|
|
1538
|
+
const handleModalClose = (0, import_react9.useCallback)(() => {
|
|
1539
|
+
setIsModalOpen(false);
|
|
1540
|
+
setFormState(DEFAULT_FORM_STATE3);
|
|
1541
|
+
setSelectedClaimType(null);
|
|
1542
|
+
}, [setSelectedClaimType]);
|
|
1543
|
+
const handleInputChange = (0, import_react9.useCallback)(
|
|
1544
|
+
(field, value) => {
|
|
1545
|
+
setFormState((prev) => ({ ...prev, [field]: value }));
|
|
1546
|
+
},
|
|
1547
|
+
[]
|
|
1548
|
+
);
|
|
1549
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react10.Box, { id: "identity-claims-wrapper", className: "card", p: 4, children: [
|
|
1550
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react10.Flex, { justify: "space-between", align: "center", mb: 4, children: [
|
|
1551
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react10.Text, { fontSize: "xl", fontWeight: "bold", children: t("AbpIdentity::ClaimTypes") || "Claim Types" }),
|
|
1552
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_theme_shared3.Button, { colorPalette: "blue", onClick: handleAdd, children: t("AbpIdentity::NewClaimType") || "New Claim Type" })
|
|
1553
|
+
] }),
|
|
1554
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react10.Box, { mb: 4, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1555
|
+
import_react10.Input,
|
|
1556
|
+
{
|
|
1557
|
+
placeholder: t("AbpIdentity::Search"),
|
|
1558
|
+
value: searchTerm,
|
|
1559
|
+
onChange: (e) => setSearchTerm(e.target.value),
|
|
1560
|
+
maxW: "300px"
|
|
1561
|
+
}
|
|
1562
|
+
) }),
|
|
1563
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_theme_shared3.Alert, { status: "error", mb: 4, children: error }),
|
|
1564
|
+
isLoading && claimTypes.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react10.Flex, { justify: "center", py: 8, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react10.Spinner, { size: "lg" }) }),
|
|
1565
|
+
claimTypes.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react10.Table.Root, { variant: "outline", children: [
|
|
1566
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react10.Table.Header, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react10.Table.Row, { children: [
|
|
1567
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react10.Table.ColumnHeader, { children: t("AbpIdentity::Actions") }),
|
|
1568
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react10.Table.ColumnHeader, { children: t("AbpIdentity::ClaimTypeName") || "Name" }),
|
|
1569
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react10.Table.ColumnHeader, { children: t("AbpIdentity::ValueType") || "Value Type" }),
|
|
1570
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react10.Table.ColumnHeader, { children: t("AbpIdentity::Description") || "Description" })
|
|
1571
|
+
] }) }),
|
|
1572
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react10.Table.Body, { children: filteredClaimTypes.map((claimType) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react10.Table.Row, { children: [
|
|
1573
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react10.Table.Cell, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react10.Menu.Root, { children: [
|
|
1574
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react10.Menu.Trigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_theme_shared3.Button, { size: "sm", colorPalette: "blue", children: t("AbpIdentity::Actions") }) }),
|
|
1575
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react10.Menu.Positioner, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react10.Menu.Content, { children: [
|
|
1576
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react10.Menu.Item, { value: "edit", onClick: () => handleEdit(claimType.id), children: t("AbpIdentity::Edit") }),
|
|
1577
|
+
!claimType.isStatic && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1578
|
+
import_react10.Menu.Item,
|
|
1579
|
+
{
|
|
1580
|
+
value: "delete",
|
|
1581
|
+
color: "red.500",
|
|
1582
|
+
onClick: () => handleDelete(claimType.id, claimType.name),
|
|
1583
|
+
children: t("AbpIdentity::Delete")
|
|
1584
|
+
}
|
|
1585
|
+
)
|
|
1586
|
+
] }) })
|
|
1587
|
+
] }) }),
|
|
1588
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react10.Table.Cell, { children: claimType.name }),
|
|
1589
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react10.Table.Cell, { children: getValueTypeName(claimType.valueType) }),
|
|
1590
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react10.Table.Cell, { children: claimType.description })
|
|
1591
|
+
] }, claimType.id)) })
|
|
1592
|
+
] }),
|
|
1593
|
+
!isLoading && claimTypes.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react10.Text, { textAlign: "center", color: "gray.500", py: 8, children: t("AbpIdentity::NoClaimTypesFound") || "No claim types found" }),
|
|
1594
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1595
|
+
import_theme_shared3.Modal,
|
|
1596
|
+
{
|
|
1597
|
+
visible: isModalOpen,
|
|
1598
|
+
onVisibleChange: setIsModalOpen,
|
|
1599
|
+
header: selectedClaimType?.id ? t("AbpIdentity::Edit") : t("AbpIdentity::NewClaimType") || "New Claim Type",
|
|
1600
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
1601
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_theme_shared3.Button, { variant: "outline", onClick: handleModalClose, disabled: isSubmitting, children: t("AbpIdentity::Cancel") }),
|
|
1602
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1603
|
+
import_theme_shared3.Button,
|
|
1604
|
+
{
|
|
1605
|
+
colorPalette: "blue",
|
|
1606
|
+
onClick: handleSubmit,
|
|
1607
|
+
loading: isSubmitting,
|
|
1608
|
+
disabled: !formState.name.trim(),
|
|
1609
|
+
children: t("AbpIdentity::Save")
|
|
1610
|
+
}
|
|
1611
|
+
)
|
|
1612
|
+
] }),
|
|
1613
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react10.VStack, { gap: 4, align: "stretch", children: [
|
|
1614
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_theme_shared3.FormField, { label: t("AbpIdentity::ClaimTypeName") || "Name", required: true, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1615
|
+
import_react10.Input,
|
|
1616
|
+
{
|
|
1617
|
+
value: formState.name,
|
|
1618
|
+
onChange: (e) => handleInputChange("name", e.target.value),
|
|
1619
|
+
maxLength: 256,
|
|
1620
|
+
placeholder: t("AbpIdentity::ClaimTypeName") || "Name",
|
|
1621
|
+
disabled: selectedClaimType?.isStatic
|
|
1622
|
+
}
|
|
1623
|
+
) }),
|
|
1624
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_theme_shared3.FormField, { label: t("AbpIdentity::ValueType") || "Value Type", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react11.NativeSelectRoot, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1625
|
+
import_react11.NativeSelectField,
|
|
1626
|
+
{
|
|
1627
|
+
value: formState.valueType,
|
|
1628
|
+
onChange: (e) => handleInputChange("valueType", parseInt(e.target.value, 10)),
|
|
1629
|
+
children: VALUE_TYPE_OPTIONS.map((option) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: option.value, children: option.label }, option.value))
|
|
1630
|
+
}
|
|
1631
|
+
) }) }),
|
|
1632
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_theme_shared3.FormField, { label: t("AbpIdentity::Description") || "Description", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1633
|
+
import_react10.Textarea,
|
|
1634
|
+
{
|
|
1635
|
+
value: formState.description,
|
|
1636
|
+
onChange: (e) => handleInputChange("description", e.target.value),
|
|
1637
|
+
placeholder: t("AbpIdentity::Description") || "Description",
|
|
1638
|
+
rows: 2
|
|
1639
|
+
}
|
|
1640
|
+
) }),
|
|
1641
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_theme_shared3.FormField, { label: t("AbpIdentity::Regex") || "Regex", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1642
|
+
import_react10.Input,
|
|
1643
|
+
{
|
|
1644
|
+
value: formState.regex,
|
|
1645
|
+
onChange: (e) => handleInputChange("regex", e.target.value),
|
|
1646
|
+
placeholder: t("AbpIdentity::Regex") || "Regex pattern"
|
|
1647
|
+
}
|
|
1648
|
+
) }),
|
|
1649
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_theme_shared3.FormField, { label: t("AbpIdentity::RegexDescription") || "Regex Description", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1650
|
+
import_react10.Input,
|
|
1651
|
+
{
|
|
1652
|
+
value: formState.regexDescription,
|
|
1653
|
+
onChange: (e) => handleInputChange("regexDescription", e.target.value),
|
|
1654
|
+
placeholder: t("AbpIdentity::RegexDescription") || "Regex description"
|
|
1655
|
+
}
|
|
1656
|
+
) })
|
|
1657
|
+
] })
|
|
1658
|
+
}
|
|
1659
|
+
)
|
|
1660
|
+
] });
|
|
1661
|
+
}
|
|
1662
|
+
|
|
1663
|
+
// src/components/Claims/ClaimModal.tsx
|
|
1664
|
+
var import_react12 = require("react");
|
|
1665
|
+
var import_core7 = require("@abpjs/core");
|
|
1666
|
+
var import_theme_shared4 = require("@abpjs/theme-shared");
|
|
1667
|
+
var import_react13 = require("@chakra-ui/react");
|
|
1668
|
+
var import_react14 = require("@chakra-ui/react");
|
|
1669
|
+
var import_lu = require("react-icons/lu");
|
|
1670
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1671
|
+
function ClaimModal({
|
|
1672
|
+
visible,
|
|
1673
|
+
onVisibleChange,
|
|
1674
|
+
subjectId,
|
|
1675
|
+
subjectType,
|
|
1676
|
+
onSaved
|
|
1677
|
+
}) {
|
|
1678
|
+
const { t } = (0, import_core7.useLocalization)();
|
|
1679
|
+
const {
|
|
1680
|
+
claimTypeNames,
|
|
1681
|
+
fetchClaimTypeNames,
|
|
1682
|
+
getClaims,
|
|
1683
|
+
updateClaims,
|
|
1684
|
+
isLoading
|
|
1685
|
+
} = useClaims();
|
|
1686
|
+
const [subjectClaims, setSubjectClaims] = (0, import_react12.useState)([]);
|
|
1687
|
+
const [newClaimType, setNewClaimType] = (0, import_react12.useState)("");
|
|
1688
|
+
const [newClaimValue, setNewClaimValue] = (0, import_react12.useState)("");
|
|
1689
|
+
const [isSaving, setIsSaving] = (0, import_react12.useState)(false);
|
|
1690
|
+
const initModal = (0, import_react12.useCallback)(async () => {
|
|
1691
|
+
if (!visible || !subjectId) return;
|
|
1692
|
+
await fetchClaimTypeNames();
|
|
1693
|
+
const claims = await getClaims(subjectId, subjectType);
|
|
1694
|
+
setSubjectClaims(claims);
|
|
1695
|
+
}, [visible, subjectId, subjectType, fetchClaimTypeNames, getClaims]);
|
|
1696
|
+
(0, import_react12.useEffect)(() => {
|
|
1697
|
+
if (visible) {
|
|
1698
|
+
initModal();
|
|
1699
|
+
} else {
|
|
1700
|
+
setSubjectClaims([]);
|
|
1701
|
+
setNewClaimType("");
|
|
1702
|
+
setNewClaimValue("");
|
|
1703
|
+
}
|
|
1704
|
+
}, [visible, initModal]);
|
|
1705
|
+
const handleAddClaim = (0, import_react12.useCallback)(() => {
|
|
1706
|
+
if (!newClaimType.trim() || !newClaimValue.trim()) return;
|
|
1707
|
+
const newClaim = {
|
|
1708
|
+
claimType: newClaimType.trim(),
|
|
1709
|
+
claimValue: newClaimValue.trim(),
|
|
1710
|
+
...subjectType === "users" ? { userId: subjectId } : { roleId: subjectId }
|
|
1711
|
+
};
|
|
1712
|
+
setSubjectClaims((prev) => [...prev, newClaim]);
|
|
1713
|
+
setNewClaimType("");
|
|
1714
|
+
setNewClaimValue("");
|
|
1715
|
+
}, [newClaimType, newClaimValue, subjectId, subjectType]);
|
|
1716
|
+
const handleRemoveClaim = (0, import_react12.useCallback)((index) => {
|
|
1717
|
+
setSubjectClaims((prev) => prev.filter((_, i) => i !== index));
|
|
1718
|
+
}, []);
|
|
1719
|
+
const handleSave = (0, import_react12.useCallback)(async () => {
|
|
1720
|
+
setIsSaving(true);
|
|
1721
|
+
const result = await updateClaims(subjectId, subjectType, subjectClaims);
|
|
1722
|
+
setIsSaving(false);
|
|
1723
|
+
if (result.success) {
|
|
1724
|
+
onSaved?.();
|
|
1725
|
+
onVisibleChange(false);
|
|
1726
|
+
}
|
|
1727
|
+
}, [subjectId, subjectType, subjectClaims, updateClaims, onSaved, onVisibleChange]);
|
|
1728
|
+
const handleClose = (0, import_react12.useCallback)(() => {
|
|
1729
|
+
onVisibleChange(false);
|
|
1730
|
+
}, [onVisibleChange]);
|
|
1731
|
+
const modalTitle = subjectType === "users" ? t("AbpIdentity::UserClaims") || "User Claims" : t("AbpIdentity::RoleClaims") || "Role Claims";
|
|
1732
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1733
|
+
import_theme_shared4.Modal,
|
|
1734
|
+
{
|
|
1735
|
+
visible,
|
|
1736
|
+
onVisibleChange,
|
|
1737
|
+
header: modalTitle,
|
|
1738
|
+
size: "lg",
|
|
1739
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
1740
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_theme_shared4.Button, { variant: "outline", onClick: handleClose, disabled: isSaving, children: t("AbpIdentity::Cancel") }),
|
|
1741
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1742
|
+
import_theme_shared4.Button,
|
|
1743
|
+
{
|
|
1744
|
+
colorPalette: "blue",
|
|
1745
|
+
onClick: handleSave,
|
|
1746
|
+
loading: isSaving,
|
|
1747
|
+
children: t("AbpIdentity::Save")
|
|
1748
|
+
}
|
|
1749
|
+
)
|
|
1750
|
+
] }),
|
|
1751
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react13.VStack, { gap: 4, align: "stretch", children: [
|
|
1752
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react13.Box, { borderWidth: "1px", borderRadius: "md", p: 4, children: [
|
|
1753
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react13.Text, { fontWeight: "semibold", mb: 3, children: t("AbpIdentity::AddNewClaim") || "Add New Claim" }),
|
|
1754
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react13.HStack, { gap: 3, align: "flex-end", children: [
|
|
1755
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react13.Box, { flex: 1, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_theme_shared4.FormField, { label: t("AbpIdentity::ClaimType") || "Claim Type", children: claimTypeNames.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react14.NativeSelectRoot, { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
1756
|
+
import_react14.NativeSelectField,
|
|
1757
|
+
{
|
|
1758
|
+
value: newClaimType,
|
|
1759
|
+
onChange: (e) => setNewClaimType(e.target.value),
|
|
1760
|
+
placeholder: t("AbpIdentity::SelectClaimType") || "Select claim type",
|
|
1761
|
+
children: [
|
|
1762
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("option", { value: "", children: t("AbpIdentity::SelectClaimType") || "Select claim type" }),
|
|
1763
|
+
claimTypeNames.map((ct) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("option", { value: ct.name, children: ct.name }, ct.name))
|
|
1764
|
+
]
|
|
1765
|
+
}
|
|
1766
|
+
) }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1767
|
+
import_react13.Input,
|
|
1768
|
+
{
|
|
1769
|
+
value: newClaimType,
|
|
1770
|
+
onChange: (e) => setNewClaimType(e.target.value),
|
|
1771
|
+
placeholder: t("AbpIdentity::ClaimType") || "Claim type"
|
|
1772
|
+
}
|
|
1773
|
+
) }) }),
|
|
1774
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react13.Box, { flex: 1, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_theme_shared4.FormField, { label: t("AbpIdentity::ClaimValue") || "Claim Value", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1775
|
+
import_react13.Input,
|
|
1776
|
+
{
|
|
1777
|
+
value: newClaimValue,
|
|
1778
|
+
onChange: (e) => setNewClaimValue(e.target.value),
|
|
1779
|
+
placeholder: t("AbpIdentity::ClaimValue") || "Claim value"
|
|
1780
|
+
}
|
|
1781
|
+
) }) }),
|
|
1782
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1783
|
+
import_react13.IconButton,
|
|
1784
|
+
{
|
|
1785
|
+
"aria-label": t("AbpIdentity::Add") || "Add",
|
|
1786
|
+
colorPalette: "blue",
|
|
1787
|
+
onClick: handleAddClaim,
|
|
1788
|
+
disabled: !newClaimType.trim() || !newClaimValue.trim(),
|
|
1789
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_lu.LuPlus, {})
|
|
1790
|
+
}
|
|
1791
|
+
)
|
|
1792
|
+
] })
|
|
1793
|
+
] }),
|
|
1794
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react13.Box, { children: [
|
|
1795
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react13.Text, { fontWeight: "semibold", mb: 3, children: [
|
|
1796
|
+
t("AbpIdentity::CurrentClaims") || "Current Claims",
|
|
1797
|
+
" (",
|
|
1798
|
+
subjectClaims.length,
|
|
1799
|
+
")"
|
|
1800
|
+
] }),
|
|
1801
|
+
subjectClaims.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react13.Text, { color: "gray.500", textAlign: "center", py: 4, children: t("AbpIdentity::NoClaimsFound") || "No claims found" }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react13.VStack, { gap: 2, align: "stretch", children: subjectClaims.map((claim, index) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
1802
|
+
import_react13.Flex,
|
|
1803
|
+
{
|
|
1804
|
+
justify: "space-between",
|
|
1805
|
+
align: "center",
|
|
1806
|
+
p: 3,
|
|
1807
|
+
borderWidth: "1px",
|
|
1808
|
+
borderRadius: "md",
|
|
1809
|
+
children: [
|
|
1810
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react13.Box, { children: [
|
|
1811
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react13.Text, { fontWeight: "medium", children: claim.claimType }),
|
|
1812
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react13.Text, { fontSize: "sm", color: "gray.600", children: claim.claimValue })
|
|
1813
|
+
] }),
|
|
1814
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1815
|
+
import_react13.IconButton,
|
|
1816
|
+
{
|
|
1817
|
+
"aria-label": t("AbpIdentity::Remove") || "Remove",
|
|
1818
|
+
colorPalette: "red",
|
|
1819
|
+
variant: "ghost",
|
|
1820
|
+
size: "sm",
|
|
1821
|
+
onClick: () => handleRemoveClaim(index),
|
|
1822
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_lu.LuTrash, {})
|
|
1823
|
+
}
|
|
1824
|
+
)
|
|
1825
|
+
]
|
|
1826
|
+
},
|
|
1827
|
+
index
|
|
1828
|
+
)) })
|
|
1829
|
+
] }),
|
|
1830
|
+
isLoading && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react13.Text, { textAlign: "center", color: "gray.500", children: t("AbpUi::Loading") || "Loading..." })
|
|
1831
|
+
] })
|
|
1832
|
+
}
|
|
1833
|
+
);
|
|
1834
|
+
}
|
|
1835
|
+
|
|
1836
|
+
// src/constants/routes.ts
|
|
1837
|
+
var import_core8 = require("@abpjs/core");
|
|
1838
|
+
var IDENTITY_ROUTES = {
|
|
1839
|
+
routes: [
|
|
1840
|
+
{
|
|
1841
|
+
name: "AbpUiNavigation::Menu:Administration",
|
|
1842
|
+
path: "",
|
|
1843
|
+
order: 1,
|
|
1844
|
+
wrapper: true
|
|
1845
|
+
},
|
|
1846
|
+
{
|
|
1847
|
+
name: "AbpIdentity::Menu:IdentityManagement",
|
|
1848
|
+
path: "identity",
|
|
1849
|
+
order: 1,
|
|
1850
|
+
parentName: "AbpUiNavigation::Menu:Administration",
|
|
1851
|
+
layout: import_core8.eLayoutType.application,
|
|
1852
|
+
children: [
|
|
1853
|
+
{
|
|
1854
|
+
path: "roles",
|
|
1855
|
+
name: "AbpIdentity::Roles",
|
|
1856
|
+
order: 2,
|
|
1857
|
+
requiredPolicy: "AbpIdentity.Roles"
|
|
1858
|
+
},
|
|
1859
|
+
{
|
|
1860
|
+
path: "users",
|
|
1861
|
+
name: "AbpIdentity::Users",
|
|
1862
|
+
order: 1,
|
|
1863
|
+
requiredPolicy: "AbpIdentity.Users"
|
|
1864
|
+
}
|
|
1865
|
+
]
|
|
1866
|
+
}
|
|
1867
|
+
]
|
|
1868
|
+
};
|
|
1869
|
+
var IDENTITY_ROUTE_PATHS = {
|
|
1870
|
+
/** Base path for identity module */
|
|
1871
|
+
BASE: "/identity",
|
|
1872
|
+
/** Roles management path */
|
|
1873
|
+
ROLES: "/identity/roles",
|
|
1874
|
+
/** Users management path */
|
|
1875
|
+
USERS: "/identity/users"
|
|
1876
|
+
};
|
|
1877
|
+
var IDENTITY_POLICIES = {
|
|
1878
|
+
/** Policy for roles management */
|
|
1879
|
+
ROLES: "AbpIdentity.Roles",
|
|
1880
|
+
/** Policy for users management */
|
|
1881
|
+
USERS: "AbpIdentity.Users",
|
|
1882
|
+
/** Policy for creating users */
|
|
1883
|
+
USERS_CREATE: "AbpIdentity.Users.Create",
|
|
1884
|
+
/** Policy for updating users */
|
|
1885
|
+
USERS_UPDATE: "AbpIdentity.Users.Update",
|
|
1886
|
+
/** Policy for deleting users */
|
|
1887
|
+
USERS_DELETE: "AbpIdentity.Users.Delete",
|
|
1888
|
+
/** Policy for creating roles */
|
|
1889
|
+
ROLES_CREATE: "AbpIdentity.Roles.Create",
|
|
1890
|
+
/** Policy for updating roles */
|
|
1891
|
+
ROLES_UPDATE: "AbpIdentity.Roles.Update",
|
|
1892
|
+
/** Policy for deleting roles */
|
|
1893
|
+
ROLES_DELETE: "AbpIdentity.Roles.Delete"
|
|
1894
|
+
};
|
|
1895
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1896
|
+
0 && (module.exports = {
|
|
1897
|
+
ClaimModal,
|
|
1898
|
+
ClaimsComponent,
|
|
1899
|
+
IDENTITY_POLICIES,
|
|
1900
|
+
IDENTITY_ROUTES,
|
|
1901
|
+
IDENTITY_ROUTE_PATHS,
|
|
1902
|
+
Identity,
|
|
1903
|
+
IdentityService,
|
|
1904
|
+
RolesComponent,
|
|
1905
|
+
UsersComponent,
|
|
1906
|
+
useClaims,
|
|
1907
|
+
useIdentity,
|
|
1908
|
+
useRoles,
|
|
1909
|
+
useUsers
|
|
1910
|
+
});
|