Skip to content

Commit 9e69bcd

Browse files
author
Sachin Maheshwari
committed
Merge branch 'develop' into feature/Auth0-RS256-Token
2 parents 3acc85a + 1137667 commit 9e69bcd

File tree

6 files changed

+29
-5
lines changed

6 files changed

+29
-5
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ install_deploysuite: &install_deploysuite
1616
cp ./../buildscript/buildenv.sh .
1717
cp ./../buildscript/awsconfiguration.sh .
1818
restore_cache_settings_for_build: &restore_cache_settings_for_build
19-
key: docker-node-modules-{{ checksum "package-lock.json" }}
19+
key: docker-node-modules-28-10-2020-{{ checksum "package-lock.json" }}
2020

2121
save_cache_settings: &save_cache_settings
22-
key: docker-node-modules-{{ checksum "package-lock.json" }}
22+
key: docker-node-modules-28-10-2020-{{ checksum "package-lock.json" }}
2323
paths:
2424
- node_modules
2525

src/components/ChallengeEditor/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,9 @@ class ChallengeEditor extends Component {
11991199
</div>}
12001200
</div>}
12011201
{!isLoading && isActive && <div className={styles.buttonContainer}>
1202+
<div className={styles.button}>
1203+
<OutlineButton text={isSaving ? 'Saving...' : 'Save'} type={'success'} onClick={this.onSaveChallenge} />
1204+
</div>
12021205
{isTask && (
12031206
<div className={styles.button}>
12041207
<PrimaryButton text={'Close Task'} type={'danger'} onClick={this.openCloseTaskConfirmation} />

src/config/constants.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ export const ALLOWED_USER_ROLES = [
147147
'connect copilot'
148148
]
149149

150+
export const ADMIN_ROLES = [
151+
'administrator',
152+
'connect admin'
153+
]
154+
150155
export const downloadAttachmentURL = (challengeId, attachmentId, token) =>
151156
`${CHALLENGE_API_URL}/${challengeId}/attachments/${attachmentId}?token=${token}`
152157

src/containers/ChallengeEditor/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { withRouter, Route } from 'react-router-dom'
55
import ChallengeEditorComponent from '../../components/ChallengeEditor'
66
import ChallengeViewComponent from '../../components/ChallengeEditor/ChallengeView'
77
import Loader from '../../components/Loader'
8+
import { checkAdmin } from '../../util/tc'
89
import styles from './ChallengeEditor.module.scss'
910

1011
import {
@@ -120,7 +121,11 @@ class ChallengeEditor extends Component {
120121
}
121122

122123
isEditable () {
123-
const { hasProjectAccess, metadata: { resourceRoles }, challengeResources, loggedInUser } = this.props
124+
const { hasProjectAccess, metadata: { resourceRoles }, challengeResources, loggedInUser, token } = this.props
125+
const isAdmin = checkAdmin(token)
126+
if (isAdmin) {
127+
return true
128+
}
124129
if (!hasProjectAccess) {
125130
return false
126131
}

src/services/challenges.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export async function fetchTimelineTemplates () {
7474
* @returns {Promise<*>}
7575
*/
7676
export async function fetchChallengeTimelines () {
77-
const response = await axiosInstance.get(`${CHALLENGE_TIMELINES_URL}?page=1&perPage=100`)
77+
const response = await axiosInstance.get(`${CHALLENGE_TIMELINES_URL}?isDefault=true&page=1&perPage=100`)
7878
return _.get(response, 'data', [])
7979
}
8080

src/util/tc.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
/**
22
* Topcoder related utilities
33
*/
4-
import { MARATHON_MATCH_SUBTRACKS, CHALLENGE_TRACKS, ALLOWED_USER_ROLES } from '../config/constants'
4+
import { MARATHON_MATCH_SUBTRACKS, CHALLENGE_TRACKS, ALLOWED_USER_ROLES, ADMIN_ROLES } from '../config/constants'
5+
import _ from 'lodash'
6+
import jwtDecode from 'jwt-decode'
57

68
export const RATING_COLORS = [{
79
color: '#9D9FA0' /* Grey */,
@@ -48,3 +50,12 @@ export function fixedTrack (track, subTrack) {
4850
* @param roles
4951
*/
5052
export const checkAllowedRoles = (roles) => roles.some(val => ALLOWED_USER_ROLES.indexOf(val.toLowerCase()) > -1)
53+
54+
/**
55+
* Checks if token has any of the admin roles
56+
* @param token
57+
*/
58+
export const checkAdmin = (token) => {
59+
const roles = _.get(jwtDecode(token), 'roles')
60+
return roles.some(val => ADMIN_ROLES.indexOf(val.toLowerCase()) > -1)
61+
}

0 commit comments

Comments
 (0)