mirror of
https://github.com/TryGhost/Ghost-Admin.git
synced 2023-12-14 02:33:04 +01:00
7ce3726589
no issue - add ember-suave dependency - upgrade grunt-jscs dependency - add a new .jscsrc for the client's tests directory that extends from client's base .jscsrc - separate client tests in Gruntfile jscs task so they pick up the test's .jscsrc - standardize es6 usage across client
63 lines
1.6 KiB
JavaScript
63 lines
1.6 KiB
JavaScript
import Ember from 'ember';
|
|
import DS from 'ember-data';
|
|
import ghostPaths from 'ghost/utils/ghost-paths';
|
|
|
|
const {inject} = Ember;
|
|
const {RESTAdapter} = DS;
|
|
|
|
export default RESTAdapter.extend({
|
|
host: window.location.origin,
|
|
namespace: ghostPaths().apiRoot.slice(1),
|
|
|
|
session: inject.service('session'),
|
|
|
|
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(type, id) {
|
|
// Ensure trailing slashes
|
|
let url = this._super(type, id);
|
|
|
|
if (url.slice(-1) !== '/') {
|
|
url += '/';
|
|
}
|
|
|
|
return url;
|
|
},
|
|
|
|
// Override deleteRecord to disregard the response body on 2xx responses.
|
|
// This is currently needed because the API is returning status 200 along
|
|
// with the JSON object for the deleted entity and Ember expects an empty
|
|
// response body for successful DELETEs.
|
|
// Non-2xx (failure) responses will still work correctly as Ember will turn
|
|
// them into rejected promises.
|
|
deleteRecord() {
|
|
let response = this._super(...arguments);
|
|
|
|
return response.then(() => {
|
|
return null;
|
|
});
|
|
},
|
|
|
|
handleResponse(status) {
|
|
if (status === 401) {
|
|
if (this.get('session.isAuthenticated')) {
|
|
this.get('session').invalidate();
|
|
}
|
|
}
|
|
|
|
return this._super(...arguments);
|
|
}
|
|
});
|