Skip to content

Commit

Permalink
fix: no access page provided
Browse files Browse the repository at this point in the history
  • Loading branch information
cyp3rius committed Apr 5, 2023
1 parent 03e2350 commit ad72da9
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 1 deletion.
55 changes: 55 additions & 0 deletions admin/src/pages/NoAccessPage/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* NoAcccessPage
*
* This is the page we show when the user do not have appropriate credentials
*
*/

// TODO
// @ts-nocheck

import React from 'react';
import { useFocusWhenNavigate, LinkButton } from '@strapi/helper-plugin';
import { Main } from '@strapi/design-system/Main';
import { ContentLayout, HeaderLayout } from '@strapi/design-system/Layout';
import { EmptyStateLayout } from '@strapi/design-system/EmptyStateLayout';
import { EmptyPictures, ArrowRight } from "@strapi/icons";
import { useIntl } from 'react-intl';

const NoAcccessPage = () => {
const { formatMessage } = useIntl();
useFocusWhenNavigate();

return (
<Main labelledBy="title">
<HeaderLayout
id="title"
title={formatMessage({
id: 'page.auth.noAccess',
defaultMessage: 'No access',
})}
/>
<ContentLayout>
<EmptyStateLayout
action={
<LinkButton variant="secondary" endIcon={<ArrowRight />} to="/">
{formatMessage({
id: 'components.notAccessPage.back',
defaultMessage: 'Back to homepage',
})}
</LinkButton>
}
content={formatMessage({
id: 'page.auth.not.allowed',
defaultMessage: "Oops! It seems like You do not have access to this page...",
})}
hasRadius
icon={<EmptyPictures width="10rem" />}
shadow="tableShadow"
/>
</ContentLayout>
</Main>
);
};

export default NoAcccessPage;
21 changes: 21 additions & 0 deletions admin/src/pages/SettingsPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
useOverlayBlocker,
useAutoReloadOverlayBlocker,
SettingsPageTitle,
useRBAC,
//@ts-ignore
} from '@strapi/helper-plugin';
//@ts-ignore
Expand Down Expand Up @@ -53,6 +54,8 @@ import { NavigationItemAdditionalField, NavigationItemCustomField } from '../../
import CustomFieldModal from './components/CustomFieldModal';
import CustomFieldTable from './components/CustomFieldTable';
import { HandleSetContentTypeExpanded, OnPopupClose, OnSave, PreparePayload, RawPayload, RestartReasons, RestartStatus, StrapiContentTypeSchema } from './types';
import pluginPermissions from '../../permissions';
import NoAcccessPage from '../NoAccessPage';

const RESTART_NOT_REQUIRED: RestartStatus = { required: false }
const RESTART_REQUIRED: RestartStatus = { required: true, reasons: [] }
Expand All @@ -77,6 +80,20 @@ const SettingsPage = () => {
const [contentTypeExpanded, setContentTypeExpanded] = useState<string | undefined>(undefined);
const { data: navigationConfigData, isLoading: isConfigLoading, error: configErr, submitMutation, restoreMutation, restartMutation } = useNavigationConfig();
const { data: allContentTypesData, isLoading: isContentTypesLoading, error: contentTypesErr } = useAllContentTypes();

const viewPermissions = useMemo(
() => ({
settings: pluginPermissions.settings
}),
[],
);

const {
isLoading: isLoadingForPermissions,
allowedActions: {
canManageSettings,
},
} = useRBAC(viewPermissions);

const isLoading = isConfigLoading || isContentTypesLoading;
const isError = configErr || contentTypesErr;
Expand Down Expand Up @@ -238,6 +255,10 @@ const SettingsPage = () => {
setCustomFields([...filteredFields, updatedField]);
}

if (!(isLoadingForPermissions || canManageSettings)) {
return (<NoAcccessPage />)
}

return (
<>
<SettingsPageTitle
Expand Down
7 changes: 6 additions & 1 deletion admin/src/pages/View/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
usedContentTypes,
validateNavigationStructure,
} from './utils/parsers';
import NoAcccessPage from '../NoAccessPage';

const View = () => {
const toggleNotification = useNotification();
Expand Down Expand Up @@ -287,6 +288,10 @@ const View = () => {
});
}

if (!canAccess && !isLoadingForPermissions) {
return (<NoAcccessPage />);
}

return (
<Main labelledBy="title" aria-busy={isLoadingForSubmit}>
<NavigationHeader
Expand All @@ -303,7 +308,7 @@ const View = () => {
}}
/>
<ContentLayout>
{isLoading && <LoadingIndicatorPage />}
{(isLoading || isLoadingForPermissions) && <LoadingIndicatorPage />}
{changedActiveNavigation && (
<>
<NavigationContentHeader
Expand Down
3 changes: 3 additions & 0 deletions admin/src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
"notification.error": "Error while processing request.",
"notification.error.customField.type": "Unsupported type of custom field",
"notification.error.item.relation": "Relations provided in some items are incorrect",
"page.auth.noAccess": "No access",
"page.auth.not.allowed": "Oops! It seems like You do not have access to this page...",
"pages.main.search.placeholder": "Type to start searching...",
"pages.main.header.localization.select.placeholder": "Select locale",
"pages.settings.general.title": "General settings",
Expand Down Expand Up @@ -197,6 +199,7 @@
"components.confirmation.dialog.button.confirm": "Confirm",
"components.confirmation.dialog.description": "Do you want to continue?",
"components.confirmation.dialog.header": "Confirmation",
"components.notAccessPage.back": "Back to homepage",
"view.i18n.fill.cta": "or bootstrap",
"view.i18n.fill.option": "{locale} locale",
"view.i18n.fill.cta.button": "copy"
Expand Down

0 comments on commit ad72da9

Please sign in to comment.