Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lab): prevent tasks linking to themselves #7097

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions .mocharc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ module.exports = {
'@babel/register',
'coffeescript/register',
'coffee-react/register'
]
}
],
retries: 1
}
4 changes: 3 additions & 1 deletion app/classifier/tasks/combo/editor.cjsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ComboTaskEditor = createReactClass
getDefaultProps: ->
workflow: null
task: null
taskPrefix: ''
onChange: ->

componentWillMount: () ->
Expand Down Expand Up @@ -47,6 +48,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 +79,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
4 changes: 3 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 Expand Up @@ -248,5 +249,6 @@ DropdownEditor.propTypes = {

DropdownEditor.defaultProps = {
task: {},
taskPrefix: '',
workflow: {}
};
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
4 changes: 3 additions & 1 deletion app/classifier/tasks/text/editor.cjsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = createReactClass
getDefaultProps: ->
workflow: {}
task: {}
taskPrefix: ''

tagExists:(tag) ->
if @props.task.text_tags
Expand All @@ -31,6 +32,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 +88,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
Loading
Loading