1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-08-04 21:15:24 +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';
}

View file

@ -38,15 +38,10 @@ export default Service.extend({
secureMode: false,
maxTags: 3,
storageProvider: '',
// for major.minor semver release detection
location: 'selfhost',
// for bugfix releases, only admin is made aware of new release and end users see no What's New messaging
updateAvailable: false,
// invalidLicense() {
// return this.valid === false;
// },
getBaseUrl(endpoint) {
return [this.get('endpoint'), endpoint].join('/');
},

View file

@ -41,10 +41,23 @@ export default Service.extend({
}
},
// Returns product subscription.
getSubscription() {
if(this.get('sessionService.isAdmin')) {
return this.get('ajax').request(`subscription`, {
method: 'GET',
dataType: 'JSON'
}).then((response) => {
return response;
});
}
},
// Returns product license.
getLicense() {
if(this.get('sessionService.isGlobalAdmin')) {
return this.get('ajax').request(`global/license`, {
if(this.get('sessionService.isAdmin')) {
return this.get('ajax').request(`license`, {
method: 'GET',
dataType: "text"
}).then((response) => {
@ -53,10 +66,10 @@ export default Service.extend({
}
},
// Saves product license.
saveLicense(license) {
if(this.get('sessionService.isGlobalAdmin')) {
return this.get('ajax').request(`global/license`, {
// Saves product subscription data.
setLicense(license) {
if(this.get('sessionService.isAdmin')) {
return this.get('ajax').request(`license`, {
method: 'PUT',
dataType: 'text',
data: license