1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-19 13:19:43 +02:00
documize/gui/app/services/app-meta.js

116 lines
3.3 KiB
JavaScript
Raw Normal View History

2016-07-07 18:54:16 -07:00
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// 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
// by contacting <sales@documize.com>.
2016-07-07 18:54:16 -07:00
//
// https://documize.com
import $ from 'jquery';
import { htmlSafe } from '@ember/string';
import { resolve } from 'rsvp';
import miscUtil from '../utils/misc';
2016-07-07 18:54:16 -07:00
import config from '../config/environment';
2018-09-10 10:12:14 +01:00
import Service, { inject as service } from '@ember/service';
2016-07-07 18:54:16 -07:00
export default Service.extend({
2016-07-07 18:54:16 -07:00
ajax: service(),
localStorage: service(),
kcAuth: service(),
2018-09-04 17:19:26 +01:00
appHost: '',
2017-04-03 16:34:42 +01:00
apiHost: `${config.apiHost}`,
2016-07-08 16:08:23 -07:00
endpoint: `${config.apiHost}/${config.apiNamespace}`,
conversionEndpoint: '',
2016-07-07 18:54:16 -07:00
orgId: '',
title: '',
version: '',
message: '',
2017-02-23 16:39:23 -08:00
edition: 'Community',
valid: true,
2016-07-07 18:54:16 -07:00
allowAnonymousAccess: false,
2018-04-20 14:38:10 +01:00
authProvider: null,
2017-03-14 17:19:53 +00:00
authConfig: null,
setupMode: false,
2017-08-29 17:55:41 +01:00
secureMode: false,
maxTags: 3,
storageProvider: '',
2016-07-07 18:54:16 -07:00
2018-09-10 10:12:14 +01:00
// for major.minor semver release detection
// for bugfix releases, only admin is made aware of new release and end users see no What's New messaging
updateAvailable: false,
2017-02-23 16:39:23 -08:00
invalidLicense() {
return this.valid === false;
},
2016-07-07 18:54:16 -07:00
getBaseUrl(endpoint) {
2016-07-26 11:48:40 -07:00
return [this.get('endpoint'), endpoint].join('/');
2016-07-07 18:54:16 -07:00
},
2017-05-03 11:37:39 +01:00
boot(requestedRoute, requestedUrl) { // eslint-disable-line no-unused-vars
2018-04-20 14:38:10 +01:00
let constants = this.get('constants');
this.set('authProvider', constants.AuthProvider.Documize);
2016-07-07 18:54:16 -07:00
let dbhash;
if (is.not.null(document.head.querySelector("[property=dbhash]"))) {
dbhash = document.head.querySelector("[property=dbhash]").content;
}
let isInSetupMode = dbhash && dbhash !== "{{.DBhash}}";
if (isInSetupMode) {
this.setProperties({
2016-07-07 18:54:16 -07:00
title: htmlSafe("Documize Setup"),
allowAnonymousAccess: true,
setupMode: true
2016-07-07 18:54:16 -07:00
});
this.get('localStorage').clearAll();
2016-07-08 16:08:23 -07:00
return resolve(this);
2016-07-07 18:54:16 -07:00
}
2016-07-08 16:08:23 -07:00
return this.get('ajax').request('public/meta').then((response) => {
this.setProperties(response);
this.set('version', 'v' + this.get('version'));
2018-09-04 17:19:26 +01:00
this.set('appHost', window.location.host);
2017-12-19 16:52:40 +00:00
if (requestedRoute === 'secure') {
this.setProperties({
title: htmlSafe("Secure document viewing"),
allowAnonymousAccess: true,
secureMode: true
});
2017-12-19 16:52:40 +00:00
this.get('localStorage').clearAll();
} else if (is.not.include(requestedUrl, '/auth/')) {
this.get('localStorage').storeSessionItem('entryUrl', requestedUrl);
}
let self = this;
let cacheBuster = + new Date();
2018-04-20 14:38:10 +01:00
$.getJSON(`https://storage.googleapis.com/documize/news/meta.json?cb=${cacheBuster}`, function (versions) {
let cv = 'v' + versions.community.version;
let ev = 'v' + versions.enterprise.version;
let re = self.get('edition');
let rv = self.get('version');
self.set('communityLatest', cv);
self.set('enterpriseLatest', ev);
self.set('updateAvailable', false); // set to true for testing
let isNewCommunity = miscUtil.isNewVersion(rv, cv, true);
let isNewEnterprise = miscUtil.isNewVersion(rv, ev, true);
if (re === 'Community' && isNewCommunity) self.set('updateAvailable', true);
if (re === 'Enterprise' && isNewEnterprise) self.set('updateAvailable', true);
});
2016-07-08 16:08:23 -07:00
return response;
});
2016-07-07 18:54:16 -07:00
}
});