Browse code

BM-15396 Fix: handle accounts targeting non-existing systems

Thomas Fricker authored on 03/01/2020 10:46:52
Showing 1 changed files
... ...
@@ -135,6 +135,7 @@ public class ExternalAccountsWidget extends CompositeGwtWidgetElement {
135 135
 		final JsMapStringJsObject map = model.cast();
136 136
 
137 137
 		JsArray<JsCompleteExternalSystem> externalSystems = map.get("external-systems").cast();
138
+
138 139
 		for (int i = 0; i < externalSystems.length(); i++) {
139 140
 			JsCompleteExternalSystem system = externalSystems.get(i);
140 141
 			logos.put(system.getIdentifier(), system.getLogo());
... ...
@@ -145,16 +146,29 @@ public class ExternalAccountsWidget extends CompositeGwtWidgetElement {
145 146
 		JsArray<JsUserAccountInfo> accounts = map.get("external-accounts").cast();
146 147
 		for (int i = 0; i < accounts.length(); i++) {
147 148
 			JsUserAccountInfo account = accounts.get(i);
149
+			Image img = null;
150
+			if (systemIsPresent(account.getExternalSystemId())) {
151
+				img = new Image(logos.get(account.getExternalSystemId()));
152
+			}
148 153
 			myAccountList.add(new AccountInfoEdit(account));
149 154
 			loginMap.put(account.getLogin(), account.getLogin());
150
-			addAccountEntry(account.getExternalSystemId(), account.getLogin(), myAccounts,
151
-					new Image(logos.get(account.getExternalSystemId())), account.getLogin());
155
+			addAccountEntry(account.getExternalSystemId(), account.getLogin(), myAccounts, img, account.getLogin());
152 156
 			unconfiguredSystems.remove(account.getExternalSystemId());
157
+
153 158
 		}
154 159
 
155 160
 		checkAddAccountButton();
156 161
 	}
157 162
 
163
+	private boolean systemIsPresent(String externalSystemId) {
164
+		for (JsCompleteExternalSystem sys : systems) {
165
+			if (sys.getIdentifier().equals(externalSystemId)) {
166
+				return true;
167
+			}
168
+		}
169
+		return false;
170
+	}
171
+
158 172
 	public void save(String login, boolean create, String systemIdentifier, String newLogin, String credentials,
159 173
 			Map<String, String> config) {
160 174
 		if (create) {
... ...
@@ -191,14 +205,16 @@ public class ExternalAccountsWidget extends CompositeGwtWidgetElement {
191 205
 		Anchor identifier = new Anchor(systemIdentifier);
192 206
 		Anchor description = new Anchor(label);
193 207
 		AccountClickHandler handler = new AccountClickHandler(this, getSystem(systemIdentifier), login, loginMap);
194
-		identifier.addClickHandler(handler);
195
-		description.addClickHandler(handler);
196 208
 
197
-		icon.setStyleName(style.systemIcon());
198 209
 		int row = table.getRowCount();
199 210
 		rowMap.put(systemIdentifier, row);
200
-		handlerMap.put(systemIdentifier, icon.addClickHandler(handler));
201
-		table.setWidget(row, 0, icon);
211
+		if (icon != null) {
212
+			identifier.addClickHandler(handler);
213
+			description.addClickHandler(handler);
214
+			icon.setStyleName(style.systemIcon());
215
+			handlerMap.put(systemIdentifier, icon.addClickHandler(handler));
216
+			table.setWidget(row, 0, icon);
217
+		}
202 218
 		table.setWidget(row, 1, identifier);
203 219
 		table.setWidget(row, 2, new Label(login));
204 220
 
... ...
@@ -208,10 +224,12 @@ public class ExternalAccountsWidget extends CompositeGwtWidgetElement {
208 224
 		table.getFlexCellFormatter().setStyleName(row, 3, style.account_tbl_button());
209 225
 		table.getFlexCellFormatter().setStyleName(row, 4, style.account_tbl_col_trash());
210 226
 
211
-		Button edit = new Button(constants.edit());
212
-		edit.setStyleName("button");
213
-		edit.addClickHandler(handler);
214
-		table.setWidget(row, 3, edit);
227
+		if (icon != null) {
228
+			Button edit = new Button(constants.edit());
229
+			edit.setStyleName("button");
230
+			edit.addClickHandler(handler);
231
+			table.setWidget(row, 3, edit);
232
+		}
215 233
 
216 234
 		Trash delete = new Trash();
217 235
 		delete.addClickHandler(c -> {
... ...
@@ -225,7 +243,9 @@ public class ExternalAccountsWidget extends CompositeGwtWidgetElement {
225 243
 					}
226 244
 					iter.remove();
227 245
 					table.removeRow(row);
228
-					unconfiguredSystems.add(accountInfo.account.getExternalSystemId());
246
+					if (systemIsPresent(accountInfo.account.getExternalSystemId())) {
247
+						unconfiguredSystems.add(accountInfo.account.getExternalSystemId());
248
+					}
229 249
 					break;
230 250
 				}
231 251
 			}