Skip to content

Commit 131b632

Browse files
committed
Fix an issue where status couldn’t be updated when editing a submission in the control panel
1 parent 4151521 commit 131b632

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

src/controllers/SubmissionsController.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use verbb\workflow\Workflow;
55
use verbb\workflow\elements\Submission;
6+
use verbb\workflow\models\Review;
67

78
use Craft;
89
use craft\db\Table;
@@ -48,9 +49,34 @@ public function actionSaveSubmission(): ?Response
4849

4950
$request = Craft::$app->getRequest();
5051
$session = Craft::$app->getSession();
52+
$currentUser = Craft::$app->getUser()->getIdentity();
5153

5254
$submissionId = $request->getParam('submissionId');
5355
$submission = Craft::$app->getElements()->getElementById($submissionId);
56+
$status = $request->getParam('status');
57+
58+
if (!$submission) {
59+
$session->setError(Craft::t('workflow', 'Unable to find submission.'));
60+
61+
return null;
62+
}
63+
64+
// Skip if there's nothing to change
65+
if ($submission->status !== $status) {
66+
// If trying to approve their own submission, fail
67+
if ($status === Review::STATUS_APPROVED && $submission->editorId === $currentUser->id) {
68+
$session->setError(Craft::t('workflow', 'You cannot approve your own submission.'));
69+
70+
Craft::$app->getUrlManager()->setRouteParams([
71+
'submission' => $submission,
72+
'errors' => $submission->getErrors(),
73+
]);
74+
75+
return null;
76+
} else {
77+
Workflow::$plugin->getSubmissions()->triggerSubmissionStatus($status, $submission);
78+
}
79+
}
5480

5581
if (!Craft::$app->getElements()->saveElement($submission)) {
5682
$session->setError(Craft::t('workflow', 'Unable to save submission.'));
@@ -63,7 +89,7 @@ public function actionSaveSubmission(): ?Response
6389
return null;
6490
}
6591

66-
$session->setNotice(Craft::t('workflow', 'Comment saved successfully.'));
92+
$session->setNotice(Craft::t('workflow', 'Submission saved successfully.'));
6793

6894
return $this->redirectToPostedUrl($submission);
6995
}

src/templates/submissions/_edit.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ <h5 class="heading">{{ 'Updated at' | t('app') }}</h5>
220220
onOptionSelect: function(data) {
221221
var value = $(data).data('value');
222222
var label = $(data).data('label');
223-
$('#statusId').val(value);
223+
$('[name="status"]').val(value);
224224

225225
var html = '<span class="status ' + value + '"></span>' + label;
226226
$statusSelect.html(html);

src/translations/en/workflow.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
'This content has been changed.' => 'This content has been changed.',
140140
'This content has been removed.' => 'This content has been removed.',
141141
'Unable to save submission.' => 'Unable to save submission.',
142-
'Comment saved successfully.' => 'Comment saved successfully.',
142+
'Submission saved successfully.' => 'Submission saved successfully.',
143143
'Unable to delete submission.' => 'Unable to delete submission.',
144144
'Submission deleted.' => 'Submission deleted.',
145145
'Unable to delete review.' => 'Unable to delete review.',

0 commit comments

Comments
 (0)