2016-07-07 18:54:16 -07:00
|
|
|
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
|
|
|
//
|
2016-07-24 14:49:40 -07: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-07-24 14:49:40 -07: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 { htmlSafe } from '@ember/string';
|
|
|
|
|
|
|
|
import { resolve } from 'rsvp';
|
|
|
|
import Service, { inject as service } from '@ember/service';
|
2016-07-07 18:54:16 -07:00
|
|
|
import config from '../config/environment';
|
2017-03-16 11:46:09 +00:00
|
|
|
import constants from '../utils/constants';
|
2016-07-07 18:54:16 -07:00
|
|
|
|
2017-11-16 13:28:05 +00:00
|
|
|
export default Service.extend({
|
2016-07-07 18:54:16 -07:00
|
|
|
ajax: service(),
|
2016-07-15 16:54:07 +01:00
|
|
|
localStorage: service(),
|
2017-03-20 17:56:15 +00:00
|
|
|
kcAuth: service(),
|
2017-04-03 16:34:42 +01:00
|
|
|
apiHost: `${config.apiHost}`,
|
2016-07-08 16:08:23 -07:00
|
|
|
endpoint: `${config.apiHost}/${config.apiNamespace}`,
|
2017-06-06 19:00:35 -04:00
|
|
|
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,
|
2017-03-16 11:46:09 +00:00
|
|
|
authProvider: constants.AuthProvider.Documize,
|
2017-03-14 17:19:53 +00:00
|
|
|
authConfig: null,
|
2016-07-15 16:54:07 +01:00
|
|
|
setupMode: false,
|
2017-08-29 17:55:41 +01:00
|
|
|
secureMode: false,
|
2016-07-07 18:54:16 -07:00
|
|
|
|
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
|
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) {
|
2016-07-15 16:54:07 +01:00
|
|
|
this.setProperties({
|
2016-07-07 18:54:16 -07:00
|
|
|
title: htmlSafe("Documize Setup"),
|
2016-07-15 16:54:07 +01:00
|
|
|
allowAnonymousAccess: true,
|
|
|
|
setupMode: true
|
2016-07-07 18:54:16 -07:00
|
|
|
});
|
2017-06-06 19:00:35 -04:00
|
|
|
|
2016-07-15 16:54:07 +01:00
|
|
|
this.get('localStorage').clearAll();
|
2016-07-08 16:08:23 -07:00
|
|
|
|
2016-07-15 16:54:07 +01:00
|
|
|
return resolve(this);
|
2016-07-07 18:54:16 -07:00
|
|
|
}
|
|
|
|
|
2017-05-03 11:37:39 +01:00
|
|
|
if (requestedRoute === 'secure') {
|
2017-03-22 12:21:18 +00:00
|
|
|
this.setProperties({
|
|
|
|
title: htmlSafe("Secure document viewing"),
|
|
|
|
allowAnonymousAccess: true,
|
2017-08-29 17:55:41 +01:00
|
|
|
secureMode: true
|
2017-03-22 12:21:18 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.get('localStorage').clearAll();
|
|
|
|
|
|
|
|
return resolve(this);
|
|
|
|
}
|
|
|
|
|
2016-07-08 16:08:23 -07:00
|
|
|
return this.get('ajax').request('public/meta').then((response) => {
|
|
|
|
this.setProperties(response);
|
2017-05-04 13:56:31 +01:00
|
|
|
|
2017-06-06 19:00:35 -04:00
|
|
|
if (is.not.include(requestedUrl, '/auth/')) {
|
2017-05-04 13:56:31 +01:00
|
|
|
this.get('localStorage').storeSessionItem('entryUrl', requestedUrl);
|
|
|
|
}
|
|
|
|
|
2016-07-08 16:08:23 -07:00
|
|
|
return response;
|
|
|
|
});
|
2016-07-07 18:54:16 -07:00
|
|
|
}
|
2016-07-24 14:49:40 -07:00
|
|
|
});
|