1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-19 21:29:42 +02:00
documize/gui/app/services/ajax.js

51 lines
1.5 KiB
JavaScript
Raw Normal View History

2016-07-07 18:54:16 -07:00
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
2016-08-16 13:34:09 +02:00
// This software (Documize Community Edition) is licensed under
2016-07-07 18:54:16 -07:00
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
2016-08-16 13:34:09 +02:00
// by contacting <sales@documize.com>.
2016-07-07 18:54:16 -07:00
//
// https://documize.com
import { computed } from '@ember/object';
import { inject as service } from '@ember/service';
2016-07-07 18:54:16 -07:00
import AjaxService from 'ember-ajax/services/ajax';
import config from '../config/environment';
export default AjaxService.extend({
session: service(),
host: config.apiHost,
namespace: config.apiNamespace,
2016-08-16 13:34:09 +02:00
headers: computed('session.session.content.authenticated.token', {
2016-07-07 18:54:16 -07:00
get() {
let headers = {};
const token = this.get('session.session.content.authenticated.token');
if (token) {
headers['authorization'] = token;
}
return headers;
}
}),
handleResponse(status, headers /*, payload*/) {
try {
let user = this.get('session.session.content.authenticated.user');
let userUpdate = headers['x-documize-status'];
if (is.not.empty(userUpdate)) {
let latest = JSON.parse(userUpdate);
2017-10-04 12:27:56 -04:00
if (!latest.active || user.editor !== latest.editor || user.admin !== latest.admin || user.viewUsers !== latest.viewUsers) {
window.location.href = 'auth/login';
}
}
} catch(e){} // eslint-disable-line no-empty
return this._super(...arguments);
}
2016-08-16 13:34:09 +02:00
});