Skip to content

Commit

Permalink
feat: allow only admin users to see registration instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
jorilindell committed May 21, 2024
1 parent 23085dd commit 62e2bdd
Show file tree
Hide file tree
Showing 14 changed files with 137 additions and 134 deletions.
8 changes: 0 additions & 8 deletions e2e/tests/help.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@ test.describe('Help page', () => {
.soft(page.getByRole('heading', { name: 'Sisällöntuotannon ohjeet' }))
.toBeVisible();

await page
.getByLabel('Lisätietoa palvelusta')
.getByRole('link', { name: 'Ilmoittautumisen ohjeet' })
.click();
await expect
.soft(page.getByRole('heading', { name: 'Ilmoittautumisen ohjeet' }))
.toBeVisible();

await page
.getByLabel('Lisätietoa palvelusta')
.getByRole('link', { name: 'UKK' })
Expand Down
6 changes: 3 additions & 3 deletions src/domain/admin/layout/AdminPageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ROUTES } from '../../../constants';
import { featureFlagUtils } from '../../../utils/featureFlags';
import LayoutWithSideNavigation from '../../app/layout/layoutWithSideNavigation/LayoutWithSideNavigation';
import useUser from '../../user/hooks/useUser';
import { arePriceGroupRoutesAllowed } from '../../user/permissions';
import { areFinancialRoutesAllowed } from '../../user/permissions';

const AdminPageLayout: React.FC<PropsWithChildren> = ({ children }) => {
const { t } = useTranslation();
Expand All @@ -22,13 +22,13 @@ const AdminPageLayout: React.FC<PropsWithChildren> = ({ children }) => {
{ label: t('keywordsPage.title'), to: ROUTES.KEYWORDS },
{ label: t('keywordSetsPage.title'), to: ROUTES.KEYWORD_SETS },
{ label: t('imagesPage.title'), to: ROUTES.IMAGES },
...(arePriceGroupRoutesAllowed(user)
...(areFinancialRoutesAllowed(user)
? [{ label: t('organizationsPage.title'), to: ROUTES.ORGANIZATIONS }]
: []),
...(featureFlagUtils.isFeatureEnabled('SHOW_PLACE_PAGES')
? [{ label: t('placesPage.title'), to: ROUTES.PLACES }]
: []),
...(arePriceGroupRoutesAllowed(user)
...(areFinancialRoutesAllowed(user)
? [{ label: t('priceGroupsPage.title'), to: ROUTES.PRICE_GROUPS }]
: []),
];
Expand Down
4 changes: 2 additions & 2 deletions src/domain/app/footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import {
navigationGroupAdmin,
navigationGroupEvents,
navigationGroupHome,
navigationGroupInstructions,
navigationGroupRegistrations,
navigationGroupSupport,
navigationGroupTechnology,
NO_FOOTER_PATHS,
} from './constants';
import styles from './footer.module.scss';
import { getNavigationGroupInstructions } from './utils';

const Footer: React.FC = () => {
const { t } = useTranslation();
Expand Down Expand Up @@ -106,7 +106,7 @@ const Footer: React.FC = () => {
areAdminRoutesAllowed(user) &&
navigationGroupAdmin,
navigationGroupSupport,
navigationGroupInstructions,
getNavigationGroupInstructions(user),
navigationGroupTechnology,
]
.filter(skipFalsyType)
Expand Down
23 changes: 0 additions & 23 deletions src/domain/app/footer/__tests__/__snapshots__/Footer.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -242,29 +242,6 @@ exports[`matches snapshot 1`] = `
Instruktioner för innehållsproduktion
</span>
</a>
<a
class="Link-module_link__TeBQo link_hds-link__5Oxo- Link-module_linkM__30gsY link_hds-link--medium__xEU_F FooterLink-module_item__3Ig3B FooterLink-module_subItem__3unGg FooterLink-module_navigation__1pNfs"
href="/sv/help/instructions/registration"
>
<svg
aria-hidden="true"
aria-label="angle-right"
class="Icon-module_icon__1Jtzj icon_hds-icon__1YqNC Icon-module_s__2WGWe icon_hds-icon--size-s__2Lkik FooterLink-module_subItemIcon__2UHZi"
role="img"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
>
<path
clip-rule="evenodd"
d="M13.5 12L8.5 7L10 5.5L16.5 12L10 18.5L8.5 17L13.5 12Z"
fill="currentColor"
fill-rule="evenodd"
/>
</svg>
<span>
Registreringsinstruktioner
</span>
</a>
<a
class="Link-module_link__TeBQo link_hds-link__5Oxo- Link-module_linkM__30gsY link_hds-link--medium__xEU_F FooterLink-module_item__3Ig3B FooterLink-module_subItem__3unGg FooterLink-module_navigation__1pNfs"
href="/sv/help/instructions/faq"
Expand Down
33 changes: 1 addition & 32 deletions src/domain/app/footer/constants.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import { PathPattern } from 'react-router';

import { ROUTES } from '../../../constants';

type NavigationGroup = {
heading: string;
headingLink: string;
items?: NavigationGroupItem[];
};

type NavigationGroupItem = {
label: string;
url: string;
};
import { NavigationGroup, NavigationGroupItem } from './types';

const NAVIGATION_GROUP_ITEMS_MAIN: NavigationGroupItem[] = [
{
Expand Down Expand Up @@ -72,21 +62,6 @@ const NAVIGATION_GROUP_ITEMS_SUPPORT: NavigationGroupItem[] = [
},
];

const NAVIGATION_GROUP_ITEMS_INSTRUCTIONS: NavigationGroupItem[] = [
{
label: 'helpPage.sideNavigation.labelEventsInstructions',
url: ROUTES.INSTRUCTIONS_EVENTS,
},
{
label: 'helpPage.sideNavigation.labelRegistrationInstructions',
url: ROUTES.INSTRUCTIONS_REGISTRATION,
},
{
label: 'helpPage.sideNavigation.labelFaq',
url: ROUTES.INSTRUCTIONS_FAQ,
},
];

const NAVIGATION_GROUP_ITEMS_TECHNOLOGY: NavigationGroupItem[] = [
{
label: 'helpPage.sideNavigation.labelSourceCode',
Expand Down Expand Up @@ -131,12 +106,6 @@ export const navigationGroupAdmin: NavigationGroup = {
items: NAVIGATION_GROUP_ITEMS_ADMIN,
};

export const navigationGroupInstructions: NavigationGroup = {
heading: 'helpPage.sideNavigation.labelInstructions',
headingLink: ROUTES.INSTRUCTIONS,
items: NAVIGATION_GROUP_ITEMS_INSTRUCTIONS,
};

export const navigationGroupTechnology: NavigationGroup = {
heading: 'helpPage.sideNavigation.labelTechnology',
headingLink: ROUTES.TECHNOLOGY,
Expand Down
10 changes: 10 additions & 0 deletions src/domain/app/footer/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export type NavigationGroup = {
heading: string;
headingLink: string;
items?: NavigationGroupItem[];
};

export type NavigationGroupItem = {
label: string;
url: string;
};
33 changes: 33 additions & 0 deletions src/domain/app/footer/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { ROUTES } from '../../../constants';
import { UserFieldsFragment } from '../../../generated/graphql';
import { areRegistrationRoutesAllowed } from '../../user/permissions';
import { NavigationGroup, NavigationGroupItem } from './types';

const getNavigationGroupItemsInstructions = (
user?: UserFieldsFragment
): NavigationGroupItem[] => [
{
label: 'helpPage.sideNavigation.labelEventsInstructions',
url: ROUTES.INSTRUCTIONS_EVENTS,
},
...(areRegistrationRoutesAllowed(user)
? [
{
label: 'helpPage.sideNavigation.labelRegistrationInstructions',
url: ROUTES.INSTRUCTIONS_REGISTRATION,
},
]
: []),
{
label: 'helpPage.sideNavigation.labelFaq',
url: ROUTES.INSTRUCTIONS_FAQ,
},
];

export const getNavigationGroupInstructions = (
user?: UserFieldsFragment
): NavigationGroup => ({
heading: 'helpPage.sideNavigation.labelInstructions',
headingLink: ROUTES.INSTRUCTIONS,
items: getNavigationGroupItemsInstructions(user),
});
32 changes: 18 additions & 14 deletions src/domain/app/routes/adminRoutes/AdminRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import NotFoundPage from '../../../notFound/NotFound';
import useUser from '../../../user/hooks/useUser';
import {
areAdminRoutesAllowed,
arePriceGroupRoutesAllowed,
areFinancialRoutesAllowed,
} from '../../../user/permissions';

const CreateImagePage = React.lazy(
Expand Down Expand Up @@ -99,18 +99,22 @@ const AdminPageRoutes: React.FC = () => {
element={<KeywordSetsPage />}
/>

<Route
path={getAdminRoutePath(ROUTES.CREATE_ORGANIZATION)}
element={<CreateOrganizationPage />}
/>
<Route
path={getAdminRoutePath(ROUTES.EDIT_ORGANIZATION)}
element={<EditOrganizationPage />}
/>
<Route
path={getAdminRoutePath(ROUTES.ORGANIZATIONS)}
element={<OrganizationsPage />}
/>
{areFinancialRoutesAllowed(user) && (
<>
<Route
path={getAdminRoutePath(ROUTES.CREATE_ORGANIZATION)}
element={<CreateOrganizationPage />}
/>
<Route
path={getAdminRoutePath(ROUTES.EDIT_ORGANIZATION)}
element={<EditOrganizationPage />}
/>
<Route
path={getAdminRoutePath(ROUTES.ORGANIZATIONS)}
element={<OrganizationsPage />}
/>
</>
)}
{featureFlagUtils.isFeatureEnabled('SHOW_PLACE_PAGES') && (
<>
<Route
Expand All @@ -128,7 +132,7 @@ const AdminPageRoutes: React.FC = () => {
</>
)}

{arePriceGroupRoutesAllowed(user) && (
{areFinancialRoutesAllowed(user) && (
<>
<Route
path={getAdminRoutePath(ROUTES.CREATE_PRICE_GROUP)}
Expand Down
68 changes: 41 additions & 27 deletions src/domain/app/routes/helpPageRoutes/HelpPageRoutes.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from 'react';
import { Navigate, Route, Routes } from 'react-router';

import LoadingSpinner from '../../../../common/components/loadingSpinner/LoadingSpinner';
import { ROUTES } from '../../../../constants';
import useLocale from '../../../../hooks/useLocale';
import { Language } from '../../../../types';
import HelpPageLayout from '../../../help/layout/HelpPageLayout';
import AskPermissionPage from '../../../help/pages/askPermissionPage/AskPermissionPage';
import ContactPage from '../../../help/pages/contactPage/ContactPage';
import EventsInstructionsPage from '../../../help/pages/eventsInstructionsPage/EventsInstructionsPage';
Expand All @@ -13,6 +15,8 @@ import ServiceInformationPage from '../../../help/pages/serviceInformation/Servi
import SourceCodePage from '../../../help/pages/sourceCodePage/SourceCodePage';
import TermsOfUsePage from '../../../help/pages/termsOfUsePage/TermsOfUsePage';
import NotFound from '../../../notFound/NotFound';
import useUser from '../../../user/hooks/useUser';
import { areRegistrationRoutesAllowed } from '../../../user/permissions';
/* istanbul ignore next */
const DocumentationPage = React.lazy(
() => import('../../../help/pages/documentationPage/DocumentationPage')
Expand All @@ -26,6 +30,7 @@ const InstructionsRoutes: React.FC<Props> = ({ locale }) => {
const getInstructionsRoutePath = (path: string) =>
path.replace(ROUTES.INSTRUCTIONS, '');
const getLocalePath = (path: string) => `/${locale}${path}`;
const { user } = useUser();

return (
<Routes>
Expand All @@ -39,15 +44,18 @@ const InstructionsRoutes: React.FC<Props> = ({ locale }) => {
path={getInstructionsRoutePath(ROUTES.INSTRUCTIONS_EVENTS)}
element={<EventsInstructionsPage />}
/>
{areRegistrationRoutesAllowed(user) && (
<Route
path={getInstructionsRoutePath(ROUTES.INSTRUCTIONS_REGISTRATION)}
element={<RegistrationInstructions />}
/>
)}
<Route
path={getInstructionsRoutePath(ROUTES.INSTRUCTIONS_FAQ)}
element={<FaqPage />}
/>
<Route
path={getInstructionsRoutePath(ROUTES.INSTRUCTIONS_REGISTRATION)}
element={<RegistrationInstructions />}
/>
<Route
path="*"
element={<NotFound pathAfterSignIn={`/${locale}${ROUTES.HOME}`} />}
/>
</Routes>
Expand Down Expand Up @@ -79,8 +87,8 @@ const TechnologyRoutes: React.FC<Props> = ({ locale }) => {
path={getTechnologyRoutePath(ROUTES.TECHNOLOGY_DOCUMENTATION)}
element={<DocumentationPage />}
/>

<Route
path="*"
element={<NotFound pathAfterSignIn={`/${locale}${ROUTES.HOME}`} />}
/>
</Routes>
Expand Down Expand Up @@ -121,6 +129,7 @@ const SupportRoutes: React.FC<Props> = ({ locale }) => {
element={<TermsOfUsePage />}
/>
<Route
path="*"
element={<NotFound pathAfterSignIn={`/${locale}${ROUTES.HOME}`} />}
/>
</Routes>
Expand All @@ -131,30 +140,35 @@ const HelpPageRoutes: React.FC = () => {
const locale = useLocale();
const getHelpRoutePath = (path: string) => path.replace(ROUTES.HELP, '');
const getLocalePath = (path: string) => `/${locale}${path}`;
const { loading } = useUser();

return (
<Routes>
<Route
path={getHelpRoutePath(ROUTES.HELP)}
element={<Navigate replace to={getLocalePath(ROUTES.SUPPORT)} />}
/>
<Route
path={`${getHelpRoutePath(ROUTES.SUPPORT)}/*`}
element={<SupportRoutes locale={locale} />}
/>
<Route
path={`${getHelpRoutePath(ROUTES.INSTRUCTIONS)}/*`}
element={<InstructionsRoutes locale={locale} />}
/>
<Route
path={`${getHelpRoutePath(ROUTES.TECHNOLOGY)}/*`}
element={<TechnologyRoutes locale={locale} />}
/>
<Route
path="*"
element={<NotFound pathAfterSignIn={`/${locale}${ROUTES.HOME}`} />}
/>
</Routes>
<LoadingSpinner isLoading={loading}>
<HelpPageLayout>
<Routes>
<Route
path={getHelpRoutePath(ROUTES.HELP)}
element={<Navigate replace to={getLocalePath(ROUTES.SUPPORT)} />}
/>
<Route
path={`${getHelpRoutePath(ROUTES.SUPPORT)}/*`}
element={<SupportRoutes locale={locale} />}
/>
<Route
path={`${getHelpRoutePath(ROUTES.INSTRUCTIONS)}/*`}
element={<InstructionsRoutes locale={locale} />}
/>
<Route
path={`${getHelpRoutePath(ROUTES.TECHNOLOGY)}/*`}
element={<TechnologyRoutes locale={locale} />}
/>
<Route
path="*"
element={<NotFound pathAfterSignIn={`/${locale}${ROUTES.HOME}`} />}
/>
</Routes>
</HelpPageLayout>
</LoadingSpinner>
);
};

Expand Down
Loading

0 comments on commit 62e2bdd

Please sign in to comment.