Skip to content

Commit 8ec9298

Browse files
committed
Don't allow for deleting reviewers or copilots after submission phase
https://topcoder.atlassian.net/browse/PROD-4270
1 parent 564720b commit 8ec9298

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

src/components/ChallengeEditor/Resources/index.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import cn from 'classnames'
1111
import { getTCMemberURL } from '../../../config/constants'
1212
import ReactSVG from 'react-svg'
1313
import { getRatingLevel, sortList } from '../../../util/tc'
14+
import { getCurrentPhase } from '../../../util/phase'
1415
import styles from './styles.module.scss'
1516
import ResourcesDeleteModal from '../ResourcesDeleteModal'
1617

@@ -63,7 +64,7 @@ export default class Resources extends React.Component {
6364
},
6465
selectedTab: 0,
6566
showDeleteResourceModal: null,
66-
exceptionHandlesDeleteList: {}
67+
exceptionResourceIdDeleteList: {}
6768
}
6869

6970
this.sortResources = this.sortResources.bind(this)
@@ -89,11 +90,13 @@ export default class Resources extends React.Component {
8990
}
9091
if (
9192
!_.isEqual(prevProps.submissions, submissions) ||
92-
!_.isEqual(prevProps.challenge, challenge)
93+
!_.isEqual(prevProps.challenge, challenge) ||
94+
!_.isEqual(prevProps.resources, resources)
9395
) {
9496
this.updateExceptionHandlesDelete()
9597
}
9698
}
99+
97100
onSortChange (sort) {
98101
this.setState({
99102
resourcesSort: sort
@@ -143,13 +146,32 @@ export default class Resources extends React.Component {
143146
* Don't allow deletion of submitters who submitted, or creator of challenge
144147
*/
145148
updateExceptionHandlesDelete () {
146-
const { submissions, challenge } = this.props
149+
const { submissions, challenge, resources } = this.props
150+
const currentPhase = getCurrentPhase(challenge).toLowerCase()
151+
const isCurrentPhasesNotSubmissionOrRegistration = _.every(['submission', 'registration'], (phase) => currentPhase.indexOf(phase) < 0)
147152
const exceptionHandlesDeleteList = {}
153+
// do not allow to delete owner of challenge
148154
exceptionHandlesDeleteList[challenge.createdBy] = true
149155
_.forEach(submissions, (s) => {
156+
// do not allow to delete member that submit submission
150157
exceptionHandlesDeleteList[s.createdBy] = true
151158
})
152-
this.setState({ exceptionHandlesDeleteList })
159+
160+
const exceptionResourceIdDeleteList = {}
161+
_.forEach(resources, (resourceItem) => {
162+
if (
163+
(
164+
// If the current phase is not submission or registration
165+
// then we will disable removing reviewers and copilots.
166+
_.some(['reviewer', 'copilot'], (role) => `${resourceItem.role}`.toLowerCase().indexOf(role) >= 0) &&
167+
isCurrentPhasesNotSubmissionOrRegistration
168+
) ||
169+
exceptionHandlesDeleteList[resourceItem.memberHandle]
170+
) {
171+
exceptionResourceIdDeleteList[resourceItem.id] = true
172+
}
173+
})
174+
this.setState({ exceptionResourceIdDeleteList })
153175
}
154176

155177
/**
@@ -209,7 +231,7 @@ export default class Resources extends React.Component {
209231
const { challenge, canEditResource, deleteResource } = this.props
210232
const { track } = challenge
211233

212-
const { sortedResources, selectedTab, showDeleteResourceModal, exceptionHandlesDeleteList } = this.state
234+
const { sortedResources, selectedTab, showDeleteResourceModal, exceptionResourceIdDeleteList } = this.state
213235

214236
const { field, sort } = this.getResourcesSortParam()
215237
const revertSort = sort === 'desc' ? 'asc' : 'desc'
@@ -376,7 +398,7 @@ export default class Resources extends React.Component {
376398
<span role='cell'>{formatDate(r.created)}</span>
377399
</td>
378400

379-
{(canEditResource && !exceptionHandlesDeleteList[r.memberHandle]) ? (
401+
{(canEditResource && !exceptionResourceIdDeleteList[r.id]) ? (
380402
<td className={cn(styles['col-8Table'], styles['col-bodyTable'])}>
381403
<button
382404
onClick={() => {

src/components/ChallengesComponent/ChallengeCard/index.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { formatDate } from '../../../util/date'
1515
import { CHALLENGE_STATUS, COMMUNITY_APP_URL, DIRECT_PROJECT_URL, MESSAGE, ONLINE_REVIEW_URL, PROJECT_ROLES } from '../../../config/constants'
1616
import ConfirmationModal from '../../Modal/ConfirmationModal'
1717
import { checkChallengeEditPermission, checkReadOnlyRoles } from '../../../util/tc'
18+
import { getCurrentPhase } from '../../../util/phase'
1819
import AlertModal from '../../Modal/AlertModal'
1920
import Tooltip from '../../Tooltip'
2021

@@ -121,7 +122,7 @@ class ChallengeCard extends React.Component {
121122
isCheckChalengePermission: false,
122123
hasEditChallengePermission: false,
123124
loginUserRoleInProject: '',
124-
currentPhase: this.getCurrentPhase(props.challenge),
125+
currentPhase: getCurrentPhase(props.challenge),
125126
forumLink: this.getForumLink(props.challenge)
126127
}
127128
this.onUpdateConfirm = this.onUpdateConfirm.bind(this)
@@ -132,10 +133,6 @@ class ChallengeCard extends React.Component {
132133
this.onLaunchChallenge = this.onLaunchChallenge.bind(this)
133134
}
134135

135-
getCurrentPhase (challenge) {
136-
return challenge.phases.filter((p) => p.isOpen).map((p) => p.name).join(' / ') || '-'
137-
}
138-
139136
getForumLink (challenge) {
140137
const discussionsHaveUrls = (challenge.discussions || []).filter((p) => !!p.url)
141138
return discussionsHaveUrls.length ? discussionsHaveUrls[0].url : ''
@@ -146,7 +143,7 @@ class ChallengeCard extends React.Component {
146143
if (!_.isEqual(challenge.phases, prevProps.challenge.phases)) {
147144
// eslint-disable-next-line react/no-did-update-set-state
148145
this.setState({
149-
currentPhase: this.getCurrentPhase(challenge)
146+
currentPhase: getCurrentPhase(challenge)
150147
})
151148
}
152149
if (!_.isEqual(challenge.discussions, prevProps.challenge.discussions)) {

src/util/phase.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ export const canChangeDuration = phase => {
66
}
77
return moment(phase.scheduledEndDate).isAfter()
88
}
9+
10+
export const getCurrentPhase = (challenge) => {
11+
return (challenge ? challenge.phases : []).filter((p) => p.isOpen).map((p) => p.name).join(' / ') || '-'
12+
}

0 commit comments

Comments
 (0)