Browse Source

docs: Improve docs on custom permission usage

Michael Bromley 2 years ago
parent
commit
63846f8a55

+ 1 - 1
docs/docs/guides/developer-guide/custom-permissions/index.md

@@ -81,7 +81,7 @@ For example, let's imagine we are creating a plugin which adds a new entity call
 ```ts title="src/plugins/product-review/constants.ts"
 ```ts title="src/plugins/product-review/constants.ts"
 import { CrudPermissionDefinition } from '@vendure/core';
 import { CrudPermissionDefinition } from '@vendure/core';
 
 
-export const productReview = new CrudPermissionDefinition(ProductReview);
+export const productReview = new CrudPermissionDefinition('ProductReview');
 ```
 ```
 
 
 These permissions can then be used in our resolver:
 These permissions can then be used in our resolver:

+ 27 - 1
packages/admin-ui/src/lib/core/src/providers/nav-builder/nav-builder-types.ts

@@ -62,7 +62,18 @@ export interface NavMenuSection {
     displayMode?: 'regular' | 'settings';
     displayMode?: 'regular' | 'settings';
     /**
     /**
      * @description
      * @description
-     * Control the display of this item based on the user permissions.
+     * Control the display of this item based on the user permissions. Note: if you attempt to pass a
+     * {@link PermissionDefinition} object, you will get a compilation error. Instead, pass the plain
+     * string version. For example, if the permission is defined as:
+     * ```ts
+     * export const MyPermission = new PermissionDefinition('ProductReview');
+     * ```
+     * then the generated permission strings will be:
+     *
+     * - `CreateProductReview`
+     * - `ReadProductReview`
+     * - `UpdateProductReview`
+     * - `DeleteProductReview`
      */
      */
     requiresPermission?: string | ((userPermissions: string[]) => boolean);
     requiresPermission?: string | ((userPermissions: string[]) => boolean);
     collapsible?: boolean;
     collapsible?: boolean;
@@ -116,6 +127,21 @@ export interface ActionBarItem {
     buttonColor?: 'primary' | 'success' | 'warning';
     buttonColor?: 'primary' | 'success' | 'warning';
     buttonStyle?: 'solid' | 'outline' | 'link';
     buttonStyle?: 'solid' | 'outline' | 'link';
     icon?: string;
     icon?: string;
+    /**
+     * @description
+     * Control the display of this item based on the user permissions. Note: if you attempt to pass a
+     * {@link PermissionDefinition} object, you will get a compilation error. Instead, pass the plain
+     * string version. For example, if the permission is defined as:
+     * ```ts
+     * export const MyPermission = new PermissionDefinition('ProductReview');
+     * ```
+     * then the generated permission strings will be:
+     *
+     * - `CreateProductReview`
+     * - `ReadProductReview`
+     * - `UpdateProductReview`
+     * - `DeleteProductReview`
+     */
     requiresPermission?: string | string[];
     requiresPermission?: string | string[];
 }
 }