@abpjs/permission-management 3.0.0 → 3.1.0

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/dist/index.d.mts CHANGED
@@ -292,6 +292,17 @@ interface UsePermissionManagementReturn {
292
292
  * @deprecated Use isGrantedByOtherProviderName instead
293
293
  */
294
294
  isGrantedByRole: (grantedProviders: PermissionManagement.GrantedProvider[]) => boolean;
295
+ /**
296
+ * Determines whether the app configuration should be refreshed after saving permissions.
297
+ * Returns true if:
298
+ * - The provider is a role ('R') that the current user belongs to
299
+ * - The provider is the current user ('U')
300
+ * @param providerKey The provider key (role ID or user ID)
301
+ * @param providerName The provider name ('R' for role, 'U' for user)
302
+ * @returns Whether app config should be refreshed
303
+ * @since 3.1.0
304
+ */
305
+ shouldFetchAppConfig: (providerKey: string, providerName: string) => boolean;
295
306
  /** Reset state */
296
307
  reset: () => void;
297
308
  }
package/dist/index.d.ts CHANGED
@@ -292,6 +292,17 @@ interface UsePermissionManagementReturn {
292
292
  * @deprecated Use isGrantedByOtherProviderName instead
293
293
  */
294
294
  isGrantedByRole: (grantedProviders: PermissionManagement.GrantedProvider[]) => boolean;
295
+ /**
296
+ * Determines whether the app configuration should be refreshed after saving permissions.
297
+ * Returns true if:
298
+ * - The provider is a role ('R') that the current user belongs to
299
+ * - The provider is the current user ('U')
300
+ * @param providerKey The provider key (role ID or user ID)
301
+ * @param providerName The provider name ('R' for role, 'U' for user)
302
+ * @returns Whether app config should be refreshed
303
+ * @since 3.1.0
304
+ */
305
+ shouldFetchAppConfig: (providerKey: string, providerName: string) => boolean;
295
306
  /** Reset state */
296
307
  reset: () => void;
297
308
  }
package/dist/index.js CHANGED
@@ -178,6 +178,7 @@ function getPermissionsFromGroups(groups) {
178
178
  }
179
179
  function usePermissionManagement() {
180
180
  const restService = (0, import_core.useRestService)();
181
+ const currentUser = (0, import_core.useCurrentUserInfo)();
181
182
  const service = (0, import_react.useMemo)(() => new PermissionManagementService(restService), [restService]);
182
183
  const [groups, setGroups] = (0, import_react.useState)([]);
183
184
  const [entityDisplayName, setEntityDisplayName] = (0, import_react.useState)("");
@@ -366,6 +367,19 @@ function usePermissionManagement() {
366
367
  setSelectThisTab(false);
367
368
  setSelectAllTab(false);
368
369
  }, []);
370
+ const shouldFetchAppConfig = (0, import_react.useCallback)(
371
+ (providerKey, providerName) => {
372
+ if (!currentUser) return false;
373
+ if (providerName === "R") {
374
+ return currentUser.roles?.some((role) => role === providerKey) ?? false;
375
+ }
376
+ if (providerName === "U") {
377
+ return currentUser.id === providerKey;
378
+ }
379
+ return false;
380
+ },
381
+ [currentUser]
382
+ );
369
383
  return {
370
384
  groups,
371
385
  entityDisplayName,
@@ -386,6 +400,7 @@ function usePermissionManagement() {
386
400
  isGranted,
387
401
  isGrantedByOtherProviderName,
388
402
  isGrantedByRole,
403
+ shouldFetchAppConfig,
389
404
  reset
390
405
  };
391
406
  }
package/dist/index.mjs CHANGED
@@ -128,7 +128,7 @@ var PermissionManagementStateService = class {
128
128
 
129
129
  // src/hooks/usePermissionManagement.ts
130
130
  import { useState, useCallback, useMemo } from "react";
131
- import { useRestService } from "@abpjs/core";
131
+ import { useRestService, useCurrentUserInfo } from "@abpjs/core";
132
132
  function findMargin(permissions, permission) {
133
133
  const parentPermission = permissions.find((per) => per.name === permission.parentName);
134
134
  if (parentPermission && parentPermission.parentName) {
@@ -148,6 +148,7 @@ function getPermissionsFromGroups(groups) {
148
148
  }
149
149
  function usePermissionManagement() {
150
150
  const restService = useRestService();
151
+ const currentUser = useCurrentUserInfo();
151
152
  const service = useMemo(() => new PermissionManagementService(restService), [restService]);
152
153
  const [groups, setGroups] = useState([]);
153
154
  const [entityDisplayName, setEntityDisplayName] = useState("");
@@ -336,6 +337,19 @@ function usePermissionManagement() {
336
337
  setSelectThisTab(false);
337
338
  setSelectAllTab(false);
338
339
  }, []);
340
+ const shouldFetchAppConfig = useCallback(
341
+ (providerKey, providerName) => {
342
+ if (!currentUser) return false;
343
+ if (providerName === "R") {
344
+ return currentUser.roles?.some((role) => role === providerKey) ?? false;
345
+ }
346
+ if (providerName === "U") {
347
+ return currentUser.id === providerKey;
348
+ }
349
+ return false;
350
+ },
351
+ [currentUser]
352
+ );
339
353
  return {
340
354
  groups,
341
355
  entityDisplayName,
@@ -356,6 +370,7 @@ function usePermissionManagement() {
356
370
  isGranted,
357
371
  isGrantedByOtherProviderName,
358
372
  isGrantedByRole,
373
+ shouldFetchAppConfig,
359
374
  reset
360
375
  };
361
376
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abpjs/permission-management",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "ABP Framework permission-management components for React - translated from @abp/ng.permission-management",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -32,11 +32,11 @@
32
32
  "dependencies": {
33
33
  "@chakra-ui/react": "^3.2.0",
34
34
  "@emotion/react": "^11.11.0",
35
- "@abpjs/theme-shared": "3.0.0",
36
- "@abpjs/core": "3.0.0"
35
+ "@abpjs/core": "3.1.0",
36
+ "@abpjs/theme-shared": "3.1.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@abp/ng.permission-management": "3.0.0",
39
+ "@abp/ng.permission-management": "3.1.0",
40
40
  "@testing-library/jest-dom": "^6.4.0",
41
41
  "@testing-library/react": "^14.2.0",
42
42
  "@types/react": "^18.2.0",