@abpjs/permission-management 0.7.6

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 ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version of
113
+ the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
package/README.md ADDED
@@ -0,0 +1,372 @@
1
+ # @abpjs/permission-management
2
+
3
+ > Permission management UI components for ABP Framework in React
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@abpjs/permission-management.svg)](https://www.npmjs.com/package/@abpjs/permission-management)
6
+ [![License: LGPL-3.0](https://img.shields.io/badge/License-LGPL--3.0-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0)
7
+
8
+ ## Overview
9
+
10
+ `@abpjs/permission-management` provides a complete permission management interface for ABP-based React applications. It allows administrators to view, grant, and revoke permissions for users, roles, and other permission providers through a user-friendly modal interface.
11
+
12
+ This package is a React translation of the original `@abp/ng.permission-management` Angular package, offering the same powerful permission management capabilities with modern React patterns.
13
+
14
+ ## Features
15
+
16
+ - **Permission Modal** - Ready-to-use modal dialog for managing permissions
17
+ - **Role Permissions** - Manage permissions for roles
18
+ - **User Permissions** - Manage permissions for individual users
19
+ - **Permission Groups** - Organized permission display by groups
20
+ - **Bulk Operations** - Grant or revoke multiple permissions at once
21
+ - **Real-time Updates** - Instant UI feedback on permission changes
22
+ - **Chakra UI** - Beautiful, accessible components
23
+ - **TypeScript** - Full type safety with comprehensive definitions
24
+
25
+ ## Installation
26
+
27
+ ```bash
28
+ # Using npm
29
+ npm install @abpjs/permission-management
30
+
31
+ # Using yarn
32
+ yarn add @abpjs/permission-management
33
+
34
+ # Using pnpm
35
+ pnpm add @abpjs/permission-management
36
+ ```
37
+
38
+ ### Required Dependencies
39
+
40
+ This package requires the following peer dependencies:
41
+
42
+ ```bash
43
+ npm install @abpjs/core @abpjs/theme-shared @chakra-ui/react @emotion/react @emotion/styled framer-motion
44
+ ```
45
+
46
+ ## Quick Start
47
+
48
+ ### Basic Usage with Permission Modal
49
+
50
+ ```tsx
51
+ import { useState } from 'react';
52
+ import { PermissionManagementModal } from '@abpjs/permission-management';
53
+ import { Button } from '@chakra-ui/react';
54
+
55
+ function RoleManagement() {
56
+ const [isOpen, setIsOpen] = useState(false);
57
+ const [selectedRole, setSelectedRole] = useState(null);
58
+
59
+ const openPermissions = (role) => {
60
+ setSelectedRole(role);
61
+ setIsOpen(true);
62
+ };
63
+
64
+ return (
65
+ <div>
66
+ <Button onClick={() => openPermissions({ id: 'role-id', name: 'admin' })}>
67
+ Manage Permissions
68
+ </Button>
69
+
70
+ <PermissionManagementModal
71
+ isOpen={isOpen}
72
+ onClose={() => setIsOpen(false)}
73
+ providerName="R" // R for Role
74
+ providerKey={selectedRole?.id}
75
+ />
76
+ </div>
77
+ );
78
+ }
79
+ ```
80
+
81
+ ### Managing User Permissions
82
+
83
+ ```tsx
84
+ import { PermissionManagementModal } from '@abpjs/permission-management';
85
+
86
+ function UserPermissions({ userId }) {
87
+ const [isOpen, setIsOpen] = useState(false);
88
+
89
+ return (
90
+ <>
91
+ <Button onClick={() => setIsOpen(true)}>
92
+ Edit User Permissions
93
+ </Button>
94
+
95
+ <PermissionManagementModal
96
+ isOpen={isOpen}
97
+ onClose={() => setIsOpen(false)}
98
+ providerName="U" // U for User
99
+ providerKey={userId}
100
+ />
101
+ </>
102
+ );
103
+ }
104
+ ```
105
+
106
+ ## Components
107
+
108
+ ### PermissionManagementModal
109
+
110
+ The main component for displaying and managing permissions.
111
+
112
+ ```tsx
113
+ import { PermissionManagementModal } from '@abpjs/permission-management';
114
+
115
+ <PermissionManagementModal
116
+ isOpen={isOpen}
117
+ onClose={handleClose}
118
+ providerName="R"
119
+ providerKey="admin-role-id"
120
+ onSave={handleSave}
121
+ />
122
+ ```
123
+
124
+ **Props:**
125
+
126
+ | Prop | Type | Description |
127
+ |------|------|-------------|
128
+ | `isOpen` | `boolean` | Controls modal visibility |
129
+ | `onClose` | `() => void` | Callback when modal is closed |
130
+ | `providerName` | `string` | Permission provider type ("R" for Role, "U" for User) |
131
+ | `providerKey` | `string` | The identifier of the role or user |
132
+ | `onSave` | `() => void` | Optional callback after permissions are saved |
133
+
134
+ ## Hooks
135
+
136
+ ### usePermissionManagement
137
+
138
+ Hook for accessing permission management functionality programmatically.
139
+
140
+ ```tsx
141
+ import { usePermissionManagement } from '@abpjs/permission-management';
142
+
143
+ function CustomPermissionUI() {
144
+ const {
145
+ permissions,
146
+ isLoading,
147
+ error,
148
+ getPermissions,
149
+ updatePermissions,
150
+ } = usePermissionManagement();
151
+
152
+ useEffect(() => {
153
+ getPermissions({
154
+ providerName: 'R',
155
+ providerKey: 'admin',
156
+ });
157
+ }, []);
158
+
159
+ const handleToggle = async (permissionName, isGranted) => {
160
+ await updatePermissions({
161
+ providerName: 'R',
162
+ providerKey: 'admin',
163
+ permissions: {
164
+ [permissionName]: isGranted,
165
+ },
166
+ });
167
+ };
168
+
169
+ if (isLoading) return <Spinner />;
170
+ if (error) return <ErrorMessage error={error} />;
171
+
172
+ return (
173
+ <div>
174
+ {permissions.groups.map(group => (
175
+ <PermissionGroup
176
+ key={group.name}
177
+ group={group}
178
+ onToggle={handleToggle}
179
+ />
180
+ ))}
181
+ </div>
182
+ );
183
+ }
184
+ ```
185
+
186
+ ## Services
187
+
188
+ ### PermissionManagementService
189
+
190
+ Service class for direct API interaction.
191
+
192
+ ```tsx
193
+ import { PermissionManagementService } from '@abpjs/permission-management';
194
+
195
+ // Get permissions for a role
196
+ const permissions = await PermissionManagementService.get({
197
+ providerName: 'R',
198
+ providerKey: 'admin-role-id',
199
+ });
200
+
201
+ // Update permissions
202
+ await PermissionManagementService.update({
203
+ providerName: 'R',
204
+ providerKey: 'admin-role-id',
205
+ permissions: [
206
+ { name: 'MyApp.Users.Create', isGranted: true },
207
+ { name: 'MyApp.Users.Delete', isGranted: false },
208
+ ],
209
+ });
210
+ ```
211
+
212
+ ## Permission Providers
213
+
214
+ ABP uses different provider types for different permission subjects:
215
+
216
+ | Provider | Key | Description |
217
+ |----------|-----|-------------|
218
+ | `R` | Role | Permissions for roles |
219
+ | `U` | User | Permissions for specific users |
220
+ | `C` | Client | Permissions for OAuth clients |
221
+
222
+ ## Data Models
223
+
224
+ ### PermissionGroup
225
+
226
+ ```typescript
227
+ interface PermissionGroup {
228
+ name: string;
229
+ displayName: string;
230
+ permissions: Permission[];
231
+ }
232
+ ```
233
+
234
+ ### Permission
235
+
236
+ ```typescript
237
+ interface Permission {
238
+ name: string;
239
+ displayName: string;
240
+ isGranted: boolean;
241
+ allowedProviders: string[];
242
+ grantedProviders: GrantedProvider[];
243
+ }
244
+ ```
245
+
246
+ ## Integration Example
247
+
248
+ Complete example integrating with role management:
249
+
250
+ ```tsx
251
+ import { useState } from 'react';
252
+ import { usePermission } from '@abpjs/core';
253
+ import { PermissionManagementModal } from '@abpjs/permission-management';
254
+ import {
255
+ Table,
256
+ Button,
257
+ IconButton,
258
+ useDisclosure
259
+ } from '@chakra-ui/react';
260
+ import { SettingsIcon } from '@chakra-ui/icons';
261
+
262
+ function RolesTable({ roles }) {
263
+ const { hasPermission } = usePermission();
264
+ const { isOpen, onOpen, onClose } = useDisclosure();
265
+ const [selectedRole, setSelectedRole] = useState(null);
266
+
267
+ const canManagePermissions = hasPermission('AbpIdentity.Roles.ManagePermissions');
268
+
269
+ const handleManagePermissions = (role) => {
270
+ setSelectedRole(role);
271
+ onOpen();
272
+ };
273
+
274
+ return (
275
+ <>
276
+ <Table>
277
+ <thead>
278
+ <tr>
279
+ <th>Role Name</th>
280
+ <th>Actions</th>
281
+ </tr>
282
+ </thead>
283
+ <tbody>
284
+ {roles.map(role => (
285
+ <tr key={role.id}>
286
+ <td>{role.name}</td>
287
+ <td>
288
+ {canManagePermissions && (
289
+ <IconButton
290
+ aria-label="Manage permissions"
291
+ icon={<SettingsIcon />}
292
+ onClick={() => handleManagePermissions(role)}
293
+ />
294
+ )}
295
+ </td>
296
+ </tr>
297
+ ))}
298
+ </tbody>
299
+ </Table>
300
+
301
+ <PermissionManagementModal
302
+ isOpen={isOpen}
303
+ onClose={onClose}
304
+ providerName="R"
305
+ providerKey={selectedRole?.id}
306
+ />
307
+ </>
308
+ );
309
+ }
310
+ ```
311
+
312
+ ## Customization
313
+
314
+ ### Custom Permission Display
315
+
316
+ Create your own permission display component:
317
+
318
+ ```tsx
319
+ import { usePermissionManagement } from '@abpjs/permission-management';
320
+ import { Checkbox, VStack, Heading } from '@chakra-ui/react';
321
+
322
+ function CustomPermissionList({ providerName, providerKey }) {
323
+ const { permissions, updatePermissions } = usePermissionManagement();
324
+
325
+ const handleChange = async (permissionName, isGranted) => {
326
+ await updatePermissions({
327
+ providerName,
328
+ providerKey,
329
+ permissions: [{ name: permissionName, isGranted }],
330
+ });
331
+ };
332
+
333
+ return (
334
+ <VStack align="stretch" spacing={4}>
335
+ {permissions?.groups.map(group => (
336
+ <div key={group.name}>
337
+ <Heading size="sm">{group.displayName}</Heading>
338
+ {group.permissions.map(permission => (
339
+ <Checkbox
340
+ key={permission.name}
341
+ isChecked={permission.isGranted}
342
+ onChange={(e) => handleChange(permission.name, e.target.checked)}
343
+ >
344
+ {permission.displayName}
345
+ </Checkbox>
346
+ ))}
347
+ </div>
348
+ ))}
349
+ </VStack>
350
+ );
351
+ }
352
+ ```
353
+
354
+ ## Related Packages
355
+
356
+ - [@abpjs/core](https://www.npmjs.com/package/@abpjs/core) - Core infrastructure (required)
357
+ - [@abpjs/theme-shared](https://www.npmjs.com/package/@abpjs/theme-shared) - Shared UI components (required)
358
+ - [@abpjs/account](https://www.npmjs.com/package/@abpjs/account) - Account management
359
+ - [@abpjs/tenant-management](https://www.npmjs.com/package/@abpjs/tenant-management) - Tenant administration
360
+ - [@abpjs/theme-basic](https://www.npmjs.com/package/@abpjs/theme-basic) - Layout components
361
+
362
+ ## Contributing
363
+
364
+ This package is part of the [ABP React](https://github.com/abpjs/abp-react) monorepo. Contributions are welcome!
365
+
366
+ ## License
367
+
368
+ LGPL-3.0 - See [LICENSE](https://github.com/abpjs/abp-react/blob/main/LICENSE) for details.
369
+
370
+ ---
371
+
372
+ **[View Full Documentation](https://docs.abpjs.io/docs/packages/permission-management/overview)** | **[Report Issues](https://github.com/abpjs/abp-react/issues)** | **[View Source](https://github.com/abpjs/abp-react/tree/main/packages/permission-management)**