Skip to content

Commit

Permalink
Hide a bunch of stuff when the user is missing edit permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean committed Jan 5, 2024
1 parent b4150b3 commit 6fcff42
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 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 v-if="$slots.twirldown" 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
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
21 changes: 11 additions & 10 deletions resources/views/navigation/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@section('title', Statamic::crumb($nav->title(), 'Navigation'))

@section('content')

<navigation-view
title="{{ $nav->title() }}"
handle="{{ $nav->handle() }}"
Expand All @@ -16,16 +17,16 @@
:max-depth="{{ $nav->maxDepth() ?? 'Infinity' }}"
:expects-root="{{ $str::bool($expectsRoot) }}"
:blueprint="{{ json_encode($blueprint) }}"
:can-edit="{{ Statamic\Support\Str::bool($user->can('edit', $nav)) }}"
>
@if(Auth::user()->can('edit', $nav) || Auth::user()->can('configure fields'))
<template #twirldown>
@can('edit', $nav)
<dropdown-item :text="__('Edit Navigation')" redirect="{{ $nav->editUrl() }}"></dropdown-item>
@endcan
@can('configure fields')
<dropdown-item :text="__('Edit Blueprint')" redirect="{{ cp_route('navigation.blueprint.edit', $nav->handle()) }}"></dropdown-item>
@endcan
</template>
@endif
<template #twirldown>
@can('edit', $nav)
<dropdown-item :text="__('Edit Navigation')" redirect="{{ $nav->editUrl() }}"></dropdown-item>
@endcan
@can('configure fields')
<dropdown-item :text="__('Edit Blueprint')" redirect="{{ cp_route('navigation.blueprint.edit', $nav->handle()) }}"></dropdown-item>
@endcan
</template>
</navigation-view>

@endsection

0 comments on commit 6fcff42

Please sign in to comment.