Skip to content

Commit

Permalink
Prevent UI creating connection definitions with duplicate IDs (#1089)
Browse files Browse the repository at this point in the history
  • Loading branch information
gjsjohnmurray authored Jan 6, 2023
1 parent 195c5ed commit 8f8542e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/plugins/connection-manager/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ export class ConnectionManagerPlugin implements IExtensionPlugin {
}

const connList = this.getConnectionList(ConfigurationTarget[writeTo] || undefined);
this._throwIfNotUnique(connInfo, connList);
connList.push(connInfo);
return this.saveConnectionList(connList, ConfigurationTarget[writeTo]);
}
Expand All @@ -491,11 +492,20 @@ export class ConnectionManagerPlugin implements IExtensionPlugin {

const connList = this.getConnectionList(ConfigurationTarget[writeTo] || undefined)
.filter(c => getConnectionId(c) !== oldId);
this._throwIfNotUnique(connInfo, connList);
connList.push(connInfo);
return this.saveConnectionList(connList, ConfigurationTarget[writeTo]);
}

// internal utils

private _throwIfNotUnique(connInfo: IConnection, connList: IConnection[]) {
const connId = getConnectionId(connInfo);
if (connList.filter((c) => getConnectionId(c) === connId).length > 0) {
throw new Error(`A connection definition already exists with id '${connId}'. Change name or another id element to make it unique.`);
}
}

private async _getTable(node?: SidebarItem<NSDatabase.ITable> | NSDatabase.ITable): Promise<NSDatabase.ITable> {
if (node instanceof SidebarItem && node.conn) {
await this._setConnection(node.conn as IConnection);
Expand Down

0 comments on commit 8f8542e

Please sign in to comment.