Skip to content

Commit de13b3a

Browse files
committed
PR review fixes
1 parent 9dcc485 commit de13b3a

File tree

6 files changed

+17
-11
lines changed

6 files changed

+17
-11
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export enum UserRole {
2+
gamificationAdmin = 'Gamification Admin',
23
customer = 'Self-Service Customer',
34
member = 'Topcoder User',
45
}

src-ts/lib/profile-provider/user-profile.model.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ export interface UserProfile {
1010
isMember?: boolean
1111
lastName: string
1212
photoURL?: string
13-
roles?: Array<string>,
13+
roles: Array<string>
1414
status: string
1515
updatedAt: number
16-
userId: number,
16+
userId: number
1717
}

src-ts/lib/restricted-page/RestrictedPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ export const RestrictedPage: ReactElement =
1212
title='Thanks for visiting'
1313
>
1414
<div className={styles.container}>
15-
<p>Unfortenatly, you are not permitted to access the site. If you feel you should be able to, please contact us at <a href='mailto:support@topcoder.com'>support@topcoder.com</a>.</p>
15+
<p>Unfortunately, you are not permitted to access the site. If you feel you should be able to, please <a href='/support'>contact us</a>.</p>
1616
</div>
1717
</ContentLayout>

src-ts/lib/route-provider/require-auth-provider/require-auth.provider.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { RestrictedPage } from '../../restricted-page'
55

66
interface RequireAuthProviderProps {
77
children: JSX.Element
8-
loginUrl: string,
9-
rolesRequired?: Array<string>,
8+
loginUrl: string
9+
rolesRequired?: Array<string>
1010
}
1111

1212
function RequireAuthProvider(props: RequireAuthProviderProps): JSX.Element {
@@ -23,9 +23,13 @@ function RequireAuthProvider(props: RequireAuthProviderProps): JSX.Element {
2323
// check the user's roles, allow access or show restricted page
2424
if (!!profile) {
2525
if (props.rolesRequired) {
26-
if (!profile.roles) { return RestrictedPage }
27-
const intersection: Array<string> = profile.roles?.filter(r => props.rolesRequired?.includes(r))
28-
if (intersection.length !== props.rolesRequired.length) { return RestrictedPage }
26+
if (!profile.roles) {
27+
return RestrictedPage
28+
}
29+
// if the profile doesn't include all the required roles, show the restricted page
30+
if (props.rolesRequired.some(role => !profile.roles.includes(role))) {
31+
return RestrictedPage
32+
}
2933
return props.children
3034
} else {
3135
return props.children

src-ts/tools/gamification-admin/GamificationAdmin.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import {
77
} from '../../lib'
88

99
export const toolTitle: string = 'Gamification Admin'
10-
export const baseUrl: string = '/gamification-admin'
11-
export const rolesRequired: Array<string> = ['Gamification Admin']
1210

1311
const GamificationAdmin: FC<{}> = () => {
1412

src-ts/tools/gamification-admin/gamification-admin.routes.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { PlatformRoute } from '../../lib'
22

3-
import GamificationAdmin, { baseUrl, rolesRequired, toolTitle } from './GamificationAdmin'
3+
import GamificationAdmin, { toolTitle } from './GamificationAdmin'
44
import BadgeDetailPage from './pages/badge-detail/BadgeDetailPage'
55
import BadgeListingPage from './pages/badge-listing/BadgeListingPage'
66
import CreateBadgePage from './pages/create-badge/CreateBadgePage'
77

8+
export const baseUrl: string = '/gamification-admin'
9+
export const rolesRequired: Array<string> = ['Gamification Admin']
10+
811
export const gamificationAdminRoutes: Array<PlatformRoute> = [
912
{
1013
authRequired: true,

0 commit comments

Comments
 (0)