Skip to content

Commit 60041bc

Browse files
committed
🤖 Update LLMs files [skip ci]
1 parent c9ee1af commit 60041bc

File tree

1 file changed

+73
-81
lines changed

1 file changed

+73
-81
lines changed

‎docusaurus/static/llms-full.txt‎

Lines changed: 73 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -10326,111 +10326,103 @@ Source: https://docs.strapi.io/cms/plugins-development/guides/admin-permissions-
1032610326

1032710327
# How to create admin permissions from plugins
1032810328

10329-
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.
1033010330

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.
1033210332

1033310333
## Register the permissions server side
1033410334

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:
10342+
10343+
```js title="/src/plugins/my-plugin/admin/src/permissions.js|ts"
10344+
const pluginPermissions = {
10345+
'accessOverview': [{ action: 'plugin::my-plugin.overview.access', subject: null }],
10346+
'accessSidebar': [{ action: 'plugin::my-plugin.sidebar.access', subject: null }],
10347+
};
1036310348

10364-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
10365-
(strapi.admin.services.permission.actionProvider.registerMany as (a: any) => void)(actions);
1036610349
```
1036710350

10368-
## Creating components
10351+
### Page permissions
1036910352

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:
1037110354

10372-
### Using the Content-Type Builder
10355+
```js title="/src/plugins/my-plugin/admin/src/pages/HomePage.jsx|tsx" {2,5,12,16}
1037310356

10374-
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();
1037610359

10377-
### Creating components manually
10360+
return (
10361+
10362+
</Page.Protect>
10363+
);
10364+
};
1037810365

10379-
If you prefer to create components manually, you'll need to:
10366+
```
1038010367

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.
1038310369

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
1038510371

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:
1038710373

10388-
## Reviewing the component structure
10374+
```js title="/src/plugins/my-plugin/admin/src/index.js|ts" {21-23,5}
1038910375

10390-
Components in Strapi follow the following format in their definition:
10376+
register(app) {
10377+
app.addMenuLink({
10378+
to: `plugins/${PluginIcon}`,
10379+
icon: PluginIcon,
10380+
intlLabel: {
10381+
id: `${PLUGIN_ID}.plugin.name`,
10382+
defaultMessage: PLUGIN_ID,
10383+
},
10384+
Component: async () => {
10385+
const { App } = await import('./pages/App');
10386+
10387+
return App;
10388+
},
10389+
permissions: [
10390+
pluginPermissions.accessOverview[0],
10391+
],
10392+
});
10393+
10394+
app.registerPlugin({
10395+
id: PLUGIN_ID,
10396+
initializer: Initializer,
10397+
isReady: false,
10398+
name: PLUGIN_ID,
10399+
});
10400+
},
10401+
};
1039110402

10392-
```javascript title="/my-plugin/server/components/category/component-name.json"
10393-
{
10394-
"attributes": {
10395-
"myComponent": {
10396-
"type": "component",
10397-
"repeatable": true,
10398-
"component": "category.componentName"
10399-
}
10400-
}
10401-
}
1040210403
```
1040310404

10404-
## Making components visible in the admin panel
10405+
### Custom permissions with the `useRBAC` hook
1040510406

10406-
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:
1040710408

10408-
```javascript {9-16}
10409-
{
10410-
"kind": "collectionType",
10411-
"collectionName": "my_plugin_components",
10412-
"info": {
10413-
"singularName": "my-plugin-component",
10414-
"pluralName": "my-plugin-components",
10415-
"displayName": "My Plugin Component"
10416-
},
10417-
"pluginOptions": {
10418-
"content-manager": {
10419-
"visible": true
10420-
},
10421-
"content-type-builder": {
10422-
"visible": true
10423-
}
10424-
},
10425-
"attributes": {
10426-
"name": {
10427-
"type": "string"
10428-
}
10409+
```js title="/src/plugins/my-plugin/admin/src/components/Sidebar.jsx|tsx"
10410+
10411+
const Sidebar = () => {
10412+
const {
10413+
allowedActions: { canAccessSidebar },
10414+
} = useRBAC(pluginPermissions);
10415+
10416+
if (!canAccessSidebar) {
10417+
return null;
1042910418
}
10430-
}
10431-
```
1043210419

10433-
This configuration ensures your components will be visible and editable in both the Content-Type Builder and Content Manager.
10420+
return (
10421+
<div>Sidebar component</div>
10422+
);
10423+
};
10424+
10425+
```
1043410426

1043510427

1043610428

0 commit comments

Comments
 (0)