Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read-only Publish toggle on Entries #3039

Merged
merged 5 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions resources/js/components/entries/BaseCreateForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
:revisions-enabled="revisions"
:breadcrumbs="breadcrumbs"
:initial-site="site"
:can-manage-publish-state="canManagePublishState"
:create-another-url="createAnotherUrl"
:listing-url="listingUrl"
@saved="saved"
Expand All @@ -37,6 +38,7 @@ export default {
'revisions',
'breadcrumbs',
'site',
'canManagePublishState',
'createAnotherUrl',
'listingUrl',
],
Expand Down
3 changes: 2 additions & 1 deletion resources/js/components/entries/PublishForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@

<div class="flex items-center border-t justify-between px-2 py-1" v-if="!revisionsEnabled">
<label v-text="__('Published')" class="publish-field-label font-medium" />
<toggle-input :value="published" @input="setFieldValue('published', $event)" />
<toggle-input :value="published" :read-only="!canManagePublishState" @input="setFieldValue('published', $event)" />
</div>

<div class="border-t p-2" v-if="revisionsEnabled && !isCreating">
Expand Down Expand Up @@ -297,6 +297,7 @@ export default {
revisionsEnabled: Boolean,
preloadedAssets: Array,
canEditBlueprint: Boolean,
canManagePublishState: Boolean,
createAnotherUrl: String,
listingUrl: String,
},
Expand Down
1 change: 1 addition & 0 deletions resources/views/entries/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
site="{{ $locale }}"
create-another-url="{{ cp_route('collections.entries.create', [$collection, $locale, 'blueprint' => $blueprint['handle']]) }}"
listing-url="{{ cp_route('collections.show', $collection) }}"
:can-manage-publish-state="{{ Statamic\Support\Str::bool($canManagePublishState) }}"
></base-entry-create-form>

@endsection
1 change: 1 addition & 0 deletions resources/views/entries/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
:preloaded-assets="{{ json_encode($preloadedAssets) }}"
:breadcrumbs="{{ $breadcrumbs->toJson() }}"
:can-edit-blueprint="{{ $str::bool($user->can('configure fields')) }}"
:can-manage-publish-state="{{ $str::bool($canManagePublishState) }}"
create-another-url="{{ cp_route('collections.entries.create', [$collection, $locale]) }}"
listing-url="{{ cp_route('collections.show', $collection) }}"
></entry-publish-form>
Expand Down
1 change: 1 addition & 0 deletions src/Fieldtypes/Entries.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Entries extends Relationship
'revisionsEnabled' => 'revisionsEnabled',
'breadcrumbs' => 'breadcrumbs',
'collectionHandle' => 'collection',
'canManagePublishState' => 'canManagePublishState',
];

protected function configFieldItems(): array
Expand Down
4 changes: 3 additions & 1 deletion src/Http/Controllers/CP/Collections/EntriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public function edit(Request $request, $collection, $entry)
'preloadedAssets' => $this->extractAssetsFromValues($values),
'revisionsEnabled' => $entry->revisionsEnabled(),
'breadcrumbs' => $this->breadcrumbs($collection),
'canManagePublishState' => User::current()->can('publish', $entry),
];

if ($request->wantsJson()) {
Expand Down Expand Up @@ -189,7 +190,7 @@ public function update(Request $request, $collection, $entry)
->user(User::current())
->save();
} else {
if (! $entry->revisionsEnabled()) {
if (! $entry->revisionsEnabled() && User::current()->can('publish', $entry)) {
$entry->published($request->published);
}

Expand Down Expand Up @@ -254,6 +255,7 @@ public function create(Request $request, $collection, $site)
})->all(),
'revisionsEnabled' => $collection->revisionsEnabled(),
'breadcrumbs' => $this->breadcrumbs($collection),
'canManagePublishState' => User::current()->can('publish '.$collection->handle().' entries'),
];

if ($request->wantsJson()) {
Expand Down
8 changes: 8 additions & 0 deletions tests/Feature/Entries/StoreEntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ public function validation_error_returns_back()
$this->assertCount(0, Entry::all());
}

/** @test */
public function user_without_permission_to_manage_publish_state_cannot_change_publish_status()
{
// when revisions are disabled

$this->markTestIncomplete();
}

private function store($payload)
{
return $this->post(cp_route('collections.entries.store', ['blog', 'en']), $payload);
Expand Down
8 changes: 8 additions & 0 deletions tests/Feature/Entries/UpdateEntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ public function validation_error_returns_back()
], $entry->data());
}

/** @test */
public function user_without_permission_to_manage_publish_state_cannot_change_publish_status()
{
// when revisions are disabled

$this->markTestIncomplete();
}

private function save($entry, $payload)
{
return $this->patch($entry->updateUrl(), $payload);
Expand Down