Skip to content

Commit

Permalink
[4.x] Prevent users without "edit" permission editing navs (#9265)
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean authored Jan 5, 2024
1 parent a760cfc commit 47a6a96
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
13 changes: 9 additions & 4 deletions resources/js/components/navigation/View.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="flex items-center">
<h1 class="flex-1" v-text="__(title)" />

<dropdown-list class="mr-2">
<dropdown-list v-if="editable" class="mr-2">
<slot name="twirldown" />
</dropdown-list>

Expand All @@ -22,7 +22,7 @@
@input="siteSelected"
/>

<dropdown-list :disabled="! hasCollections">
<dropdown-list v-if="canEdit" :disabled="! hasCollections">
<template #trigger>
<button
class="btn"
Expand All @@ -38,6 +38,7 @@
</dropdown-list>

<button
v-if="canEdit"
class="btn-primary ml-4"
:class="{ 'disabled': !changed }"
:disabled="!changed"
Expand All @@ -55,6 +56,7 @@
:expects-root="expectsRoot"
:site="site"
:preferences-prefix="preferencesPrefix"
:editable="canEdit"
@edit-page="editPage"
@changed="changed = true; targetParent = null;"
@saved="treeSaved"
Expand Down Expand Up @@ -101,7 +103,7 @@
<svg-icon v-if="isTextBranch(branch)" class="inline-block w-4 h-4 text-gray-500" name="light/file-text" v-tooltip="__('Text')" />
</template>

<template #branch-options="{ branch, removeBranch, orphanChildren, vm, depth }">
<template v-if="canEdit" #branch-options="{ branch, removeBranch, orphanChildren, vm, depth }">
<dropdown-item
v-if="isEntryBranch(branch)"
:text="__('Edit Entry')"
Expand Down Expand Up @@ -138,6 +140,7 @@
:publish-info="publishInfo[editingPage.page.id]"
:blueprint="blueprint"
:handle="handle"
:read-only="!canEdit"
@publish-info-updated="updatePublishInfo"
@localized-fields-updated="updateLocalizedFields"
@closed="closePageEditor"
Expand All @@ -150,6 +153,7 @@
:site="site"
:blueprint="blueprint"
:handle="handle"
:read-only="!canEdit"
@publish-info-updated="updatePendingCreatedPagePublishInfo"
@localized-fields-updated="updatePendingCreatedPageLocalizedFields"
@closed="closePageCreator"
Expand Down Expand Up @@ -197,7 +201,8 @@ export default {
expectsRoot: { type: Boolean, required: true },
site: { type: String, required: true },
sites: { type: Array, required: true },
blueprint: { type: Object, required: true }
blueprint: { type: Object, required: true },
canEdit: { type: Boolean, required: true }
},
data() {
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/structures/Branch.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>

<div class="flex">
<slot name="branch-action" :branch="page">
<slot name="branch-action" :branch="page" v-if="editable">
<div class="page-move w-6" />
</slot>
<div class="flex items-center flex-1 p-2 ml-2 text-xs leading-normal">
Expand Down
10 changes: 5 additions & 5 deletions resources/js/components/structures/PageEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
<loading-graphic text="" />
</div>


<publish-sections
:sections="adjustedBlueprint.tabs[0].sections"
:syncable="type == 'entry'"
:syncable-fields="syncableFields"
:read-only="readOnly"
@updated="setFieldValue"
@meta-updated="setFieldMeta"
@synced="syncField"
Expand All @@ -54,8 +54,8 @@

</div>

<div v-if="!loading" class="bg-gray-200 p-4 border-t flex items-center justify-between flex-row-reverse">
<div>
<div v-if="!loading && (!readOnly || type === 'entry')" class="bg-gray-200 p-4 border-t flex items-center justify-between flex-row-reverse">
<div v-if="!readOnly">
<button @click="confirmClose(close)" class="btn mr-2">{{ __('Cancel') }}</button>
<button @click="submit" class="btn-primary">{{ __('Submit') }}</button>
</div>
Expand All @@ -65,7 +65,6 @@
{{ __('Edit Entry') }}
</a>
</div>

</div>

</div>
Expand All @@ -84,7 +83,8 @@ export default {
blueprint: Object,
handle: String,
editEntryUrl: String,
creating: Boolean
creating: Boolean,
readOnly: Boolean,
},
data() {
Expand Down
1 change: 1 addition & 0 deletions resources/views/navigation/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
:max-depth="{{ $nav->maxDepth() ?? 'Infinity' }}"
:expects-root="{{ $str::bool($expectsRoot) }}"
:blueprint="{{ json_encode($blueprint) }}"
:can-edit="{{ Statamic\Support\Str::bool($user->can('edit', $nav)) }}"
>
<template #twirldown>
@can('edit', $nav)
Expand Down

0 comments on commit 47a6a96

Please sign in to comment.