2021-03-18 13:33:35 +00:00
|
|
|
import { compareServerVersion, methods } from '../utils';
|
2020-08-21 13:38:50 +00:00
|
|
|
import reduxStore from '../createStore';
|
|
|
|
import database from '../database';
|
|
|
|
import log from '../../utils/log';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { clearEnterpriseModules, setEnterpriseModules as setEnterpriseModulesAction } from '../../actions/enterpriseModules';
|
2020-08-21 13:38:50 +00:00
|
|
|
|
|
|
|
export const LICENSE_OMNICHANNEL_MOBILE_ENTERPRISE = 'omnichannel-mobile-enterprise';
|
|
|
|
export const LICENSE_LIVECHAT_ENTERPRISE = 'livechat-enterprise';
|
|
|
|
|
|
|
|
export async function setEnterpriseModules() {
|
|
|
|
try {
|
|
|
|
const { server: serverId } = reduxStore.getState().server;
|
|
|
|
const serversDB = database.servers;
|
2021-02-26 16:25:51 +00:00
|
|
|
const serversCollection = serversDB.get('servers');
|
2020-09-23 17:16:04 +00:00
|
|
|
let server;
|
|
|
|
try {
|
|
|
|
server = await serversCollection.find(serverId);
|
|
|
|
} catch {
|
|
|
|
// Server not found
|
|
|
|
}
|
|
|
|
if (server?.enterpriseModules) {
|
2020-08-21 13:38:50 +00:00
|
|
|
reduxStore.dispatch(setEnterpriseModulesAction(server.enterpriseModules.split(',')));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
reduxStore.dispatch(clearEnterpriseModules());
|
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getEnterpriseModules() {
|
2021-09-13 20:41:05 +00:00
|
|
|
return new Promise(async resolve => {
|
2020-08-21 13:38:50 +00:00
|
|
|
try {
|
|
|
|
const { version: serverVersion, server: serverId } = reduxStore.getState().server;
|
2021-03-18 13:33:35 +00:00
|
|
|
if (compareServerVersion(serverVersion, '3.1.0', methods.greaterThanOrEqualTo)) {
|
2020-08-21 13:38:50 +00:00
|
|
|
// RC 3.1.0
|
|
|
|
const enterpriseModules = await this.methodCallWrapper('license:getModules');
|
|
|
|
if (enterpriseModules) {
|
|
|
|
const serversDB = database.servers;
|
2021-02-26 16:25:51 +00:00
|
|
|
const serversCollection = serversDB.get('servers');
|
2020-08-21 13:38:50 +00:00
|
|
|
const server = await serversCollection.find(serverId);
|
2021-09-13 20:41:05 +00:00
|
|
|
await serversDB.action(async () => {
|
|
|
|
await server.update(s => {
|
2020-08-21 13:38:50 +00:00
|
|
|
s.enterpriseModules = enterpriseModules.join(',');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
reduxStore.dispatch(setEnterpriseModulesAction(enterpriseModules));
|
|
|
|
return resolve();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
reduxStore.dispatch(clearEnterpriseModules());
|
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
|
|
|
}
|
|
|
|
return resolve();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function hasLicense(module) {
|
|
|
|
const { enterpriseModules } = reduxStore.getState();
|
|
|
|
return enterpriseModules.includes(module);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isOmnichannelModuleAvailable() {
|
|
|
|
const { enterpriseModules } = reduxStore.getState();
|
|
|
|
return [LICENSE_OMNICHANNEL_MOBILE_ENTERPRISE, LICENSE_LIVECHAT_ENTERPRISE].some(module => enterpriseModules.includes(module));
|
|
|
|
}
|