1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-21 14:19:43 +02:00

Merge code between editions

This commit is contained in:
Harvey Kandola 2018-11-07 15:56:05 +00:00
parent d1b803b246
commit 6a9ad7f540
20 changed files with 365 additions and 110 deletions

View file

@ -17,6 +17,7 @@ import AjaxService from 'ember-ajax/services/ajax';
export default AjaxService.extend({
session: service(),
localStorage: service(),
appMeta: service(),
host: config.apiHost,
namespace: config.apiNamespace,
@ -34,20 +35,27 @@ export default AjaxService.extend({
handleResponse(status, headers /*, payload*/) {
try {
// Handle user permission changes.
let user = this.get('session.session.content.authenticated.user');
let userUpdate = headers['x-documize-status'];
let appVersion = headers['x-documize-version'];
// when unauthorized on local API AJAX calls, redirect to app root
// Unauthorized local API AJAX calls redirect to app root.
if (status === 401 && is.not.undefined(appVersion) && is.not.include(window.location.href, '/auth')) {
this.get('localStorage').clearAll();
window.location.href = 'auth/login';
}
if (this.get('session.authenticated') && is.not.empty(userUpdate) && is.not.undefined(userUpdate)) {
let latest = JSON.parse(userUpdate);
// Handle billing/licensing issue.
if (status === 402 || headers['x-documize-subscription'] === 'false') {
this.set('appMeta.valid', false);
}
if (!latest.active || user.editor !== latest.editor || user.admin !== latest.admin || user.analytics !== latest.analytics || user.viewUsers !== latest.viewUsers) {
if (this.get('session.authenticated') && is.not.empty(userUpdate) && is.not.undefined(userUpdate)) {
let latest = JSON.parse(userUpdate);
// Permission change means re-validation.
if (!latest.active || user.editor !== latest.editor || user.admin !== latest.admin ||
user.analytics !== latest.analytics || user.viewUsers !== latest.viewUsers) {
this.get('localStorage').clearAll();
window.location.href = 'auth/login';
}