Skip to content

Commit

Permalink
Fixing permission denied on toast messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
everythinginjs committed Dec 20, 2022
1 parent 8866f33 commit c04472f
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 24 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
node_modules

# OS X files
DS_Store
DS_Store

# folders
.vscode
26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
---

<p align="center" width="100%">
<img alt="strapi plugin update static content logo" src="/public/logo/strapi-plugin-update-static-content.png"/>
<img alt="strapi plugin update static content logo" src="https://raw.githubusercontent.com/everythinginjs/strapi-plugin-update-static-content/main/public/logo/strapi-plugin-update-static-content.png"/>
</p>

## Plugin Previews

Plugin Settings

<p align="center" width="100%">
<img alt="strapi plugin update static content configuration" src="/public/previews/plugin-config.png"/>
<img alt="strapi plugin update static content configuration" src="https://raw.githubusercontent.com/everythinginjs/strapi-plugin-update-static-content/main/public/previews/plugin-config.png"/>
</p>

Plugin Page

<p align="center" width="100%">
<img alt="strapi plugin update static content plugin" src="/public/previews/plugin-page.png"/>
<img alt="strapi plugin update static content plugin" src="https://raw.githubusercontent.com/everythinginjs/strapi-plugin-update-static-content/main/public/previews/plugin-page.png"/>
</p>

---
Expand All @@ -41,7 +41,7 @@ Plugin Page

## Plugin Configuration

1. add plugin configs inside `strapiProject/config/plugins.js`
1. Add plugin configs inside `strapiProject/config/plugins.js`

```javascript
module.exports = ({ env }) => ({
Expand All @@ -59,25 +59,26 @@ module.exports = ({ env }) => ({
});
```

2. create a file in the root of you project `.github/workflows/deploy.yml` it should be something like below
2. Create a file in the root of your project `.github/workflows/deploy.yml` like below. In this example we are using fing cloud

```yml
name: Fing Deployment # a name for your workflow
on:
push: # triggers on push event to the repo

on: # trigger on push event and main branch to the repo
push:
branches: [main]
workflow_dispatch: # must be included in your .yml file for manually triggering event
defaults:
defaults: # in case of monorepo project you can use `defauls` and choose the subfolder
run:
working-directory: ./gatsbyJS # in case of monorepo project, choose the subfolder
working-directory: ./gatsbyJS
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: install fing-cli and deploy
env:
env: # set the cloud provider token to the secrets on github and use it on run
TOKEN: ${{ secrets.FING_TOKEN }}
run: | # write your shell scripts for deploying or building based on your host provider
npm install -g @fingcloud/cli
Expand All @@ -87,3 +88,8 @@ jobs:
## Roadmap
- Cancel workflow manually.
- Better documentation.
## Special Thanks
[Reza from Fing](https://github.com/r6m)
5 changes: 3 additions & 2 deletions admin/src/components/Guard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import pluginId from '../../../../utils/pluginId';

const ICON_SIZE = 100;
const PLUGIN = `${pluginId}.plugin`;

export default function Guard({ errors, children }) {
if (errors?.message === 'ACCESS_DENIED' && errors?.type === 'ROLES_AND_PERMISSIONS') {
const PERMITTED_ROLES = useFormattedLabel(`${pluginId}.permissionMsg`);
const PERMISSION_DENIED_MESSGAE = useFormattedLabel(`${pluginId}.guard`);

return (
<EmptyStateLayout
content={PERMITTED_ROLES}
content={PERMISSION_DENIED_MESSGAE}
icon={<EmptyPermissions width={ICON_SIZE} height={ICON_SIZE} />}
/>
);
Expand Down
17 changes: 16 additions & 1 deletion admin/src/pages/PluginPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default function PluginPage() {
const [loadingTriggerButton, setLoadingTriggerButton] = useState(false);
const [toastMsg, setToastMsg] = useState({});
const [toastToggle, setToastToggle] = useState(false);

const { errors, fetchedData, isLoading, setRefetch } = useFetchData({
url: `/${pluginId}/github-actions-history`,
method: 'GET',
Expand All @@ -59,6 +60,8 @@ export default function PluginPage() {
const TOAST_FAILURE_UNPROCESSABLE_DESCRIPTION = useFormattedLabel(
`${PLUGIN}.toast.failure.unprocessableEntity.description`
);
const TOAST_PERMISSION_DENIED_MSG = useFormattedLabel(`${pluginId}.permission.toast.message`);
const TOAST_PERMISSION_DENIED_TITLE = useFormattedLabel(`${pluginId}.permission.toast.title`);
const SEE_MORE_BUTTON = useFormattedLabel(`${pluginId}.button.seeMore`);
const REFRESH_BUTTON = useFormattedLabel(`${pluginId}.button.refresh`);
const Back_BUTTON = useFormattedLabel(`${pluginId}.button.back`);
Expand Down Expand Up @@ -88,7 +91,7 @@ export default function PluginPage() {
});
setToastToggle(true);
} catch (error) {
console.log(error);
console.error(error);
if (
error.response.data.error?.status === 422 &&
error.response.data.error?.name === 'UnprocessableEntityError'
Expand All @@ -106,6 +109,15 @@ export default function PluginPage() {
</Link>
),
});
} else if (
error.response.data.error?.status === 403 &&
error.response.data.error?.name === 'PolicyError'
) {
setToastMsg({
variant: 'danger',
title: TOAST_PERMISSION_DENIED_TITLE,
message: TOAST_PERMISSION_DENIED_MSG,
});
} else {
setToastMsg({
variant: 'danger',
Expand All @@ -119,6 +131,8 @@ export default function PluginPage() {
}
}

const isAccessDenied =
errors.message === 'ACCESS_DENIED' && errors.type === 'ROLES_AND_PERMISSIONS';
return (
<>
<PageWrapper
Expand All @@ -137,6 +151,7 @@ export default function PluginPage() {
onClick={triggerGithubActions}
variant="default"
size="L"
disabled={isAccessDenied ? true : false}
loading={loadingTriggerButton}
startIcon={<Plus />}
>
Expand Down
6 changes: 4 additions & 2 deletions admin/src/translations/en.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"update-static-content.plugin.name": "Update Static Content",
"update-static-content.settings.title": "Update Static Content",
"update-static-content.permissionMsg": "You do not have permission to access the page.",
"update-static-content.permission.guard": "You do not have permission to access the page.",
"update-static-content.permission.toast.title": "Access denied",
"update-static-content.permission.toast.message": "You do NOT have permission to do this action.",
"update-static-content.settings.pagetitle": "Update Static Content Configuration",
"update-static-content.settings.headers.title": "Configuration",
"update-static-content.settings.headers.subtitle": "Here you can see your Update Static Content Configuration",
Expand All @@ -17,7 +19,7 @@
"update-static-content.settings.fields.hint.githubtoken": "Enter your `Github Personal Access Token` if you do not have create one from here",
"update-static-content.settings.fields.hint.owner": "Enter your `Github Username (owner of the account)`",
"update-static-content.settings.fields.hint.repo": "Enter your `Github Repository`",
"update-static-content.settings.fields.hint.workflowid": "Enter your `workflowId` for more info check here",
"update-static-content.settings.fields.hint.workflowid": "Enter your `workflowId` or `filename`",
"update-static-content.settings.fields.hint.branch": "Enter the desired `branch`",
"update-static-content.settings.fields.hint.roles": "Roles that have access to the plugin",

Expand Down
43 changes: 35 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,53 @@
{
"name": "strapi-plugin-update-static-content",
"version": "0.0.0",
"description": "A plugin to rebuild your SSG website.",
"version": "1.0.4",
"description": "An strapi plugin to rebuild and deploy your SSG website via Github Actions.",
"strapi": {
"name": "update-static-content",
"description": "A plugin to rebuild your SSG website.",
"description": "An strapi plugin to rebuild and deploy your SSG website via Github Actions.",
"kind": "plugin",
"displayName": "Update Static Content"
},
"homepage": "https://github.com/everythinginjs/strapi-plugin-update-static-content#update-static-content---strapi-v4",
"bugs": {
"url": "https://github.com/everythinginjs/strapi-plugin-update-static-content/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/everythinginjs/strapi-plugin-update-static-content.git"
},
"author": {
"name": "Amir Mahmoudi<amixengineer>"
"name": "Amir Mahmoudi",
"email": "[email protected]"
},
"license": "MIT",
"maintainers": [
{
"name": "Amir Mahmoudi<amixengineer>"
"name": "Amir Mahmoudi",
"email": "[email protected]"
}
],
"engines": {
"node": ">=14.19.1 <=18.x.x",
"npm": ">=6.0.0"
},
"license": "MIT",
"devDependencies": {},
"dependencies": {}
"dependencies": {
"date-fns": "2.29.3",
"react-intl": "6.2.1"
},
"devDependencies": {
"@babel/eslint-parser": "7.19.1",
"@babel/preset-react": "7.18.6",
"eslint": "8.28.0",
"eslint-plugin-react": "7.31.11"
},
"peerDependencies": {
"@strapi/strapi": "^4.4.5"
},
"keywords": [
"strapi",
"strapi-plugin",
"github-actions",
"plugin"
]
}
Binary file modified public/logo/strapi-plugin-update-static-content.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c04472f

Please sign in to comment.