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
|
|
|
|
|
2017-11-16 13:28:05 +00:00
|
|
|
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;
|
|
|
|
}
|
2017-04-27 12:49:10 +01:00
|
|
|
}),
|
|
|
|
|
|
|
|
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) {
|
2017-04-27 12:49:10 +01:00
|
|
|
window.location.href = 'auth/login';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch(e){} // eslint-disable-line no-empty
|
|
|
|
|
|
|
|
return this._super(...arguments);
|
|
|
|
}
|
2016-08-16 13:34:09 +02:00
|
|
|
});
|