From 400c02f2645d979db86d3510d790d9d6ce62ec4c Mon Sep 17 00:00:00 2001 From: Kanishk Kakar Date: Fri, 19 Jul 2019 22:04:48 +0530 Subject: [PATCH] enterprise: Add support for preset orgs. Enable configuration of preset organizations in the enterprise config file and load them when app loads. Partially valid array of URLs accepted while loading app. --- app/renderer/js/main.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/app/renderer/js/main.ts b/app/renderer/js/main.ts index 305f83d8..f4e9b7f5 100644 --- a/app/renderer/js/main.ts +++ b/app/renderer/js/main.ts @@ -20,6 +20,7 @@ import DNDUtil = require('./utils/dnd-util'); import ReconnectUtil = require('./utils/reconnect-util'); import Logger = require('./utils/logger-util'); import CommonUtil = require('./utils/common-util'); +import EnterpriseUtil = require('./utils/enterprise-util'); const logger = new Logger({ file: 'errors.log', @@ -135,6 +136,7 @@ class ServerManagerView { init(): void { this.loadProxy().then(() => { this.initSidebar(); + this.initPresetOrgs(); this.initTabs(); this.initActions(); this.registerIpcs(); @@ -232,6 +234,40 @@ class ServerManagerView { this.toggleSidebar(showSidebar); } + async queueDomain(domain: any): Promise { + // allows us to start adding multiple domains to the app simultaneously + // promise of addition resolves in both cases, but we consider it rejected + // if the resolved value is false + try { + const serverConf = await DomainUtil.checkDomain(domain); + await DomainUtil.addDomain(serverConf); + return true; + } catch (err) { + logger.error(err); + logger.error('Could not add ' + domain + '. Please contact your system administrator.'); + return false; + } + } + + async initPresetOrgs(): Promise { + // read preset organizations from global_config.json and queues them + // for addition to the app's domains + const presetOrgs = EnterpriseUtil.getConfigItem('presetOrganizations', []); + // set to true if at least one new domain is added + const domainPromises = []; + for (const url in presetOrgs) { + if (DomainUtil.duplicateDomain(presetOrgs[url])) { + continue; + } + domainPromises.push(this.queueDomain(presetOrgs[url])); + } + const domainsAdded = await Promise.all(domainPromises); + if (domainsAdded.includes(true)) { + // at least one domain was resolved + ipcRenderer.send('reload-full-app'); + } + } + initTabs(): void { const servers = DomainUtil.getDomains(); if (servers.length > 0) {