You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When [developing a Strapi plugin](/cms/plugins-development/developing-plugins), you might want to create reusable components for your plugin. Components in Strapi are reusable data structures that can be used across different content-types.
10329
+
When [developing a Strapi plugin](/cms/plugins-development/developing-plugins), you might want to create admin permissions for your plugin. By doing that you can hook in to the [RBAC system](/cms/features/rbac) of Strapi to selectively grant permissions to certain pieces of your plugin.
10330
10330
10331
-
To create components for your Strapi plugin, you'll need to follow a similar approach to creating content-types, but with some specific differences.
10331
+
To create admin permissions for your Strapi plugin, you'll need to register them on the server side before implementing them on the admin side.
10332
10332
10333
10333
## Register the permissions server side
10334
10334
10335
-
```
10336
-
// Register permission actions.
10337
-
const actions = [
10338
-
{
10339
-
section: 'plugins',
10340
-
displayName: 'Access the overview page',
10341
-
uid: 'settings.overview',
10342
-
pluginName: 'webtools',
10343
-
},
10344
-
{
10345
-
section: 'plugins',
10346
-
displayName: 'Access the URL alias list',
10347
-
uid: 'settings.list',
10348
-
pluginName: 'webtools',
10349
-
},
10350
-
{
10351
-
section: 'plugins',
10352
-
displayName: 'Access the URL alias patterns',
10353
-
uid: 'settings.patterns',
10354
-
pluginName: 'webtools',
10355
-
},
10356
-
{
10357
-
section: 'plugins',
10358
-
displayName: 'Access the URL alias sidebar',
10359
-
uid: 'edit-view.sidebar',
10360
-
pluginName: 'webtools',
10361
-
},
10362
-
];
10335
+
Each individual permission has to registered in the bootstrap function of your plugin, as follows:
10336
+
10337
+
</Tabs>
10338
+
10339
+
## Implement permissions on the admin panel side
10340
+
10341
+
Before we can implement our permissions on the admin panel side we have to define them in a reusable configuration file. This file can be stored anywhere in your plugin admin code. You can do that as follows:
(strapi.admin.services.permission.actionProvider.registerMany as (a: any) => void)(actions);
10366
10349
```
10367
10350
10368
-
## Creating components
10351
+
### Page permissions
10369
10352
10370
-
You can create components for your plugins in 2 different ways: using the Content-Type Builder (recommended way) or manually.
10353
+
Once you've created the configuration file you are ready to implement your permissions. If you've bootstrapped your plugin using the [plugin SDK init command](/cms/plugins-development/plugin-sdk#npx-strapisdk-plugin-init), you will have an example `HomePage.tsx` file. To implement page permissions you can do the following:
The recommended way to create components for your plugin is through the Content-Type Builder in the admin panel.
10375
-
The [Content-Type Builder documentation](/cms/features/content-type-builder#new-component) provides more details on this process.
10357
+
const HomePage = () => {
10358
+
const { formatMessage } = useIntl();
10376
10359
10377
-
### Creating components manually
10360
+
return (
10361
+
10362
+
</Page.Protect>
10363
+
);
10364
+
};
10378
10365
10379
-
If you prefer to create components manually, you'll need to:
10366
+
```
10380
10367
10381
-
1. Create a component schema in your plugin's structure.
10382
-
2. Make sure the component is properly registered.
10368
+
You can see how we use our permissions configuration file together with the `<Page.Protect>` component to require specific permissions in order to view this page.
10383
10369
10384
-
Components for plugins should be placed in the appropriate directory within your plugin structure. You would typically create them within the server part of your plugin (see [plugin structure documentation](/cms/plugins-development/plugin-structure)).
10370
+
### Menu link permissions
10385
10371
10386
-
For more detailed information about components in Strapi, you can refer to the [Model attributes documentation](/cms/backend-customization/models#components-json).
10372
+
The previous example makes sure that the permissions of a user that visits your page directly will be validated. However, you might want to remove the menu link to that page as well. To do that, you'll have to make a change to the `addMenuLink` implementation. You can do as follows:
To ensure your plugin's components are visible in the admin panel, you need to set the appropriate `pluginOptions` in your component schema:
10407
+
To get even more control over the permission of the admin user you can use the `useRBAC` hook. With this hook you can use the permissions validation just like you want, as in the following example:
0 commit comments