Skip to content

Commit

Permalink
fix: prevent tasks linking to themselves
Browse files Browse the repository at this point in the history
A second go at fixing this, previously fixed in zooniverse#5925. Pass the current task key as a prop to `NextTaskSelector`. Filter the list of tasks to exclude that task key, so that a task can't link back to itself.

This has to be edited in the editors for each individual task type, but I think I got them all.
  • Loading branch information
eatyourgreens committed May 9, 2024
1 parent 04a4bbe commit c440edc
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 9 deletions.
3 changes: 2 additions & 1 deletion app/classifier/tasks/combo/editor.cjsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ ComboTaskEditor = createReactClass
</li>

render: ->
[root, taskKey] = @props.taskPrefix.split '.'
tasks = require('..').default
<div>
<p>Add any number of tasks here and they'll be shown in one step.</p>
Expand Down Expand Up @@ -77,7 +78,7 @@ ComboTaskEditor = createReactClass
<p>
<label>
Next task:{' '}
<NextTaskSelector task={@props.task} workflow={@props.workflow} value={@props.task.next} onChange={@setNextTask} />
<NextTaskSelector taskKey={taskKey} workflow={@props.workflow} value={@props.task.next} onChange={@setNextTask} />
</label>
<br />
<span className="form-help">This overrides anything set by a sub-task.</span>
Expand Down
3 changes: 2 additions & 1 deletion app/classifier/tasks/dropdown/editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export default class DropdownEditor extends React.Component {
}

render() {
const [root, taskKey] = this.props.taskPrefix.split('.');
const handleChange = handleInputChange.bind(this.props.workflow);

const selects = this.props.task.selects;
Expand Down Expand Up @@ -218,7 +219,7 @@ export default class DropdownEditor extends React.Component {
<span className="form-label">Next task</span>
<br />
<NextTaskSelector
task={this.props.task}
taskKey={taskKey}
workflow={this.props.workflow}
name={`${this.props.taskPrefix}.next`}
value={this.props.task.next || ''}
Expand Down
5 changes: 3 additions & 2 deletions app/classifier/tasks/generic-editor.cjsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module.exports = createReactClass
taskPrefix: ''

render: ->
[root, taskKey] = @props.taskPrefix.split '.'
handleChange = handleInputChange.bind @props.workflow

[mainTextKey, choicesKey] = switch @props.task.type
Expand Down Expand Up @@ -130,7 +131,7 @@ module.exports = createReactClass
<div className="workflow-choice-setting">
<AutoSave resource={@props.workflow}>
Next task{' '}
<NextTaskSelector task={@props.task} workflow={@props.workflow} name="#{@props.taskPrefix}.#{choicesKey}.#{index}.next" value={choice.next ? ''} onChange={handleChange} />
<NextTaskSelector taskKey={taskKey} workflow={@props.workflow} name="#{@props.taskPrefix}.#{choicesKey}.#{index}.next" value={choice.next ? ''} onChange={handleChange} />
</AutoSave>
</div>

Expand Down Expand Up @@ -304,7 +305,7 @@ module.exports = createReactClass
<div>
<AutoSave resource={@props.workflow}>
Next task{' '}
<NextTaskSelector task={@props.task} workflow={@props.workflow} name="#{@props.taskPrefix}.next" value={@props.task.next ? ''} onChange={handleChange} />
<NextTaskSelector taskKey={taskKey} workflow={@props.workflow} name="#{@props.taskPrefix}.next" value={@props.task.next ? ''} onChange={handleChange} />
</AutoSave>
</div>}
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/classifier/tasks/next-task-selector.cjsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = createReactClass
<select name={@props.name} value={@props.value} onChange={@props.onChange}>
<option value="">(Submit classification and load next subject)</option>
{for key, definition of @props.workflow.tasks
unless definition.type is 'shortcut' or definition is @props.task
unless definition.type is 'shortcut' or key is @props.taskKey
text = tasks[definition.type]?.getTaskText definition
if text and text.length > MAX_TEXT_LENGTH_IN_MENU
text = text[0...MAX_TEXT_LENGTH_IN_MENU] + '...'
Expand Down
3 changes: 2 additions & 1 deletion app/classifier/tasks/slider/editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import handleInputChange from '../../../lib/handle-input-change';
import NextTaskSelector from '../next-task-selector';

const SliderTaskEditor = (props) => {
const [root, taskKey] = props.taskPrefix.split('.');
const handleChange = handleInputChange.bind(props.workflow);
let nextTask;
let helpBox;
Expand All @@ -16,7 +17,7 @@ const SliderTaskEditor = (props) => {
<span className="form-label">Next task</span>
<br />
<NextTaskSelector
task={props.task}
taskKey={taskKey}
workflow={props.workflow}
name={`${props.taskPrefix}.next`}
value={props.task.next ? props.task.next : ''}
Expand Down
3 changes: 2 additions & 1 deletion app/classifier/tasks/survey/editor.cjsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module.exports = createReactClass
task: JSON.parse JSON.stringify nextProps.task

render: ->
[root, taskKey] = @props.taskPrefix.split '.'
contentWarnings = @checkContentWarnings()

<div className="workflow-task-editor">
Expand Down Expand Up @@ -223,7 +224,7 @@ module.exports = createReactClass
<AutoSave resource={@props.workflow}>
<span className="form-label">Next task</span>
<br />
<NextTaskSelector task={@props.task} workflow={@props.workflow} name="#{@props.taskPrefix}.next" value={@props.task.next ? ''} onChange={handleInputChange.bind @props.workflow} />
<NextTaskSelector taskKey={taskKey} workflow={@props.workflow} name="#{@props.taskPrefix}.next" value={@props.task.next ? ''} onChange={handleInputChange.bind @props.workflow} />
</AutoSave>
</p>

Expand Down
3 changes: 2 additions & 1 deletion app/classifier/tasks/text/editor.cjsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = createReactClass


render: ->
[root, taskKey] = @props.taskPrefix.split '.'
handleChange = handleInputChange.bind @props.workflow
requiredHelp = 'Check this box if this question has to be answered before proceeding. If a marking task is Required, the volunteer will not be able to move on until they have made at least 1 mark.'

Expand Down Expand Up @@ -86,6 +87,6 @@ module.exports = createReactClass
<AutoSave resource={@props.workflow}>
<span className="form-label">Next task</span>
<br />
<NextTaskSelector task={@props.task} workflow={@props.workflow} name="#{@props.taskPrefix}.next" value={@props.task.next ? ''} onChange={handleInputChange.bind @props.workflow} />
<NextTaskSelector taskKey={taskKey} workflow={@props.workflow} name="#{@props.taskPrefix}.next" value={@props.task.next ? ''} onChange={handleInputChange.bind @props.workflow} />
</AutoSave>}
</div>
3 changes: 2 additions & 1 deletion app/classifier/tasks/textFromSubject/editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default function TextFromSubjectEditor({
taskPrefix,
workflow
}) {
const [root, taskKey] = taskPrefix.split('.');
const handleChange = handleInputChange.bind(workflow);

return (
Expand Down Expand Up @@ -64,7 +65,7 @@ export default function TextFromSubjectEditor({
</span>
<br />
<NextTaskSelector
task={task}
taskKey={taskKey}
workflow={workflow}
name={`${taskPrefix}.next`}
value={task.next}
Expand Down

0 comments on commit c440edc

Please sign in to comment.