mirror of
				https://github.com/zulip/zulip-desktop.git
				synced 2025-11-04 14:03:27 +00:00 
			
		
		
		
	enterprise: Raise error when removing orgs.
When a user tries to remove a preset org, we raise an error asking them to contact their sys admin.
This commit is contained in:
		
				
					committed by
					
						
						Akash Nimare
					
				
			
			
				
	
			
			
			
						parent
						
							33fadcd876
						
					
				
				
					commit
					a7887211ac
				
			@@ -285,8 +285,15 @@ class ServerManagerView {
 | 
			
		||||
				ipcRenderer.send('reload-full-app');
 | 
			
		||||
			}
 | 
			
		||||
		} else if (domainsAdded.length > 0) {
 | 
			
		||||
			// no enterprise domains added
 | 
			
		||||
			const { title, content } = Messages.enterpriseOrgError(domainsAdded.length);
 | 
			
		||||
			// find all orgs that failed
 | 
			
		||||
			const failedDomains: string[] = [];
 | 
			
		||||
			for (const org of this.presetOrgs) {
 | 
			
		||||
				if (DomainUtil.duplicateDomain(org)) {
 | 
			
		||||
					continue;
 | 
			
		||||
				}
 | 
			
		||||
				failedDomains.push(org);
 | 
			
		||||
			}
 | 
			
		||||
			const { title, content } = Messages.enterpriseOrgError(domainsAdded.length, failedDomains);
 | 
			
		||||
			dialog.showErrorBox(title, content);
 | 
			
		||||
			if (DomainUtil.getDomains().length === 0) {
 | 
			
		||||
				// no orgs present, stop showing loading gif
 | 
			
		||||
@@ -721,8 +728,12 @@ class ServerManagerView {
 | 
			
		||||
							message: 'Are you sure you want to disconnect this organization?'
 | 
			
		||||
						}, response => {
 | 
			
		||||
							if (response === 0) {
 | 
			
		||||
								DomainUtil.removeDomain(index);
 | 
			
		||||
								ipcRenderer.send('reload-full-app');
 | 
			
		||||
								if (DomainUtil.removeDomain(index)) {
 | 
			
		||||
									ipcRenderer.send('reload-full-app');
 | 
			
		||||
								} else {
 | 
			
		||||
									const { title, content } = Messages.orgRemovalError(DomainUtil.getDomain(index).url);
 | 
			
		||||
									dialog.showErrorBox(title, content);
 | 
			
		||||
								}
 | 
			
		||||
							}
 | 
			
		||||
						});
 | 
			
		||||
					}
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,7 @@ import { remote, ipcRenderer } from 'electron';
 | 
			
		||||
 | 
			
		||||
import BaseComponent = require('../../components/base');
 | 
			
		||||
import DomainUtil = require('../../utils/domain-util');
 | 
			
		||||
import Messages = require('./../../../../resources/messages');
 | 
			
		||||
 | 
			
		||||
const { dialog } = remote;
 | 
			
		||||
 | 
			
		||||
@@ -67,8 +68,12 @@ class ServerInfoForm extends BaseComponent {
 | 
			
		||||
				message: 'Are you sure you want to disconnect this organization?'
 | 
			
		||||
			}, response => {
 | 
			
		||||
				if (response === 0) {
 | 
			
		||||
					DomainUtil.removeDomain(this.props.index);
 | 
			
		||||
					this.props.onChange(this.props.index);
 | 
			
		||||
					if (DomainUtil.removeDomain(this.props.index)) {
 | 
			
		||||
						ipcRenderer.send('reload-full-app');
 | 
			
		||||
					} else {
 | 
			
		||||
						const { title, content } = Messages.orgRemovalError(DomainUtil.getDomain(this.props.index).url);
 | 
			
		||||
						dialog.showErrorBox(title, content);
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			});
 | 
			
		||||
		});
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,7 @@ import Logger = require('./logger-util');
 | 
			
		||||
import electron = require('electron');
 | 
			
		||||
 | 
			
		||||
import RequestUtil = require('./request-util');
 | 
			
		||||
import EnterpriseUtil = require('./enterprise-util');
 | 
			
		||||
import Messages = require('../../../resources/messages');
 | 
			
		||||
 | 
			
		||||
const { app, dialog } = electron.remote;
 | 
			
		||||
@@ -87,9 +88,13 @@ class DomainUtil {
 | 
			
		||||
		this.reloadDB();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	removeDomain(index: number): void {
 | 
			
		||||
	removeDomain(index: number): boolean {
 | 
			
		||||
		if (EnterpriseUtil.isPresetOrg(this.getDomain(index).url)) {
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
		this.db.delete(`/domains[${index}]`);
 | 
			
		||||
		this.reloadDB();
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Check if domain is already added
 | 
			
		||||
 
 | 
			
		||||
@@ -52,6 +52,19 @@ class EnterpriseUtil {
 | 
			
		||||
		this.reloadDB();
 | 
			
		||||
		return (this.enterpriseSettings[key] !== undefined);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	isPresetOrg(url: string): boolean {
 | 
			
		||||
		if (!this.configItemExists('presetOrganizations')) {
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
		const presetOrgs = this.enterpriseSettings.presetOrganizations;
 | 
			
		||||
		for (const org of presetOrgs) {
 | 
			
		||||
			if (url.includes(org)) {
 | 
			
		||||
				return true;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export = new EnterpriseUtil();
 | 
			
		||||
 
 | 
			
		||||
@@ -23,9 +23,20 @@ class Messages {
 | 
			
		||||
		\nYou can click here if you'd like to proceed with the connection.`;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	enterpriseOrgError(length: number): any {
 | 
			
		||||
	enterpriseOrgError(length: number, domains: string[]): any {
 | 
			
		||||
		let domainList = '';
 | 
			
		||||
		for (const domain of domains) {
 | 
			
		||||
			domainList += `• ${domain}\n`;
 | 
			
		||||
		}
 | 
			
		||||
		return {
 | 
			
		||||
			title: `Could not add ${length} ${length === 1 ? `organization` : `organizations`}`,
 | 
			
		||||
			title: `Could not add the following ${length === 1 ? `organization` : `organizations`}`,
 | 
			
		||||
			content: `${domainList}\nPlease contact your system administrator.`
 | 
			
		||||
		};
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	orgRemovalError(url: string): any {
 | 
			
		||||
		return {
 | 
			
		||||
			title: `Removing ${url} is a restricted operation.`,
 | 
			
		||||
			content: `Please contact your system administrator.`
 | 
			
		||||
		};
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user