Skip to content

Commit

Permalink
Merge pull request #1101 from bcgov/feature/ns-to-gw-redirects
Browse files Browse the repository at this point in the history
/devportal and /manager redirects
  • Loading branch information
rustyjux authored Jul 22, 2024
2 parents 41ad730 + 7e6da9d commit f6f35d4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 157 deletions.
80 changes: 3 additions & 77 deletions src/nextapp/pages/devportal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,90 +1,16 @@
import * as React from 'react';
import { Box, Container, Heading, Icon, Link, Text } from '@chakra-ui/react';
import Head from 'next/head';
import NextLink from 'next/link';
import Card from '@/components/card';
import GridLayout from '@/layouts/grid';
import {
FaBook,
FaDatabase,
FaServer,
FaShieldAlt,
FaToolbox,
} from 'react-icons/fa';
import { useAuth } from '@/shared/services/auth';

type HomeActions = {
title: string;
url: string;
icon: React.ComponentType;
roles: string[];
description: string;
};
const actions: HomeActions[] = [
{
title: 'API Provider Console',
url: '/manager',
icon: FaServer,
roles: [],
description: "Are you in a Ministry looking to offer APIs to others? Get started in the API Provider Console."
},
];
import { useRouter } from 'next/router';

const HomePage: React.FC = () => {
const { user } = useAuth();
const router = useRouter();
router.push('/devportal/api-directory');

return (
<>
<Head>
<title>API Program Services | Home</title>
</Head>
<Box bgColor="bc-blue" color="white" bgImg="url( /images/banner.png )">
<Container maxW="6xl" paddingY={8}>
<Box
padding={4}
marginTop={{ base: 0, sm: 8 }}
bgColor="rgba(0, 51, 102, 0.8)"
maxW={{ base: '100%', md: '60%' }}
textShadow="0 0 10px rgba(0, 0, 0, 0.8)"
>
<Heading fontWeight="normal" marginBottom={4}>
BC Government API Developer Portal
</Heading>
<Text marginBottom={4}>
Discover and access APIs from various ministries and programs
across government.
</Text>
{/* <Link fontWeight="bold">{`What's New`}</Link> */}
</Box>
</Container>
</Box>
<Container maxW="6xl">
<GridLayout>
{actions
.filter(
(action) =>
user?.roles.some((r: string) => action.roles.includes(r)) ||
action.roles.length === 0
)
.map((action) => (
<Card key={action.url}>
<Box p={4}>
<Heading size="md" mb={2}>
<NextLink passHref href={action.url}>
<Link color="bc-link" display="flex" alignItems="center">
<Icon as={action.icon} color="bc-yellow" mr={2} />
{action.title}
</Link>
</NextLink>
</Heading>
<p>
{action.description}
</p>
</Box>
</Card>
))}
</GridLayout>
</Container>
</>
);
};
Expand Down
79 changes: 3 additions & 76 deletions src/nextapp/pages/manager/index.tsx
Original file line number Diff line number Diff line change
@@ -1,89 +1,16 @@
import * as React from 'react';
import { Box, Container, Heading, Icon, Link, Text } from '@chakra-ui/react';
import Head from 'next/head';
import NextLink from 'next/link';
import Card from '@/components/card';
import GridLayout from '@/layouts/grid';
import {
FaBook,
FaDatabase,
FaServer,
FaShieldAlt,
FaToolbox,
} from 'react-icons/fa';
import { useAuth } from '@/shared/services/auth';

type HomeActions = {
title: string;
url: string;
icon: React.ComponentType;
roles: string[];
description: string;
};
const actions: HomeActions[] = [
{
title: 'API Developer Portal',
url: '/devportal',
icon: FaServer,
roles: [],
description: "Looking to discover APIs that you can use in your application? Jump to the API Developer Portal!"
},
];
import { useRouter } from 'next/router';

const HomePage: React.FC = () => {
const { user } = useAuth();
const router = useRouter();
router.push('/manager/gateways');

return (
<>
<Head>
<title>API Program Services | Home</title>
</Head>
<Box bgColor="bc-blue" color="white" bgImg="url( /images/banner.png )">
<Container maxW="6xl" paddingY={8}>
<Box
padding={4}
marginTop={{ base: 0, sm: 8 }}
bgColor="rgba(0, 51, 102, 0.8)"
maxW={{ base: '100%', md: '60%' }}
textShadow="0 0 10px rgba(0, 0, 0, 0.8)"
>
<Heading fontWeight="normal" marginBottom={4}>
BC Government API Provider Console
</Heading>
<Text marginBottom={4}>
Register your API to give you full control of access and to build up a community of users using your API.
</Text>
{/* <Link fontWeight="bold">{`What's New`}</Link> */}
</Box>
</Container>
</Box>
<Container maxW="6xl">
<GridLayout>
{actions
.filter(
(action) =>
user?.roles.some((r: string) => action.roles.includes(r)) ||
action.roles.length === 0
)
.map((action) => (
<Card key={action.url}>
<Box p={4}>
<Heading size="md" mb={2}>
<NextLink passHref href={action.url}>
<Link color="bc-link" display="flex" alignItems="center">
<Icon as={action.icon} color="bc-yellow" mr={2} />
{action.title}
</Link>
</NextLink>
</Heading>
<p>
{action.description}
</p>
</Box>
</Card>
))}
</GridLayout>
</Container>
</>
);
};
Expand Down
14 changes: 10 additions & 4 deletions src/nextapp/shared/services/auth/auth-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,28 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
);
const isUnauthorized =
(session.error || !session.user) && route?.access.length > 0;

const providerPage =
route?.access.indexOf('api-owner') > -1 ||
route?.access.indexOf('idir-user') > -1;

const identityParam = providerPage ? 'identity=provider&' : '';

if (session.status == 'loading') {
return <></>;
}

// A logged in user trying to access a Namespace'd page (page that is not protected with "portal-user" role)
// and no namespace set, then redirect to home page
const isUnauthorizedProvider =
// and no namespace set, then redirect to Gateways page
const noNamespace =
session.user &&
route?.access &&
route?.access.length > 0 &&
route?.access.indexOf('portal-user') == -1 &&
route?.access.indexOf('idir-user') == -1 &&
!session.user.namespace;

if (isUnauthorizedProvider) {
if (noNamespace) {
router?.push('/manager/gateways');
return <></>;
}
Expand All @@ -61,7 +67,7 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
<Text>You do not have permission to view this page.</Text>
</Box>
<Button
href={`/login?${new URLSearchParams({
href={`/login?${identityParam}${new URLSearchParams({
f: router?.asPath,
})}`}
>
Expand Down

0 comments on commit f6f35d4

Please sign in to comment.