Skip to content

Commit 2fa251e

Browse files
authored
Merge pull request #12255 from Vitaliy-1/i11912_creator_validate
#11912 Task/Discussion creator should be a participant
2 parents c9aaf57 + d709eb6 commit 2fa251e

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

api/v1/submissions/tasks/formRequests/AddTask.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,9 @@ protected function getStageId(): int
6161
{
6262
return (int) $this->input('stageId');
6363
}
64+
65+
protected function getCreatorId(): int
66+
{
67+
return (int) $this->input('createdBy');
68+
}
6469
}

api/v1/submissions/tasks/formRequests/EditTask.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,22 @@ function (string $attribute, array $value, Closure $fail) {
160160
if ($this->input('type') == EditorialTaskType::DISCUSSION->value && count($value) < 2) {
161161
$fail(__('submission.task.validation.error.participants.required'));
162162
}
163+
},
164+
165+
// Check if the task creator is among participants
166+
function (string $attribute, array $value, Closure $fail) {
167+
$participantIds = Arr::pluck($this->input('participants'), 'userId');
168+
$creatorId = $this->getCreatorId();
169+
170+
if ($creatorId === null) {
171+
return true; // We allow absent creator when task is automatically created
172+
}
173+
174+
if (!in_array($this->getCreatorId(), $participantIds)) {
175+
return $fail(__('submission.task.validation.error.participant.creator'));
176+
}
177+
178+
return true;
163179
}
164180
],
165181
EditorialTask::ATTRIBUTE_PARTICIPANTS . '.*' => [
@@ -263,4 +279,9 @@ protected function getStageId(): int
263279
{
264280
return $this->task->stageId;
265281
}
282+
283+
protected function getCreatorId(): ?int
284+
{
285+
return $this->task->createdBy;
286+
}
266287
}

locale/en/submission.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,6 +2327,9 @@ msgstr "You can update this discussion for {$allowedEditTimeNoticeLimit} minutes
23272327
msgid "submission.task.validation.error.participant.responsible"
23282328
msgstr "There should be one user responsible for the task."
23292329

2330+
msgid "submission.task.validation.error.participant.creator"
2331+
msgstr "The creator must participate in the task/discussion."
2332+
23302333
msgid "submission.task.validation.error.reviewer.anonymous"
23312334
msgstr "Cannot disclose the identity of reviewers in the task/discussion."
23322335

0 commit comments

Comments
 (0)