feat: Managed access for the settings page (RBAC)
parent
ab8b6699d8
commit
ad68519ac2
|
@ -7,17 +7,21 @@
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Provider } from 'react-redux';
|
import { Provider } from 'react-redux';
|
||||||
import Header from '../../components/Header';
|
import { CheckPagePermissions } from '@strapi/helper-plugin';
|
||||||
|
|
||||||
|
import pluginPermissions from '../../permissions';
|
||||||
|
import Header from '../../components/Header';
|
||||||
import { store } from "../../helpers/configureStore";
|
import { store } from "../../helpers/configureStore";
|
||||||
import ConfigPage from '../ConfigPage';
|
import ConfigPage from '../ConfigPage';
|
||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
return (
|
return (
|
||||||
<Provider store={store}>
|
<CheckPagePermissions permissions={pluginPermissions.settings}>
|
||||||
<Header />
|
<Provider store={store}>
|
||||||
<ConfigPage />
|
<Header />
|
||||||
</Provider>
|
<ConfigPage />
|
||||||
|
</Provider>
|
||||||
|
</CheckPagePermissions>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { prefixPluginTranslations } from '@strapi/helper-plugin';
|
||||||
import pluginPkg from '../../package.json';
|
import pluginPkg from '../../package.json';
|
||||||
import pluginId from './helpers/pluginId';
|
import pluginId from './helpers/pluginId';
|
||||||
import pluginIcon from './components/PluginIcon';
|
import pluginIcon from './components/PluginIcon';
|
||||||
// import pluginPermissions from './permissions';
|
import pluginPermissions from './permissions';
|
||||||
// import getTrad from './helpers/getTrad';
|
// import getTrad from './helpers/getTrad';
|
||||||
|
|
||||||
const pluginDescription = pluginPkg.strapi.description || pluginPkg.description;
|
const pluginDescription = pluginPkg.strapi.description || pluginPkg.description;
|
||||||
|
@ -32,7 +32,7 @@ export default {
|
||||||
|
|
||||||
return component;
|
return component;
|
||||||
},
|
},
|
||||||
permissions: [], // TODO: Add permission to view settings page.
|
permissions: pluginPermissions['menu-item'],
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
bootstrap(app) {},
|
bootstrap(app) {},
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
const pluginPermissions = {
|
||||||
|
// This permission regards the main component (App) and is used to tell
|
||||||
|
// If the plugin link should be displayed in the menu
|
||||||
|
// And also if the plugin is accessible. This use case is found when a user types the url of the
|
||||||
|
// plugin directly in the browser
|
||||||
|
'menu-item': [{ action: 'plugin::config-sync.menu-item', subject: null }],
|
||||||
|
settings: [{ action: 'plugin::config-sync.settings.read', subject: null }],
|
||||||
|
};
|
||||||
|
|
||||||
|
export default pluginPermissions;
|
|
@ -13,9 +13,27 @@ const fs = require('fs');
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = async () => {
|
module.exports = async () => {
|
||||||
|
// Import on bootstrap.
|
||||||
if (strapi.plugins['config-sync'].config.importOnBootstrap) {
|
if (strapi.plugins['config-sync'].config.importOnBootstrap) {
|
||||||
if (fs.existsSync(strapi.plugins['config-sync'].config.destination)) {
|
if (fs.existsSync(strapi.plugins['config-sync'].config.destination)) {
|
||||||
await strapi.plugins['config-sync'].services.main.importAllConfig();
|
await strapi.plugins['config-sync'].services.main.importAllConfig();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Register permission actions.
|
||||||
|
const actions = [
|
||||||
|
{
|
||||||
|
section: 'plugins',
|
||||||
|
displayName: 'Access the plugin settings',
|
||||||
|
uid: 'settings.read',
|
||||||
|
pluginName: 'config-sync',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
section: 'plugins',
|
||||||
|
displayName: 'Link to plugin settings from the main menu',
|
||||||
|
uid: 'menu-item',
|
||||||
|
pluginName: 'config-sync',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
await strapi.admin.services.permission.actionProvider.registerMany(actions);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue