Skip to content

Commit

Permalink
Convert bulk action endpoints from GET to POST (statamic#3298)
Browse files Browse the repository at this point in the history
  • Loading branch information
jelleroorda authored Jun 10, 2021
1 parent 74c18fc commit 0844f27
Show file tree
Hide file tree
Showing 18 changed files with 37 additions and 54 deletions.
16 changes: 7 additions & 9 deletions resources/js/components/assets/Browser/Browser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<breadcrumbs :path="path" @navigated="selectFolder" />

<data-list-bulk-actions
:url="bulkActionsUrl"
:url="actionUrl"
:context="actionContext"
:show-always="mode === 'grid'"
@started="actionStarted"
Expand Down Expand Up @@ -128,7 +128,7 @@

<data-list-inline-actions
:item="folder.path"
:url="runFolderActionUrl"
:url="folderActionUrl"
:actions="folderActions(folder)"
@started="actionStarted"
@completed="actionCompleted"
Expand Down Expand Up @@ -162,7 +162,7 @@
<div class="divider" v-if="asset.actions.length" />
<data-list-inline-actions
:item="asset.id"
:url="runActionUrl"
:url="actionUrl"
:actions="asset.actions"
@started="actionStarted"
@completed="actionCompleted"
Expand Down Expand Up @@ -302,9 +302,8 @@ export default {
sortColumn: 'basename',
sortDirection: 'asc',
mode: 'table',
runActionUrl: null,
bulkActionsUrl: null,
runFolderActionUrl: null,
actionUrl: null,
folderActionUrl: null,
}
},
Expand Down Expand Up @@ -466,9 +465,8 @@ export default {
} else {
this.folder = data.data.folder;
this.folders = data.data.folder.folders;
this.runActionUrl = data.links.run_asset_action;
this.bulkActionsUrl = data.links.bulk_asset_actions;
this.runFolderActionUrl = data.links.run_folder_action;
this.actionUrl = data.links.asset_action;
this.folderActionUrl = data.links.folder_action;
}
this.loadingAssets = false;
Expand Down
4 changes: 2 additions & 2 deletions resources/js/components/assets/Editor/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
v-if="actions.length"
:id="id"
:actions="actions"
:url="runActionUrl"
:url="actionUrl"
@started="actionStarted"
@completed="actionCompleted" />
</portal>
Expand Down Expand Up @@ -288,7 +288,7 @@ export default {
this.asset = data;
this.values = data.values;
this.meta = data.meta;
this.runActionUrl = data.runActionUrl;
this.actionUrl = data.actionUrl;
this.actions = data.actions;
this.fieldset = data.blueprint;
Expand Down
6 changes: 2 additions & 4 deletions resources/js/components/collections/View.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@
:initial-sort-direction="sortDirection"
:initial-columns="columns"
:filters="filters"
:run-action-url="runActionUrl"
:bulk-actions-url="bulkActionsUrl"
:action-url="actionUrl"
:reordering="reordering"
:reorder-url="reorderUrl"
:site="site"
Expand Down Expand Up @@ -190,8 +189,7 @@ export default {
sortDirection: { type: String, required: true },
columns: { type: Array, required: true },
filters: { type: Array, required: true },
runActionUrl: { type: String, required: true },
bulkActionsUrl: { type: String, required: true },
actionUrl: { type: String, required: true },
reorderUrl: { type: String, required: true },
initialSite: { type: String, required: true },
sites: { type: Array },
Expand Down
12 changes: 3 additions & 9 deletions resources/js/components/data-list/BulkActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

<script>
import Actions from './Actions';
import qs from 'qs';
export default {
Expand Down Expand Up @@ -77,20 +76,15 @@ export default {
return;
}
let params = {
let data = {
selections: this.selections,
};
if (this.context) {
params.context = this.context;
data.context = this.context;
}
let config = {
params,
paramsSerializer: params => qs.stringify(params, {arrayFormat: 'brackets'})
};
this.$axios.get(this.url, config).then(response => {
this.$axios.post(this.url+'/list', data).then(response => {
this.actions = response.data;
});
},
Expand Down
3 changes: 1 addition & 2 deletions resources/js/components/data-list/HasActions.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
export default {

props: {
runActionUrl: String,
bulkActionsUrl: String,
actionUrl: String,
},

methods: {
Expand Down
4 changes: 2 additions & 2 deletions resources/js/components/entries/Listing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<div v-show="items.length === 0" class="p-3 text-center text-grey-50" v-text="__('No results')" />

<data-list-bulk-actions
:url="bulkActionsUrl"
:url="actionUrl"
@started="actionStarted"
@completed="actionCompleted"
/>
Expand Down Expand Up @@ -80,7 +80,7 @@
<div class="divider" v-if="entry.actions.length" />
<data-list-inline-actions
:item="entry.id"
:url="runActionUrl"
:url="actionUrl"
:actions="entry.actions"
@started="actionStarted"
@completed="actionCompleted"
Expand Down
4 changes: 2 additions & 2 deletions resources/js/components/forms/SubmissionListing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<div v-show="items.length === 0" class="p-3 text-center text-grey-50" v-text="__('No results')" />

<data-list-bulk-actions
:url="bulkActionsUrl"
:url="actionUrl"
@started="actionStarted"
@completed="actionCompleted"
/>
Expand All @@ -49,7 +49,7 @@
<dropdown-item :text="__('View')" :redirect="submission.url" />
<data-list-inline-actions
:item="submission.id"
:url="runActionUrl"
:url="actionUrl"
:actions="submission.actions"
@started="actionStarted"
@completed="actionCompleted"
Expand Down
4 changes: 2 additions & 2 deletions resources/js/components/terms/Listing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<div v-show="items.length === 0" class="p-3 text-center text-grey-50" v-text="__('No results')" />

<data-list-bulk-actions
:url="bulkActionsUrl"
:url="actionUrl"
@started="actionStarted"
@completed="actionCompleted"
/>
Expand Down Expand Up @@ -74,7 +74,7 @@
<div class="divider" />
<data-list-inline-actions
:item="term.id"
:url="runActionUrl"
:url="actionUrl"
:actions="term.actions"
@started="actionStarted"
@completed="actionCompleted"
Expand Down
4 changes: 2 additions & 2 deletions resources/js/components/users/Listing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<div class="card p-0 relative">
<data-list-bulk-actions
class="rounded"
:url="bulkActionsUrl"
:url="actionUrl"
@started="actionStarted"
@completed="actionCompleted"
/>
Expand All @@ -39,7 +39,7 @@
<dropdown-item :text="__('View')" :redirect="user.edit_url" v-else />
<data-list-inline-actions
:item="user.id"
:url="runActionUrl"
:url="actionUrl"
:actions="user.actions"
@started="actionStarted"
@completed="actionCompleted"
Expand Down
3 changes: 1 addition & 2 deletions resources/views/collections/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
sort-direction="{{ $collection->sortDirection() }}"
:columns="{{ $columns->toJson() }}"
:filters="{{ $filters->toJson() }}"
run-action-url="{{ cp_route('collections.entries.actions.run', $collection->handle()) }}"
bulk-actions-url="{{ cp_route('collections.entries.actions.bulk', $collection->handle()) }}"
action-url="{{ cp_route('collections.entries.actions.run', $collection->handle()) }}"
reorder-url="{{ cp_route('collections.entries.reorder', $collection->handle()) }}"
initial-site="{{ $site }}"
:sites="{{ json_encode($sites) }}"
Expand Down
3 changes: 1 addition & 2 deletions resources/views/forms/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@

<form-submission-listing
form="{{ $form->handle() }}"
run-action-url="{{ cp_route('forms.submissions.actions.run', $form->handle()) }}"
bulk-actions-url="{{ cp_route('forms.submissions.actions.bulk', $form->handle()) }}"
action-url="{{ cp_route('forms.submissions.actions.run', $form->handle()) }}"
initial-sort-column="datestamp"
initial-sort-direction="desc"
:initial-columns="{{ $columns->toJson() }}"
Expand Down
3 changes: 1 addition & 2 deletions resources/views/taxonomies/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@
initial-sort-direction="{{ $taxonomy->sortDirection() }}"
:initial-columns="{{ $columns->toJson() }}"
:filters="{{ $filters->toJson() }}"
run-action-url="{{ cp_route('taxonomies.terms.actions.run', $taxonomy->handle()) }}"
bulk-actions-url="{{ cp_route('taxonomies.terms.actions.bulk', $taxonomy->handle()) }}"
action-url="{{ cp_route('taxonomies.terms.actions.run', $taxonomy->handle()) }}"
></term-list>

@else
Expand Down
3 changes: 1 addition & 2 deletions resources/views/usergroups/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
listing-key="usergroup-users"
group="{{ $group->id() }}"
:filters="{{ $filters->toJson() }}"
run-action-url="{{ cp_route('users.actions.run') }}"
bulk-actions-url="{{ cp_route('users.actions.bulk') }}"
action-url="{{ cp_route('users.actions.run') }}"
></user-listing>

@endsection
3 changes: 1 addition & 2 deletions resources/views/users/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
initial-sort-column="email"
initial-sort-direction="asc"
:filters="{{ $filters->toJson() }}"
run-action-url="{{ cp_route('users.actions.run') }}"
bulk-actions-url="{{ cp_route('users.actions.bulk') }}"
action-url="{{ cp_route('users.actions.run') }}"
></user-listing>

@include('statamic::partials.docs-callout', [
Expand Down
10 changes: 5 additions & 5 deletions routes/cp.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
Route::group(['prefix' => 'collections/{collection}/entries'], function () {
Route::get('/', 'EntriesController@index')->name('collections.entries.index');
Route::post('actions', 'EntryActionController@run')->name('collections.entries.actions.run');
Route::get('actions', 'EntryActionController@bulkActions')->name('collections.entries.actions.bulk');
Route::post('actions/list', 'EntryActionController@bulkActions')->name('collections.entries.actions.bulk');
Route::get('create/{site}', 'EntriesController@create')->name('collections.entries.create');
Route::post('create/{site}/preview', 'EntryPreviewController@create')->name('collections.entries.preview.create');
Route::post('reorder', 'ReorderEntriesController')->name('collections.entries.reorder');
Expand Down Expand Up @@ -77,7 +77,7 @@
Route::group(['prefix' => 'taxonomies/{taxonomy}/terms'], function () {
Route::get('/', 'TermsController@index')->name('taxonomies.terms.index');
Route::post('actions', 'TermActionController@run')->name('taxonomies.terms.actions.run');
Route::get('actions', 'TermActionController@bulkActions')->name('taxonomies.terms.actions.bulk');
Route::post('actions/list', 'TermActionController@bulkActions')->name('taxonomies.terms.actions.bulk');
Route::get('create/{site}', 'TermsController@create')->name('taxonomies.terms.create');
Route::post('create/{site}/preview', 'TermPreviewController@create')->name('taxonomies.terms.preview.create');
Route::post('{site}', 'TermsController@store')->name('taxonomies.terms.store');
Expand Down Expand Up @@ -122,7 +122,7 @@
Route::get('asset-containers/{asset_container}/blueprint', 'AssetContainerBlueprintController@edit')->name('asset-containers.blueprint.edit');
Route::patch('asset-containers/{asset_container}/blueprint', 'AssetContainerBlueprintController@update')->name('asset-containers.blueprint.update');
Route::post('assets/actions', 'ActionController@run')->name('assets.actions.run');
Route::get('assets/actions', 'ActionController@bulkActions')->name('assets.actions.bulk');
Route::post('assets/actions/list', 'ActionController@bulkActions')->name('assets.actions.bulk');
Route::get('assets/browse', 'BrowserController@index')->name('assets.browse.index');
Route::get('assets/browse/search/{asset_container}', 'BrowserController@search');
Route::post('assets/browse/folders/{asset_container}/actions', 'FolderActionController@run')->name('assets.folders.actions.run');
Expand Down Expand Up @@ -169,7 +169,7 @@

Route::group(['namespace' => 'Forms'], function () {
Route::post('forms/{form}/submissions/actions', 'SubmissionActionController@run')->name('forms.submissions.actions.run');
Route::get('forms/{form}/submissions/actions', 'SubmissionActionController@bulkActions')->name('forms.submissions.actions.bulk');
Route::post('forms/{form}/submissions/actions/list', 'SubmissionActionController@bulkActions')->name('forms.submissions.actions.bulk');
Route::resource('forms', 'FormsController');
Route::resource('forms.submissions', 'FormSubmissionsController');
Route::get('forms/{form}/export/{type}', 'FormExportController@export')->name('forms.export');
Expand All @@ -179,7 +179,7 @@

Route::group(['namespace' => 'Users'], function () {
Route::post('users/actions', 'UserActionController@run')->name('users.actions.run');
Route::get('users/actions', 'UserActionController@bulkActions')->name('users.actions.bulk');
Route::post('users/actions/list', 'UserActionController@bulkActions')->name('users.actions.bulk');
Route::get('users/blueprint', 'UserBlueprintController@edit')->name('users.blueprint.edit');
Route::patch('users/blueprint', 'UserBlueprintController@update')->name('users.blueprint.update');
Route::resource('users', 'UsersController');
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Resources/CP/Assets/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function toArray($request)
$this->merge($this->publishFormData()),

'allowDownloading' => $this->container()->allowDownloading(),
'runActionUrl' => cp_route('assets.actions.run'),
'actionUrl' => cp_route('assets.actions.run'),
'actions' => Action::for($this->resource, ['container' => $this->container()->handle()]),

'blueprint' => $this->blueprint()->toPublishArray(),
Expand Down
5 changes: 2 additions & 3 deletions src/Http/Resources/CP/Assets/FolderAssetsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ public function with($request)
{
return [
'links' => [
'run_asset_action' => cp_route('assets.actions.run'),
'bulk_asset_actions' => cp_route('assets.actions.bulk'),
'run_folder_action' => cp_route('assets.folders.actions.run', $this->folder->container()->id()),
'asset_action' => cp_route('assets.actions.run'),
'folder_action' => cp_route('assets.folders.actions.run', $this->folder->container()->id()),
],
];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/Assets/BrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ private function jsonStructure()
{
return [
'meta',
'links' => ['run_folder_action', 'run_asset_action'],
'links' => ['folder_action', 'asset_action'],
'data' => [
'assets' => [
['id', 'size_formatted', 'last_modified_relative', 'actions'],
Expand Down

0 comments on commit 0844f27

Please sign in to comment.