Skip to content

Commit 322a553

Browse files
authored
Merge pull request CactuseSecurity#3118 from SolidProgramming/issue_2692
Merge: Fixed connection object duplication
2 parents a36394a + 81f5e95 commit 322a553

File tree

1 file changed

+9
-106
lines changed

1 file changed

+9
-106
lines changed

roles/lib/files/FWO.Services/ModellingConnectionHandler.cs

Lines changed: 9 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,19 +1205,17 @@ public async Task<bool> Save(bool noCheck = false)
12051205
}
12061206
if (noCheck || CheckConn())
12071207
{
1208-
if (!SrcReadOnly)
1208+
if(!SrcReadOnly)
12091209
{
12101210
SyncSrcChanges();
12111211
}
1212-
if (!DstReadOnly)
1212+
if(!DstReadOnly)
12131213
{
12141214
SyncDstChanges();
12151215
}
1216-
if (!SvcReadOnly)
1217-
{
1218-
SyncSvcChanges();
1219-
}
1216+
12201217
ActConn.SyncState(DummyAppRole.Id);
1218+
12211219
if (AddMode)
12221220
{
12231221
await AddConnectionToDb();
@@ -1282,39 +1280,7 @@ private void SyncSrcChanges()
12821280
{
12831281
SrcAppRolesToDelete.Add(linkedDummyAR.Content);
12841282
}
1285-
}
1286-
foreach (var appServer in SrcAppServerToDelete)
1287-
{
1288-
ActConn.SourceAppServers.Remove(ActConn.SourceAppServers.FirstOrDefault(x => x.Content.Id == appServer.Id) ?? throw new Exception("Did not find app server."));
1289-
}
1290-
foreach (var appServer in SrcAppServerToAdd)
1291-
{
1292-
ActConn.SourceAppServers.Add(new ModellingAppServerWrapper() { Content = appServer });
1293-
}
1294-
foreach (var appRole in SrcAppRolesToDelete)
1295-
{
1296-
ActConn.SourceAppRoles.Remove(ActConn.SourceAppRoles.FirstOrDefault(x => x.Content.Id == appRole.Id) ?? throw new Exception("Did not find app role."));
1297-
}
1298-
foreach (var appRole in SrcAppRolesToAdd)
1299-
{
1300-
ActConn.SourceAppRoles.Add(new ModellingAppRoleWrapper() { Content = appRole });
1301-
}
1302-
foreach (var area in SrcAreasToDelete)
1303-
{
1304-
ActConn.SourceAreas.Remove(ActConn.SourceAreas.FirstOrDefault(x => x.Content.Id == area.Id) ?? throw new Exception("Did not find area."));
1305-
}
1306-
foreach (var area in SrcAreasToAdd)
1307-
{
1308-
ActConn.SourceAreas.Add(new ModellingNetworkAreaWrapper() { Content = area });
1309-
}
1310-
foreach (var nwGroup in SrcNwGroupsToDelete)
1311-
{
1312-
ActConn.SourceOtherGroups.Remove(ActConn.SourceOtherGroups.FirstOrDefault(x => x.Content.Id == nwGroup.Id) ?? throw new Exception("Did not find nwgroup."));
1313-
}
1314-
foreach (var nwGroup in SrcNwGroupsToAdd)
1315-
{
1316-
ActConn.SourceOtherGroups.Add(new ModellingNwGroupWrapper() { Content = nwGroup });
1317-
}
1283+
}
13181284
}
13191285

13201286
private void SyncDstChanges()
@@ -1326,59 +1292,7 @@ private void SyncDstChanges()
13261292
{
13271293
DstAppRolesToDelete.Add(linkedDummyAR.Content);
13281294
}
1329-
}
1330-
foreach (var appServer in DstAppServerToDelete)
1331-
{
1332-
ActConn.DestinationAppServers.Remove(ActConn.DestinationAppServers.FirstOrDefault(x => x.Content.Id == appServer.Id) ?? throw new Exception("Did not find app server."));
1333-
}
1334-
foreach (var appServer in DstAppServerToAdd)
1335-
{
1336-
ActConn.DestinationAppServers.Add(new ModellingAppServerWrapper() { Content = appServer });
1337-
}
1338-
foreach (var appRole in DstAppRolesToDelete)
1339-
{
1340-
ActConn.DestinationAppRoles.Remove(ActConn.DestinationAppRoles.FirstOrDefault(x => x.Content.Id == appRole.Id) ?? throw new Exception("Did not find app role."));
1341-
}
1342-
foreach (var appRole in DstAppRolesToAdd)
1343-
{
1344-
ActConn.DestinationAppRoles.Add(new ModellingAppRoleWrapper() { Content = appRole });
1345-
}
1346-
foreach (var area in DstAreasToDelete)
1347-
{
1348-
ActConn.DestinationAreas.Remove(ActConn.DestinationAreas.FirstOrDefault(x => x.Content.Id == area.Id) ?? throw new Exception("Did not find area."));
1349-
}
1350-
foreach (var area in DstAreasToAdd)
1351-
{
1352-
ActConn.DestinationAreas.Add(new ModellingNetworkAreaWrapper() { Content = area });
1353-
}
1354-
foreach (var nwGroup in DstNwGroupsToDelete)
1355-
{
1356-
ActConn.DestinationOtherGroups.Remove(ActConn.DestinationOtherGroups.FirstOrDefault(x => x.Content.Id == nwGroup.Id) ?? throw new Exception("Did not find nwgroup."));
1357-
}
1358-
foreach (var nwGroup in DstNwGroupsToAdd)
1359-
{
1360-
ActConn.DestinationOtherGroups.Add(new ModellingNwGroupWrapper() { Content = nwGroup });
1361-
}
1362-
}
1363-
1364-
private void SyncSvcChanges()
1365-
{
1366-
foreach (var svc in SvcToDelete)
1367-
{
1368-
ActConn.Services.Remove(ActConn.Services.FirstOrDefault(x => x.Content.Id == svc.Id) ?? throw new Exception("Did not find service."));
1369-
}
1370-
foreach (var svc in SvcToAdd)
1371-
{
1372-
ActConn.Services.Add(new ModellingServiceWrapper() { Content = svc });
1373-
}
1374-
foreach (var svcGrp in SvcGrpToDelete)
1375-
{
1376-
ActConn.ServiceGroups.Remove(ActConn.ServiceGroups.FirstOrDefault(x => x.Content.Id == svcGrp.Id) ?? throw new Exception("Did not find service group."));
1377-
}
1378-
foreach (var svcGrp in SvcGrpToAdd)
1379-
{
1380-
ActConn.ServiceGroups.Add(new ModellingServiceGroupWrapper() { Content = svcGrp });
1381-
}
1295+
}
13821296
}
13831297

13841298
private async Task AddConnectionToDb(bool propose = false)
@@ -1412,26 +1326,15 @@ await LogChange(ModellingTypes.ChangeType.Insert, ModellingTypes.ModObjectType.C
14121326
$"New {( ActConn.IsInterface ? "Interface" : "Connection" )}: {ActConn.Name}", AppId);
14131327
if (ActConn.UsedInterfaceId == null || ActConn.DstFromInterface)
14141328
{
1415-
1416-
await AddNwObjects(ModellingAppServerWrapper.Resolve(ActConn.SourceAppServers).ToList(),
1417-
ModellingAppRoleWrapper.Resolve(ActConn.SourceAppRoles).ToList(),
1418-
ModellingNetworkAreaWrapper.Resolve(ActConn.SourceAreas).ToList(),
1419-
ModellingNwGroupWrapper.Resolve(ActConn.SourceOtherGroups).ToList(),
1420-
ModellingTypes.ConnectionField.Source);
1329+
await AddNwObjects(SrcAppServerToAdd, SrcAppRolesToAdd, SrcAreasToAdd, SrcNwGroupsToAdd, ModellingTypes.ConnectionField.Source);
14211330
}
14221331
if (ActConn.UsedInterfaceId == null || ActConn.SrcFromInterface)
14231332
{
1424-
//DstAppRolesToAdd.Add(ActConn.DestinationAppRoles.First().Content);
1425-
await AddNwObjects(ModellingAppServerWrapper.Resolve(ActConn.DestinationAppServers).ToList(),
1426-
ModellingAppRoleWrapper.Resolve(ActConn.DestinationAppRoles).ToList(),
1427-
ModellingNetworkAreaWrapper.Resolve(ActConn.DestinationAreas).ToList(),
1428-
ModellingNwGroupWrapper.Resolve(ActConn.DestinationOtherGroups).ToList(),
1429-
ModellingTypes.ConnectionField.Destination);
1333+
await AddNwObjects(DstAppServerToAdd, DstAppRolesToAdd, DstAreasToAdd, DstNwGroupsToAdd, ModellingTypes.ConnectionField.Destination);
14301334
}
14311335
if (ActConn.UsedInterfaceId == null)
14321336
{
1433-
await AddSvcObjects(ModellingServiceWrapper.Resolve(ActConn.Services).ToList(),
1434-
ModellingServiceGroupWrapper.Resolve(ActConn.ServiceGroups).ToList());
1337+
await AddSvcObjects(SvcToAdd, SvcGrpToAdd);
14351338
}
14361339
ActConn.Creator = userConfig.User.Name;
14371340
ActConn.CreationDate = DateTime.Now;

0 commit comments

Comments
 (0)