Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ install_deploysuite: &install_deploysuite
cp ./../buildscript/buildenv.sh .
cp ./../buildscript/awsconfiguration.sh .
restore_cache_settings_for_build: &restore_cache_settings_for_build
key: docker-node-modules-{{ checksum "package-lock.json" }}
key: docker-node-modules-temp1-{{ checksum "package-lock.json" }}

save_cache_settings: &save_cache_settings
key: docker-node-modules-{{ checksum "package-lock.json" }}
key: docker-node-modules-temp1-{{ checksum "package-lock.json" }}
paths:
- node_modules

Expand Down
3 changes: 3 additions & 0 deletions src/components/ChallengeEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,9 @@ class ChallengeEditor extends Component {
</div>}
</div>}
{!isLoading && isActive && <div className={styles.buttonContainer}>
<div className={styles.button}>
<OutlineButton text={isSaving ? 'Saving...' : 'Save'} type={'success'} onClick={this.onSaveChallenge} />
</div>
{isTask && (
<div className={styles.button}>
<PrimaryButton text={'Close Task'} type={'danger'} onClick={this.openCloseTaskConfirmation} />
Expand Down
5 changes: 5 additions & 0 deletions src/config/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ export const ALLOWED_USER_ROLES = [
'connect copilot'
]

export const ADMIN_ROLES = [
'administrator',
'connect admin'
]

export const downloadAttachmentURL = (challengeId, attachmentId, token) =>
`${CHALLENGE_API_URL}/${challengeId}/attachments/${attachmentId}?token=${token}`

Expand Down
7 changes: 6 additions & 1 deletion src/containers/ChallengeEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { withRouter, Route } from 'react-router-dom'
import ChallengeEditorComponent from '../../components/ChallengeEditor'
import ChallengeViewComponent from '../../components/ChallengeEditor/ChallengeView'
import Loader from '../../components/Loader'
import { checkAdmin } from '../../util/tc'
import styles from './ChallengeEditor.module.scss'

import {
Expand Down Expand Up @@ -120,7 +121,11 @@ class ChallengeEditor extends Component {
}

isEditable () {
const { hasProjectAccess, metadata: { resourceRoles }, challengeResources, loggedInUser } = this.props
const { hasProjectAccess, metadata: { resourceRoles }, challengeResources, loggedInUser, token } = this.props
const isAdmin = checkAdmin(token)
if (isAdmin) {
return true
}
if (!hasProjectAccess) {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export async function fetchTimelineTemplates () {
* @returns {Promise<*>}
*/
export async function fetchChallengeTimelines () {
const response = await axiosInstance.get(`${CHALLENGE_TIMELINES_URL}?page=1&perPage=100`)
const response = await axiosInstance.get(`${CHALLENGE_TIMELINES_URL}?isDefault=true&page=1&perPage=100`)
return _.get(response, 'data', [])
}

Expand Down
13 changes: 12 additions & 1 deletion src/util/tc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/**
* Topcoder related utilities
*/
import { MARATHON_MATCH_SUBTRACKS, CHALLENGE_TRACKS, ALLOWED_USER_ROLES } from '../config/constants'
import { MARATHON_MATCH_SUBTRACKS, CHALLENGE_TRACKS, ALLOWED_USER_ROLES, ADMIN_ROLES } from '../config/constants'
import _ from 'lodash'
import jwtDecode from 'jwt-decode'

export const RATING_COLORS = [{
color: '#9D9FA0' /* Grey */,
Expand Down Expand Up @@ -48,3 +50,12 @@ export function fixedTrack (track, subTrack) {
* @param roles
*/
export const checkAllowedRoles = (roles) => roles.some(val => ALLOWED_USER_ROLES.indexOf(val.toLowerCase()) > -1)

/**
* Checks if token has any of the admin roles
* @param token
*/
export const checkAdmin = (token) => {
const roles = _.get(jwtDecode(token), 'roles')
return roles.some(val => ADMIN_ROLES.indexOf(val.toLowerCase()) > -1)
}