Skip to content

Commit

Permalink
Merge pull request #897 from bcgov/fix/pending-analyst-redirect
Browse files Browse the repository at this point in the history
fix: pending analysts should not be allowed on user/profile page
  • Loading branch information
matthieu-foucault authored Jul 14, 2020
2 parents 16c9455 + c31f3c4 commit 5aa8b0c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
17 changes: 10 additions & 7 deletions app/layouts/default-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,22 @@ const DefaultLayout: React.FunctionComponent<Props> = ({
return null;
}

if (needsUser && !session.ciipUserBySub) {
// Redirect users attempting to access a page that their group doesn't allow
// to their landing route. This needs to happen before redirecting to the registration
// to ensure that a pending analyst doesn't get redirect to the registration page
if (!canAccess) {
router.push({
pathname: '/registration',
query: {
redirectTo: router.asPath
}
pathname: getUserGroupLandingRoute(userGroups)
});
return null;
}

if (!canAccess) {
if (needsUser && !session.ciipUserBySub) {
router.push({
pathname: getUserGroupLandingRoute(userGroups)
pathname: '/registration',
query: {
redirectTo: router.asPath
}
});
return null;
}
Expand Down
4 changes: 3 additions & 1 deletion app/pages/user/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import {graphql} from 'react-relay';
import {profileQueryResponse} from 'profileQuery.graphql';
import DefaultLayout from 'layouts/default-layout';
import UserProfileContainer from 'containers/User/UserProfile';
import {INCENTIVE_ANALYST, ADMIN_GROUP, USER} from 'data/group-constants';

const ALLOWED_GROUPS = [INCENTIVE_ANALYST, ...ADMIN_GROUP, USER];
interface Props {
query: profileQueryResponse['query'];
}
Expand All @@ -25,7 +27,7 @@ class Profile extends Component<Props> {
const {session} = this.props.query;

return (
<DefaultLayout session={session}>
<DefaultLayout session={session} allowedGroups={ALLOWED_GROUPS}>
<UserProfileContainer user={session ? session.ciipUserBySub : null} />
</DefaultLayout>
);
Expand Down
11 changes: 10 additions & 1 deletion app/tests/unit/pages/user/__snapshots__/profile.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`user profile matches snapshot 1`] = `
<Relay(DefaultLayout)>
<Relay(DefaultLayout)
allowedGroups={
Array [
"Incentive Analyst",
"Realm Administrator",
"Incentive Administrator",
"User",
]
}
>
<Relay(UserProfile)
user={null}
/>
Expand Down

0 comments on commit 5aa8b0c

Please sign in to comment.