Skip to content

Commit

Permalink
Add read-only state for submission detail pages for editors to view s…
Browse files Browse the repository at this point in the history
…ubmission detail
  • Loading branch information
engram-design committed Nov 21, 2023
1 parent 1088f56 commit 02a4d4b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 21 deletions.
12 changes: 12 additions & 0 deletions src/controllers/SubmissionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public function actionEdit(?Submission $submission, ?int $submissionId = null):
{
$this->requireCpRequest();

$settings = Workflow::$plugin->getSettings();
$currentUser = Craft::$app->getUser()->getIdentity();

if ($submission === null) {
$submission = Submission::find()->id($submissionId)->siteId('*')->one();

Expand All @@ -32,9 +35,18 @@ public function actionEdit(?Submission $submission, ?int $submissionId = null):
}
}

$canEdit = true;
$editorGroup = $settings->getEditorUserGroup($submission->site);

if ($editorGroup && $currentUser && $currentUser->isInGroup($editorGroup)) {
$canEdit = false;
}

$variables = [
'submission' => $submission,
'title' => $submission->title,
'settings' => $settings,
'canEdit' => $canEdit,
];

$variables['changesCount'] = Workflow::$plugin->getContent()->getContentChangesTotalCount($submission);
Expand Down
46 changes: 25 additions & 21 deletions src/templates/submissions/_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
] %}

{% set isNew = submission.id ? false : true %}
{% set fullPageForm = true %}
{% set fullPageForm = canEdit %}
{% set saveShortcutRedirect = '{cpEditUrl}' %}

{% set numberReviews = 0 %}
Expand All @@ -28,30 +28,32 @@

{% block actionButton %}

<div class="buttons">
<div class="btngroup submit">
<input type="submit" class="btn submit" value="{{ 'Save' | t('workflow') }}">

<div class="btn submit menubtn"></div>
<div class="menu">
<ul>
<li>
<a class="formsubmit" data-redirect="{{ saveShortcutRedirect | hash }}">
{{ 'Save and continue editing' | t('app') }}
<span class="shortcut">⌘S</span>
</a>
</li>
</ul>
{% if canEdit %}
<div class="buttons">
<div class="btngroup submit">
<input type="submit" class="btn submit" value="{{ 'Save' | t('workflow') }}">

{% if not isNew %}
<hr>
<div class="btn submit menubtn"></div>
<div class="menu">
<ul>
<li><a class="formsubmit error" data-action="workflow/submissions/delete-submission" data-confirm="{{ 'Are you sure you want to delete this submission?' | t('workflow') }}" data-redirect="{{ 'workflow/submissions' | hash }}">{{ 'Delete' | t('app') }}</a></li>
<li>
<a class="formsubmit" data-redirect="{{ saveShortcutRedirect | hash }}">
{{ 'Save and continue editing' | t('app') }}
<span class="shortcut">⌘S</span>
</a>
</li>
</ul>
{% endif %}

{% if not isNew %}
<hr>
<ul>
<li><a class="formsubmit error" data-action="workflow/submissions/delete-submission" data-confirm="{{ 'Are you sure you want to delete this submission?' | t('workflow') }}" data-redirect="{{ 'workflow/submissions' | hash }}">{{ 'Delete' | t('app') }}</a></li>
</ul>
{% endif %}
</div>
</div>
</div>
</div>
{% endif %}

{% endblock %}

Expand Down Expand Up @@ -112,7 +114,9 @@
<li><a href="{{ cpUrl('workflow/reviews/compare/' ~ review.id ~ ':' ~ previousReview.id) }}">{{ 'Compare' | t('app') }}</a></li>
{% endif %}

<li><a class="formsubmit error" data-action="workflow/reviews/delete-review" data-param="reviewId" data-value="{{ review.id }}" data-confirm="{{ 'Are you sure you want to delete this review?' | t('workflow') }}" data-redirect="{{ craft.app.request.url | hash }}">{{ 'Delete' | t('app') }}</a></li>
{% if canEdit %}
<li><a class="formsubmit error" data-action="workflow/reviews/delete-review" data-param="reviewId" data-value="{{ review.id }}" data-confirm="{{ 'Are you sure you want to delete this review?' | t('workflow') }}" data-redirect="{{ craft.app.request.url | hash }}">{{ 'Delete' | t('app') }}</a></li>
{% endif %}
</ul>
</div>
</div>
Expand Down

0 comments on commit 02a4d4b

Please sign in to comment.