[MM-48184] Disallow edit/remove server if it is imported from GPO (#2353)
* Disallow edit/remove server if it is imported from GPO * Fix width issue of team dropdown
This commit is contained in:
@@ -57,4 +57,52 @@ describe('main/views/teamDropdownView', () => {
|
||||
teamDropdownView.handleClose();
|
||||
expect(teamDropdownView.view.setBounds).toBeCalledWith({width: 0, height: 0, x: expect.any(Number), y: expect.any(Number)});
|
||||
});
|
||||
|
||||
describe('addGpoToTeams', () => {
|
||||
it('should return teams with "isGPO": false when no config.registryTeams exist', () => {
|
||||
const teamDropdownView = new TeamDropdownView(window, [], false, true);
|
||||
const teams = [{
|
||||
name: 'team-1',
|
||||
url: 'https://mattermost.team-1.com',
|
||||
}, {
|
||||
name: 'team-2',
|
||||
url: 'https://mattermost.team-2.com',
|
||||
}];
|
||||
const registryTeams = [];
|
||||
|
||||
expect(teamDropdownView.addGpoToTeams(teams, registryTeams)).toStrictEqual([{
|
||||
name: 'team-1',
|
||||
url: 'https://mattermost.team-1.com',
|
||||
isGpo: false,
|
||||
}, {
|
||||
name: 'team-2',
|
||||
url: 'https://mattermost.team-2.com',
|
||||
isGpo: false,
|
||||
}]);
|
||||
});
|
||||
it('should return teams with "isGPO": true if they exist in config.registryTeams', () => {
|
||||
const teamDropdownView = new TeamDropdownView(window, [], false, true);
|
||||
const teams = [{
|
||||
name: 'team-1',
|
||||
url: 'https://mattermost.team-1.com',
|
||||
}, {
|
||||
name: 'team-2',
|
||||
url: 'https://mattermost.team-2.com',
|
||||
}];
|
||||
const registryTeams = [{
|
||||
name: 'team-1',
|
||||
url: 'https://mattermost.team-1.com',
|
||||
}];
|
||||
|
||||
expect(teamDropdownView.addGpoToTeams(teams, registryTeams)).toStrictEqual([{
|
||||
name: 'team-1',
|
||||
url: 'https://mattermost.team-1.com',
|
||||
isGpo: true,
|
||||
}, {
|
||||
name: 'team-2',
|
||||
url: 'https://mattermost.team-2.com',
|
||||
isGpo: false,
|
||||
}]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -5,7 +5,7 @@ import {BrowserView, BrowserWindow, ipcMain, IpcMainEvent} from 'electron';
|
||||
|
||||
import log from 'electron-log';
|
||||
|
||||
import {CombinedConfig, TeamWithTabs} from 'types/config';
|
||||
import {CombinedConfig, Team, TeamWithTabs, TeamWithTabsAndGpo} from 'types/config';
|
||||
|
||||
import {
|
||||
CLOSE_TEAMS_DROPDOWN,
|
||||
@@ -25,7 +25,7 @@ import WindowManager from '../windows/windowManager';
|
||||
export default class TeamDropdownView {
|
||||
view: BrowserView;
|
||||
bounds?: Electron.Rectangle;
|
||||
teams: TeamWithTabs[];
|
||||
teams: TeamWithTabsAndGpo[];
|
||||
activeTeam?: string;
|
||||
darkMode: boolean;
|
||||
enableServerManagement?: boolean;
|
||||
@@ -38,7 +38,7 @@ export default class TeamDropdownView {
|
||||
isOpen: boolean;
|
||||
|
||||
constructor(window: BrowserWindow, teams: TeamWithTabs[], darkMode: boolean, enableServerManagement: boolean) {
|
||||
this.teams = teams;
|
||||
this.teams = this.addGpoToTeams(teams, []);
|
||||
this.window = window;
|
||||
this.darkMode = darkMode;
|
||||
this.enableServerManagement = enableServerManagement;
|
||||
@@ -71,7 +71,7 @@ export default class TeamDropdownView {
|
||||
updateConfig = (event: IpcMainEvent, config: CombinedConfig) => {
|
||||
log.silly('TeamDropdownView.config', {config});
|
||||
|
||||
this.teams = config.teams;
|
||||
this.teams = this.addGpoToTeams(config.teams, config.registryTeams);
|
||||
this.darkMode = config.darkMode;
|
||||
this.enableServerManagement = config.enableServerManagement;
|
||||
this.hasGPOTeams = config.registryTeams && config.registryTeams.length > 0;
|
||||
@@ -162,4 +162,16 @@ export default class TeamDropdownView {
|
||||
// @ts-ignore
|
||||
this.view.webContents.destroy();
|
||||
}
|
||||
|
||||
addGpoToTeams = (teams: TeamWithTabs[], registryTeams: Team[]): TeamWithTabsAndGpo[] => {
|
||||
if (!registryTeams || registryTeams.length === 0) {
|
||||
return teams.map((team) => ({...team, isGpo: false}));
|
||||
}
|
||||
return teams.map((team) => {
|
||||
return {
|
||||
...team,
|
||||
isGpo: registryTeams.some((regTeam) => regTeam!.url === team!.url),
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user