Skip to content

Commit 10e90f6

Browse files
committed
Better business rules for deleting users - don’t delete submitters with submissions or the creator of the challenge
#1549
1 parent 8f00892 commit 10e90f6

File tree

2 files changed

+42
-15
lines changed

2 files changed

+42
-15
lines changed

src/components/ChallengeEditor/ChallengeViewTabs/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ const ChallengeViewTabs = ({
287287
resources={allResources}
288288
canEditResource={canEditResource}
289289
deleteResource={deleteResource}
290+
submissions={submissions}
290291
/>
291292
)}
292293
{selectedTab === 2 && (

src/components/ChallengeEditor/Resources/index.js

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,28 +62,37 @@ export default class Resources extends React.Component {
6262
sort: ''
6363
},
6464
selectedTab: 0,
65-
showDeleteResourceModal: null
65+
showDeleteResourceModal: null,
66+
exceptionHandlesDeleteList: {}
6667
}
6768

6869
this.sortResources = this.sortResources.bind(this)
6970
this.getResourcesSortParam = this.getResourcesSortParam.bind(this)
7071
this.updateSortedResources = this.updateSortedResources.bind(this)
72+
this.updateExceptionHandlesDelete = this.updateExceptionHandlesDelete.bind(this)
7173
this.onSortChange = this.onSortChange.bind(this)
7274
this.setSelectedTab = this.setSelectedTab.bind(this)
7375
}
7476

7577
componentDidMount () {
7678
this.updateSortedResources()
79+
this.updateExceptionHandlesDelete()
7780
}
7881

7982
componentDidUpdate (prevProps) {
80-
const { resources, resourcesSort } = this.props
83+
const { resources, resourcesSort, submissions, challenge } = this.props
8184
if (
8285
!_.isEqual(prevProps.resources, resources) ||
8386
!_.isEqual(prevProps.resourcesSort, resourcesSort)
8487
) {
8588
this.updateSortedResources()
8689
}
90+
if (
91+
!_.isEqual(prevProps.submissions, submissions) ||
92+
!_.isEqual(prevProps.challenge, challenge)
93+
) {
94+
this.updateExceptionHandlesDelete()
95+
}
8796
}
8897
onSortChange (sort) {
8998
this.setState({
@@ -129,6 +138,20 @@ export default class Resources extends React.Component {
129138
this.setState({ sortedResources })
130139
}
131140

141+
/**
142+
* Update exception handles delete
143+
* Don't allow deletion of submitters who submitted, or creator of challenge
144+
*/
145+
updateExceptionHandlesDelete () {
146+
const { submissions, challenge } = this.props
147+
const exceptionHandlesDeleteList = {}
148+
exceptionHandlesDeleteList[challenge.createdBy] = true
149+
_.forEach(submissions, (s) => {
150+
exceptionHandlesDeleteList[s.createdBy] = true
151+
})
152+
this.setState({ exceptionHandlesDeleteList })
153+
}
154+
132155
/**
133156
* Sort array of registrant
134157
* @param {Array} resources array of registrant
@@ -186,7 +209,7 @@ export default class Resources extends React.Component {
186209
const { challenge, canEditResource, deleteResource } = this.props
187210
const { track } = challenge
188211

189-
const { sortedResources, selectedTab, showDeleteResourceModal } = this.state
212+
const { sortedResources, selectedTab, showDeleteResourceModal, exceptionHandlesDeleteList } = this.state
190213

191214
const { field, sort } = this.getResourcesSortParam()
192215
const revertSort = sort === 'desc' ? 'asc' : 'desc'
@@ -353,17 +376,18 @@ export default class Resources extends React.Component {
353376
<span role='cell'>{formatDate(r.created)}</span>
354377
</td>
355378

356-
{canEditResource ? (<td className={cn(styles['col-8Table'], styles['col-bodyTable'])}>
357-
<button
358-
onClick={() => {
359-
this.setState({
360-
showDeleteResourceModal: r
361-
})
362-
}}
363-
>
364-
<ReactSVG path={assets(`${Trash}`)} />
365-
</button>
366-
</td>) : null}
379+
{(canEditResource && !exceptionHandlesDeleteList[r.memberHandle]) ? (
380+
<td className={cn(styles['col-8Table'], styles['col-bodyTable'])}>
381+
<button
382+
onClick={() => {
383+
this.setState({
384+
showDeleteResourceModal: r
385+
})
386+
}}
387+
>
388+
<ReactSVG path={assets(`${Trash}`)} />
389+
</button>
390+
</td>) : null}
367391
</tr>
368392
)
369393
})}
@@ -383,7 +407,8 @@ export default class Resources extends React.Component {
383407
Resources.defaultProps = {
384408
results: [],
385409
checkpointResults: {},
386-
resourcesSort: {}
410+
resourcesSort: {},
411+
submissions: []
387412
}
388413

389414
Resources.propTypes = {
@@ -404,6 +429,7 @@ Resources.propTypes = {
404429
type: PT.string,
405430
track: PT.string
406431
}).isRequired,
432+
submissions: PT.arrayOf(PT.shape()),
407433
resources: PT.arrayOf(PT.shape()),
408434
resourcesSort: PT.shape({
409435
field: PT.string,

0 commit comments

Comments
 (0)