Skip to content

Commit 84902f1

Browse files
Merge branch 'CactuseSecurity:develop' into develop
2 parents c3e4144 + 19faa87 commit 84902f1

16 files changed

Lines changed: 123 additions & 50 deletions

roles/common/files/fwo-api-calls/modelling/getInterfaceUsers.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ query getInterfaceUsers ($id: Int){
77
owner{
88
id
99
name
10+
app_id_external
1011
}
1112
}
1213
}

roles/lib/files/FWO.Report/ReportGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ await report.Generate(userConfig.ElementsPerFetch, apiConnection,
125125
private static async Task PrepareConnReportData(FwoOwner selectedOwner, OwnerConnectionReport ownerReport, ReportType reportType, ModellingFilter modellingFilter,
126126
ApiConnection apiConnection, UserConfig userConfig, Action<Exception?, string, string, bool> displayMessageInUi)
127127
{
128-
ModellingHandlerBase handlerBase = new(apiConnection, userConfig, new(), false, displayMessageInUi);
128+
ModellingHandlerBase handlerBase = new(apiConnection, userConfig, new(), false, displayMessageInUi, true, false);
129129
foreach (var conn in ownerReport.Connections)
130130
{
131131
await handlerBase.ExtractUsedInterface(conn);

roles/lib/files/FWO.Services/Modelling/ModellingAppServerHandler.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ public class ModellingAppServerHandler : ModellingHandlerBase
1515

1616

1717
public ModellingAppServerHandler(ApiConnection apiConnection, UserConfig userConfig, FwoOwner application,
18-
ModellingAppServer appServer, List<ModellingAppServer> availableAppServers, bool addMode, Action<Exception?, string, string, bool> displayMessageInUi)
19-
: base(apiConnection, userConfig, application, addMode, displayMessageInUi)
18+
ModellingAppServer appServer, List<ModellingAppServer> availableAppServers, bool addMode,
19+
Action<Exception?, string, string, bool> displayMessageInUi, bool readOnly, bool isOwner)
20+
: base(apiConnection, userConfig, application, addMode, displayMessageInUi, readOnly, isOwner)
2021
{
2122
ActAppServer = appServer;
2223
AvailableAppServers = availableAppServers;
@@ -35,7 +36,16 @@ public async Task<bool> Save()
3536
}
3637
if (CheckAppServer())
3738
{
39+
if(IsOwner)
40+
{
41+
apiConnection.SetRole(Roles.Admin); // usual modeller has no write permission on App Servers
42+
}
3843
(long? appServerId, string? ExistingAppServerName) = await AppServerHelper.UpsertAppServer(apiConnection, userConfig, ActAppServer, !userConfig.DnsLookup, true, AddMode);
44+
if(IsOwner)
45+
{
46+
apiConnection.SwitchBack();
47+
}
48+
3949
if (appServerId != null)
4050
{
4151
if (AddMode)

roles/lib/files/FWO.Services/Modelling/ModellingAppServerListHandler.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public class ModellingAppServerListHandler : ModellingHandlerBase
2020

2121

2222
public ModellingAppServerListHandler(ApiConnection apiConnection, UserConfig userConfig,
23-
Action<Exception?, string, string, bool> displayMessageInUi)
24-
: base(apiConnection, userConfig, new FwoOwner(), false, displayMessageInUi)
23+
Action<Exception?, string, string, bool> displayMessageInUi, bool readOnly, bool isOwner)
24+
: base(apiConnection, userConfig, new FwoOwner(), false, displayMessageInUi, readOnly, isOwner)
2525
{ }
2626

2727
public async Task Init(FwoOwner application)
@@ -59,7 +59,7 @@ public void HandleAppServer(ModellingAppServer appServer)
5959
{
6060
try
6161
{
62-
AppServerHandler = new ModellingAppServerHandler(apiConnection, userConfig, Application, appServer, ManualAppServers, AddAppServerMode, DisplayMessageInUi);
62+
AppServerHandler = new ModellingAppServerHandler(apiConnection, userConfig, Application, appServer, ManualAppServers, AddAppServerMode, DisplayMessageInUi, ReadOnly, IsOwner);
6363
EditAppServerMode = true;
6464
}
6565
catch (Exception exception)
@@ -79,7 +79,10 @@ public async Task DeleteAppServer()
7979
{
8080
try
8181
{
82-
apiConnection.SetRole(Roles.Admin);
82+
if(IsOwner)
83+
{
84+
apiConnection.SetRole(Roles.Admin); // usual modeller has no write permission on App Servers
85+
}
8386
if (await CheckAppServerInUse(actAppServer))
8487
{
8588
await apiConnection.SendQueryAsync<ReturnId>(ModellingQueries.setAppServerDeletedState, new { id = actAppServer.Id, deleted = true });
@@ -93,7 +96,10 @@ await LogChange(ModellingTypes.ChangeType.Delete, ModellingTypes.ModObjectType.A
9396
}
9497
await AppServerHelper.ReactivateOtherSource(apiConnection, userConfig, actAppServer);
9598
await Init(Application);
96-
apiConnection.SwitchBack();
99+
if(IsOwner)
100+
{
101+
apiConnection.SwitchBack();
102+
}
97103
DeleteAppServerMode = false;
98104
}
99105
catch (Exception exception)
@@ -115,10 +121,18 @@ public async Task ReactivateAppServer()
115121
{
116122
if (actAppServer.IsDeleted)
117123
{
124+
if(IsOwner)
125+
{
126+
apiConnection.SetRole(Roles.Admin); // usual modeller has no write permission on App Servers
127+
}
118128
await apiConnection.SendQueryAsync<ReturnId>(ModellingQueries.setAppServerDeletedState, new { id = actAppServer.Id, deleted = false });
119129
await LogChange(ModellingTypes.ChangeType.Reactivate, ModellingTypes.ModObjectType.AppServer, actAppServer.Id,
120130
$"Reactivate App Server: {actAppServer.Display()}", Application.Id);
121131
await AppServerHelper.DeactivateOtherSources(apiConnection, userConfig, actAppServer);
132+
if(IsOwner)
133+
{
134+
apiConnection.SwitchBack();
135+
}
122136
await Init(Application);
123137
}
124138
ReactivateAppServerMode = false;

roles/lib/files/FWO.Services/Modelling/ModellingConnectionHandlerNwObjHandling.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ public void DisplayAppServer(ModellingAppServer? appServer)
353353
{
354354
try
355355
{
356-
AppServerHandler = new(apiConnection, userConfig, Application, appServer, [], false, DisplayMessageInUi) { ReadOnly = true };
356+
AppServerHandler = new(apiConnection, userConfig, Application, appServer, [], false, DisplayMessageInUi, ReadOnly, IsOwner) { ReadOnly = true };
357357
DisplayAppServerMode = true;
358358
}
359359
catch (Exception exception)

roles/lib/files/FWO.Services/Modelling/ModellingHandlerBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class ModellingHandlerBase
4848
private const string DeactMsg = "C9001";
4949

5050
public ModellingHandlerBase(ApiConnection apiConnection, UserConfig userConfig, FwoOwner application,
51-
bool addMode, Action<Exception?, string, string, bool> displayMessageInUi, bool readOnly = false, bool isOwner = true)
51+
bool addMode, Action<Exception?, string, string, bool> displayMessageInUi, bool readOnly, bool isOwner)
5252
{
5353
this.apiConnection = apiConnection;
5454
this.userConfig = userConfig;

roles/tests-unit/files/FWO.Test/ModellingAppServerHandlerTest.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ public async Task Save_ReturnsFalse_WhenMissingIpOrCustomType()
4343
new ModellingAppServer { Ip = "", CustomType = 1 },
4444
[],
4545
false,
46-
(_, _, message, _) => lastMessage = message
46+
(_, _, message, _) => lastMessage = message,
47+
false,
48+
false
4749
);
4850

4951
bool result = await handler.Save();
@@ -64,7 +66,9 @@ public async Task Save_ReturnsFalse_WhenIpInvalid_AndSetsManualImport()
6466
appServer,
6567
[],
6668
false,
67-
(_, _, message, _) => lastMessage = message
69+
(_, _, message, _) => lastMessage = message,
70+
false,
71+
false
6872
);
6973

7074
bool result = await handler.Save();
@@ -93,7 +97,9 @@ public void Reset_RestoresOriginalValues_AndUpdatesList()
9397
appServer,
9498
available,
9599
false,
96-
(_, _, _, _) => { }
100+
(_, _, _, _) => { },
101+
false,
102+
false
97103
);
98104

99105
handler.ActAppServer.Name = "changed";

roles/ui/files/FWO.UI/Pages/Monitoring/MonitorModelling.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
{
6161
try
6262
{
63-
HandlerBase = new(apiConnection, userConfig, new(), false, DisplayMessageInUi);
63+
HandlerBase = new(apiConnection, userConfig, new(), false, DisplayMessageInUi, true, false);
6464
Owners = await apiConnection.SendQueryAsync<List<FwoOwner>>(OwnerQueries.getOwners);
6565
if (Owners.Count > 0)
6666
{

roles/ui/files/FWO.UI/Pages/NetworkModelling/EditAppRole.razor

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,14 @@
130130
{
131131
@if(AppRoleHandler.IsOwner)
132132
{
133-
<button type="button" class="btn btn-sm btn-primary" @onclick="Save">@(DisplayService.DisplayButton(userConfig, "save", Icons.Save))</button>
133+
<AuthorizeView Roles="@Roles.Modeller">
134+
<Authorized>
135+
<button type="button" class="btn btn-sm btn-primary" @onclick="Save">@(DisplayService.DisplayButton(userConfig, "save", Icons.Save))</button>
136+
</Authorized>
137+
<NotAuthorized>
138+
<button type="button" class="btn btn-sm btn-primary" disabled>@(DisplayService.DisplayButton(userConfig, "save", Icons.Save))</button>
139+
</NotAuthorized>
140+
</AuthorizeView>
134141
}
135142
else
136143
{

roles/ui/files/FWO.UI/Pages/NetworkModelling/EditConn.razor

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,14 @@
414414
{
415415
@if((ConnHandler.IsOwner || ConnHandler.ActConn.IsRequested) && !(ConnHandler.ActConn.GetBoolProperty(ConState.Rejected.ToString()) || ConnHandler.ActConn.GetBoolProperty(ConState.Decommissioned.ToString())))
416416
{
417-
<button type="button" class="btn btn-sm btn-primary" @onclick="Save">@(DisplayService.DisplayButton(userConfig, "save", Icons.Save))</button>
417+
<AuthorizeView Roles="@Roles.Modeller">
418+
<Authorized>
419+
<button type="button" class="btn btn-sm btn-primary" @onclick="Save">@(DisplayService.DisplayButton(userConfig, "save", Icons.Save))</button>
420+
</Authorized>
421+
<NotAuthorized>
422+
<button type="button" class="btn btn-sm btn-primary" disabled>@(DisplayService.DisplayButton(userConfig, "save", Icons.Save))</button>
423+
</NotAuthorized>
424+
</AuthorizeView>
418425
}
419426
else
420427
{

0 commit comments

Comments
 (0)