Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(rbac frontend) Protected routes and menu #82

Merged
merged 15 commits into from
Jan 28, 2025
Merged
Prev Previous commit
Next Next commit
replaced localization
GailMelanie committed Jan 24, 2025
commit 4561b1f6a5734d33a3ef58e65b2c683b3e483c56
8 changes: 4 additions & 4 deletions src/layout/menu/BottomMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { MenuListItem, MenuListItemProps } from 'layout/menu/MenuListItem';
import { FormattedMessage } from 'react-intl';
import { messages } from 'lib/i18n/localization';
import { AccountCircle, AdminPanelSettings, Login, Logout } from '@mui/icons-material';
import { Box, Divider, List, styled } from '@mui/material';
import { MenuHeading } from 'layout/menu/MenuHeading';
import { useAuth } from 'lib/hooks/UseAuth';
import { useTranslations } from 'next-intl';

const StyledDivider = styled(Divider)(({ theme }) => ({
borderColor: theme.palette.common.white,
opacity: 0.3,
}));
export default function BottomMenu(props: { isLoggedIn: boolean; name: string; isAdmin: boolean }) {
const auth = useAuth();
const t = useTranslations('mainMenu');

const guestBottomMenu: MenuListItemProps[] = [
{
label: <FormattedMessage {...messages.mnestix.login} />,
label: t('login'),
icon: <Login />,
onClick: () => auth.login(),
},
];

const loggedInBottomMenu: MenuListItemProps[] = [
{
label: <FormattedMessage {...messages.mnestix.logout} />,
label: t('logout'),
icon: <Logout />,
onClick: () => auth.logout(),
},
20 changes: 8 additions & 12 deletions src/layout/menu/MainMenu.tsx
Original file line number Diff line number Diff line change
@@ -3,8 +3,6 @@ import { alpha, Box, Divider, Drawer, IconButton, List, styled, Typography } fro
import { Dashboard, OpenInNew, Settings } from '@mui/icons-material';
import React, { useState } from 'react';
import { useAuth } from 'lib/hooks/UseAuth';
import { FormattedMessage } from 'react-intl';
import { messages } from 'lib/i18n/localization';
import { TemplateIcon } from 'components/custom-icons/TemplateIcon';
import { MenuHeading } from './MenuHeading';
import { MenuListItem, MenuListItemProps } from './MenuListItem';
@@ -13,6 +11,7 @@ import packageJson from '../../../package.json';
import { useEnv } from 'app/env/provider';
import Roles from 'components/authentication/Roles';
import BottomMenu from 'layout/menu/BottomMenu';
import { useTranslations } from 'next-intl';

const StyledDrawer = styled(Drawer)(({ theme }) => ({
'.MuiDrawer-paper': {
@@ -63,6 +62,7 @@ export default function MainMenu() {
const versionString = 'Version ' + packageJson.version;
const isAdmin = !!auth.getAccount()?.user.isAdmin;
const allowedRoutes = isAdmin ? Roles.mnestixAdmin : Roles.mnestixUser;
const t = useTranslations('mainMenu');

const getAuthName = () => {
const user = auth?.getAccount()?.user;
@@ -88,15 +88,15 @@ export default function MainMenu() {

const basicMenu: MenuListItemProps[] = [
{
label: <FormattedMessage {...messages.mnestix.dashboard} />,
label: t('dashboard'),
to: '/',
icon: <Dashboard />,
},
];

if (env.AAS_LIST_FEATURE_FLAG) {
const listItemToAdd = {
label: <FormattedMessage {...messages.mnestix.list} />,
label: t('aasList'),
to: '/list',
icon: <ListIcon />,
};
@@ -105,7 +105,7 @@ export default function MainMenu() {

if (env.MNESTIX_BACKEND_API_URL && checkIfRouteIsAllowed('/templates')) {
const templateItemToAdd = {
label: <FormattedMessage {...messages.mnestix.templates} />,
label: t('templates'),
to: '/templates',
icon: <TemplateIcon />,
};
@@ -114,7 +114,7 @@ export default function MainMenu() {

if (checkIfRouteIsAllowed('/settings')) {
const settingsMenu = {
label: <FormattedMessage {...messages.mnestix.settings} />,
label: t('settings'),
to: '/settings',
icon: <Settings />,
};
@@ -144,9 +144,7 @@ export default function MainMenu() {
<StyledDrawer anchor="left" open={drawerOpen} onClose={handleMenuInteraction(false)}>
<Box onClick={handleMenuInteraction(false)} onKeyDown={handleMenuInteraction(false)}>
<List>
<MenuHeading>
<FormattedMessage {...messages.mnestix.repository} />
</MenuHeading>
<MenuHeading>{t('repository')}</MenuHeading>
<>
{basicMenu.map((props, i) => (
<MenuListItem {...props} key={'adminMainMenu' + i} />
@@ -155,9 +153,7 @@ export default function MainMenu() {
{useAuthentication && auth.isLoggedIn && (
<>
<StyledDivider />
<MenuHeading>
<FormattedMessage {...messages.mnestix.findOutMore} />
</MenuHeading>
<MenuHeading>{t('findOutMore')}</MenuHeading>
{guestMoreMenu.map((props, i) => (
<MenuListItem {...props} key={'guestMoreMenu' + i} />
))}
17 changes: 0 additions & 17 deletions src/lib/i18n/de.mnestix.ts
Original file line number Diff line number Diff line change
@@ -145,8 +145,6 @@ export const deMnestix = {
noDataFoundFor: 'Es wurden keine Daten für "{name}" gefunden.',
toHome: 'Zur Startseite',
authenticationNeeded: 'Authentifizierung erforderlich',
login: 'Anmelden',
logout: 'Abmelden',
templateDeletedSuccessfully: 'Vorlage erfolgreich gelöscht.',
defaultValue: 'Vorgegebener Wert',
add: 'Hinzufügen',
@@ -155,11 +153,6 @@ export const deMnestix = {
revertChanges: 'Änderungen zurücksetzen',
restore: 'Wiederherstellen',
changesSavedSuccessfully: 'Änderungen erfolgreich gespeichert.',
findOutMore: 'Mehr Informationen',
dashboard: 'Dashboard',
repository: 'Repository',
home: 'Startseite',
list: 'AAS Liste',
mnestix: 'Mnestix',
displayName: 'Anzeigename',
view: 'Ansehen',
@@ -222,16 +215,6 @@ export const deMnestix = {
partiallyFailedToast: 'Teil des Transfers fehlgeschlagen',
warningToast: 'Transfer der AAS nur teilweise erfolgreich.',
},
themeSettings: {
heading: 'Theme',
description: 'Definieren Sie das Theme von Mnestix.',
primaryColorLabel: 'Primärfarbe',
secondaryColorLabel: 'Sekundärfarbe',
logo: 'Logo',
submitButton: 'Theme speichern',
resetButton: 'Zurücksetzen',
logoHelperText: 'base64 encoded',
},
discoveryList: {
titleViewAASButton: 'VWS anzeigen',
picture: 'Bild',
17 changes: 0 additions & 17 deletions src/lib/i18n/en.mnestix.ts
Original file line number Diff line number Diff line change
@@ -142,8 +142,6 @@ export const enMnestix = {
noDataFoundFor: 'No data found for "{name}".',
toHome: 'To Home',
authenticationNeeded: 'Authentication needed',
login: 'Login',
logout: 'Logout',
templateDeletedSuccessfully: 'Template deleted successfully.',
defaultValue: 'Default value',
add: 'Add',
@@ -152,11 +150,6 @@ export const enMnestix = {
revertChanges: 'Revert changes',
restore: 'Restore',
changesSavedSuccessfully: 'Changes saved successfully.',
findOutMore: 'Find out more',
dashboard: 'Dashboard',
repository: 'Repository',
home: 'Home',
list: 'AAS list',
mnestix: 'Mnestix',
displayName: 'Display name',
view: 'View',
@@ -218,16 +211,6 @@ export const enMnestix = {
partiallyFailedToast: 'Failed to transfer element',
warningToast: 'AAS was only partially transferred.',
},
themeSettings: {
heading: 'Theme',
description: 'Define the theme of Mnestix.',
primaryColorLabel: 'Primary color',
secondaryColorLabel: 'Secondary color',
logo: 'Logo',
submitButton: 'Submit Theme',
resetButton: 'Reset to default',
logoHelperText: 'base64 encoded',
},
discoveryList: {
titleViewAASButton: 'View AAS',
picture: 'Picture',
10 changes: 10 additions & 0 deletions src/locale/de.json
Original file line number Diff line number Diff line change
@@ -62,5 +62,15 @@
"authentication": {
"authentication-needed": "Authentifizierung erforderlich",
"contactAdmin": "You cannot visit this page. Please contact your administrator."
},
"mainMenu": {
"dashboard": "Dashboard",
"aasList": "AAS Liste",
"templates": "Vorlagen",
"settings": "Einstellungen",
"repository": "Repository",
"findOutMore": "Mehr Informationen",
"login": "Anmelden",
"logout": "Abmelden"
}
}
10 changes: 10 additions & 0 deletions src/locale/en.json
Original file line number Diff line number Diff line change
@@ -62,5 +62,15 @@
"authentication": {
"authentication-needed": "Authentication needed",
"contactAdmin": "You cannot visit this page. Please contact your administrator."
},
"mainMenu": {
"dashboard": "Dashboard",
"aasList": "AAS List",
"templates": "Templates",
"settings": "Settings",
"repository": "Repository",
"findOutMore": "Find out more",
"login": "Login",
"logout": "Logout"
}
}