Ghost/ghost/admin/app/adapters/base.js
Fabien 'egg' O'Carroll 28a2caec98 Updated delete member UI to add toggle to cancel subscriptions (#1647)
no-issue

* Supported cancellation of subscriptions on delete

This makes the cancellation of subscriptions much more obvious to the
user, and we err on the side of caution by *not* cancelling by default.

* Updated base adapter to handle urls with query params

After creating the member adapter and overriding the urlForDeleteRecord
method the flow would take the url from that and it would get passed
into the buildUrl method of the base adapter. At this point it would
append a "/" _after_ the query param.

It would ouput http://admin.com/ghost/api?query=blah/
rather than http://admin.com/ghost/api/?query=blah
2020-07-24 16:02:42 +02:00

40 lines
1.0 KiB
JavaScript

import AjaxServiceSupport from 'ember-ajax/mixins/ajax-support';
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';
import RESTAdapter from '@ember-data/adapter/rest';
import ghostPaths from 'ghost-admin/utils/ghost-paths';
import {inject as service} from '@ember/service';
export default RESTAdapter.extend(DataAdapterMixin, AjaxServiceSupport, {
host: window.location.origin,
namespace: ghostPaths().apiRoot.slice(1),
session: service(),
shouldBackgroundReloadRecord() {
return false;
},
query(store, type, query) {
let id;
if (query.id) {
id = query.id;
delete query.id;
}
return this.ajax(this.buildURL(type.modelName, id), 'GET', {data: query});
},
buildURL() {
// Ensure trailing slashes
let url = this._super(...arguments);
let parsedUrl = new URL(url);
if (!parsedUrl.pathname.endsWith('/')) {
parsedUrl.pathname += '/';
}
return parsedUrl.toString();
}
});