Skip to content

Commit

Permalink
Ability to display a page depending on role permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
yarkovaleksei committed Jan 21, 2024
1 parent e0468d2 commit 3932680
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
## <a id="features"></a>✨ Features
* Adds a page where you can view all the environment variables that are available on the system.
* Any variable and its value can be copied by pressing one button.
* Ability to display a page depending on role permissions.

## <a id="installation"></a>💎 Installation
```bash
Expand Down
7 changes: 4 additions & 3 deletions admin/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { prefixPluginTranslations } from '@strapi/helper-plugin';
import pluginPkg from '../../package.json';
import { getTrad } from './utils';
import pluginPermissions from './permissions';
import pluginId from './pluginId';
import {
Initializer,
Expand All @@ -25,11 +26,11 @@ export default {
defaultMessage: name,
},
Component: async () => {
const component = await import(/* webpackChunkName: "environment-variables" */ './pages/App');
const component = await import(/* webpackChunkName: "environment-variables-page" */ './pages/App');

return component;
},
permissions: [],
permissions: pluginPermissions.settings,
});

const plugin = {
Expand All @@ -49,7 +50,7 @@ export default {
}) {
const importedTrads = await Promise.all(
(locales as string[]).map((locale) => {
return import(`./translations/${locale}.json`)
return import(/* webpackChunkName: "environment-variables-translations-[request]" */ `./translations/${locale}.json`)
.then(({ default: data }) => {
return {
data: prefixPluginTranslations(data, pluginId),
Expand Down
10 changes: 10 additions & 0 deletions admin/src/permissions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const pluginPermissions = {
settings: [
{
action: 'plugin::environment-variables.settings.read',
subject: null,
},
],
};

export default pluginPermissions;
15 changes: 15 additions & 0 deletions dist/server/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const permissions_actions_1 = __importDefault(require("./permissions-actions"));
async function bootstrap({ strapi }) {
await strapi
.admin
.services
.permission
.actionProvider
.registerMany(permissions_actions_1.default.actions);
}
exports.default = bootstrap;
2 changes: 2 additions & 0 deletions dist/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const bootstrap_1 = __importDefault(require("./bootstrap"));
const controllers_1 = __importDefault(require("./controllers"));
const routes_1 = __importDefault(require("./routes"));
const services_1 = __importDefault(require("./services"));
exports.default = {
bootstrap: bootstrap_1.default,
controllers: controllers_1.default,
routes: routes_1.default,
services: services_1.default,
Expand Down
14 changes: 14 additions & 0 deletions dist/server/permissions-actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const permissionsActions = {
actions: [
{
section: 'plugins',
displayName: 'Read environment variables',
uid: 'settings.read',
subCategory: 'read',
pluginName: 'environment-variables',
},
],
};
exports.default = permissionsActions;
8 changes: 8 additions & 0 deletions dist/server/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ exports.default = [
config: {
policies: [
'admin::isAuthenticatedAdmin',
{
name: 'admin::hasPermissions',
config: {
actions: [
'plugin::environment-variables.settings.read',
],
},
},
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion dist/tsconfig.server.tsbuildinfo

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "strapi-plugin-environment-variables",
"version": "1.0.0",
"version": "1.1.0",
"license": "MIT",
"description": "Plugin for Strapi CMS, which allows you to view and copy environment variables with which the backend is running",
"strapi": {
Expand Down
Binary file added public/permissions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions server/bootstrap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Strapi } from '@strapi/strapi';
import permissionsActions from './permissions-actions';

export default async function bootstrap({ strapi }: { strapi: Strapi }) {
await strapi
.admin
.services
.permission
.actionProvider
.registerMany(
permissionsActions.actions,
);
}
2 changes: 2 additions & 0 deletions server/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import bootstrap from './bootstrap';
import controllers from './controllers';
import routes from './routes';
import services from './services';

export default {
bootstrap,
controllers,
routes,
services,
Expand Down
13 changes: 13 additions & 0 deletions server/permissions-actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const permissionsActions = {
actions: [
{
section: 'plugins',
displayName: 'Read environment variables',
uid: 'settings.read',
subCategory: 'read',
pluginName: 'environment-variables',
},
],
};

export default permissionsActions;
8 changes: 8 additions & 0 deletions server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ export default [
config: {
policies: [
'admin::isAuthenticatedAdmin',
{
name: 'admin::hasPermissions',
config: {
actions: [
'plugin::environment-variables.settings.read',
],
},
},
],
},
},
Expand Down

0 comments on commit 3932680

Please sign in to comment.