Skip to content

Commit

Permalink
Merge branch 'main' into juj/UpdateJobParams
Browse files Browse the repository at this point in the history
  • Loading branch information
FirestarJes committed Sep 24, 2024
2 parents bf8c1e9 + d77a2d0 commit 68e8669
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,23 @@ await _revisionLogClient.LogAsync(
payload: System.Text.Json.JsonSerializer.Serialize(settlementReportRequest)))
.ConfigureAwait(false);

if (_userContext.CurrentUser.Actor.MarketRole == FrontendActorMarketRole.EnergySupplier && string.IsNullOrWhiteSpace(settlementReportRequest.Filter.EnergySupplier))
var marketRole = _userContext.CurrentUser.Actor.MarketRole switch
{
FrontendActorMarketRole.Other => MarketRole.Other,
FrontendActorMarketRole.GridAccessProvider => MarketRole.GridAccessProvider,
FrontendActorMarketRole.EnergySupplier => MarketRole.EnergySupplier,
FrontendActorMarketRole.SystemOperator => MarketRole.SystemOperator,
FrontendActorMarketRole.DataHubAdministrator => MarketRole.DataHubAdministrator,
_ => throw new ArgumentOutOfRangeException(nameof(_userContext.CurrentUser.Actor.MarketRole)),
};

if (_userContext.CurrentUser is { MultiTenancy: true, Actor.MarketRole: FrontendActorMarketRole.DataHubAdministrator } &&
settlementReportRequest.MarketRoleOverride.HasValue)
{
marketRole = settlementReportRequest.MarketRoleOverride.Value;
}

if (marketRole == MarketRole.EnergySupplier && string.IsNullOrWhiteSpace(settlementReportRequest.Filter.EnergySupplier))
{
settlementReportRequest = settlementReportRequest with
{
Expand All @@ -75,7 +91,7 @@ await _revisionLogClient.LogAsync(
};
}

if (!IsValid(settlementReportRequest))
if (!IsValid(settlementReportRequest, marketRole))
{
return req.CreateResponse(HttpStatusCode.Forbidden);
}
Expand All @@ -86,16 +102,6 @@ await _revisionLogClient.LogAsync(
return req.CreateResponse(HttpStatusCode.BadRequest);
}

var marketRole = _userContext.CurrentUser.Actor.MarketRole switch
{
FrontendActorMarketRole.Other => MarketRole.Other,
FrontendActorMarketRole.GridAccessProvider => MarketRole.GridAccessProvider,
FrontendActorMarketRole.EnergySupplier => MarketRole.EnergySupplier,
FrontendActorMarketRole.SystemOperator => MarketRole.SystemOperator,
FrontendActorMarketRole.DataHubAdministrator => MarketRole.DataHubAdministrator,
_ => throw new ArgumentOutOfRangeException(nameof(_userContext.CurrentUser.Actor.MarketRole)),
};

var chargeOwnerId = marketRole is MarketRole.GridAccessProvider or MarketRole.SystemOperator
? _userContext.CurrentUser.Actor.ActorNumber
: null;
Expand Down Expand Up @@ -125,16 +131,14 @@ await response
return response;
}

private bool IsValid(SettlementReportRequestDto req)
private bool IsValid(SettlementReportRequestDto req, MarketRole marketRole)
{
if (_userContext.CurrentUser.MultiTenancy)
{
return true;
}

var marketRole = _userContext.CurrentUser.Actor.MarketRole;

if (marketRole == FrontendActorMarketRole.GridAccessProvider)
if (marketRole == MarketRole.GridAccessProvider)
{
if (!string.IsNullOrWhiteSpace(req.Filter.EnergySupplier))
{
Expand All @@ -144,12 +148,12 @@ private bool IsValid(SettlementReportRequestDto req)
return req.Filter.GridAreas.All(x => _userContext.CurrentUser.Actor.GridAreas.Contains(x.Key));
}

if (marketRole == FrontendActorMarketRole.EnergySupplier)
if (marketRole == MarketRole.EnergySupplier)
{
return req.Filter.EnergySupplier == _userContext.CurrentUser.Actor.ActorNumber;
}

if (marketRole == FrontendActorMarketRole.SystemOperator &&
if (marketRole == MarketRole.SystemOperator &&
req.Filter.CalculationType != CalculationType.BalanceFixing &&
req.Filter.CalculationType != CalculationType.Aggregation)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public sealed record SettlementReportRequestDto(
bool PreventLargeTextFiles,
bool IncludeBasisData,
bool IncludeMonthlyAmount,
SettlementReportRequestFilterDto Filter);
SettlementReportRequestFilterDto Filter,
MarketRole? MarketRoleOverride = null);
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,23 @@ public SettlementReportsController(
[EnableRevision(activityName: "RequestSettlementReportAPI", entityType: typeof(SettlementReportRequestDto))]
public async Task<ActionResult<long>> RequestSettlementReport([FromBody] SettlementReportRequestDto settlementReportRequest)
{
if (_userContext.CurrentUser.Actor.MarketRole == FrontendActorMarketRole.EnergySupplier && string.IsNullOrWhiteSpace(settlementReportRequest.Filter.EnergySupplier))
var marketRole = _userContext.CurrentUser.Actor.MarketRole switch
{
FrontendActorMarketRole.Other => MarketRole.Other,
FrontendActorMarketRole.GridAccessProvider => MarketRole.GridAccessProvider,
FrontendActorMarketRole.EnergySupplier => MarketRole.EnergySupplier,
FrontendActorMarketRole.SystemOperator => MarketRole.SystemOperator,
FrontendActorMarketRole.DataHubAdministrator => MarketRole.DataHubAdministrator,
_ => throw new ArgumentOutOfRangeException(nameof(_userContext.CurrentUser.Actor.MarketRole)),
};

if (_userContext.CurrentUser is { MultiTenancy: true, Actor.MarketRole: FrontendActorMarketRole.DataHubAdministrator } &&
settlementReportRequest.MarketRoleOverride.HasValue)
{
marketRole = settlementReportRequest.MarketRoleOverride.Value;
}

if (marketRole == MarketRole.EnergySupplier && string.IsNullOrWhiteSpace(settlementReportRequest.Filter.EnergySupplier))
{
settlementReportRequest = settlementReportRequest with
{
Expand All @@ -65,7 +81,7 @@ public async Task<ActionResult<long>> RequestSettlementReport([FromBody] Settlem
};
}

if (!IsValid(settlementReportRequest))
if (!IsValid(settlementReportRequest, marketRole))
{
return Forbid();
}
Expand All @@ -76,16 +92,6 @@ public async Task<ActionResult<long>> RequestSettlementReport([FromBody] Settlem
return BadRequest();
}

var marketRole = _userContext.CurrentUser.Actor.MarketRole switch
{
FrontendActorMarketRole.Other => MarketRole.Other,
FrontendActorMarketRole.GridAccessProvider => MarketRole.GridAccessProvider,
FrontendActorMarketRole.EnergySupplier => MarketRole.EnergySupplier,
FrontendActorMarketRole.SystemOperator => MarketRole.SystemOperator,
FrontendActorMarketRole.DataHubAdministrator => MarketRole.DataHubAdministrator,
_ => throw new ArgumentOutOfRangeException(nameof(_userContext.CurrentUser.Actor.MarketRole)),
};

var chargeOwnerId = marketRole is MarketRole.GridAccessProvider or MarketRole.SystemOperator
? _userContext.CurrentUser.Actor.ActorNumber
: null;
Expand Down Expand Up @@ -142,16 +148,14 @@ await _downloadHandler
}
}

private bool IsValid(SettlementReportRequestDto req)
private bool IsValid(SettlementReportRequestDto req, MarketRole marketRole)
{
if (_userContext.CurrentUser.MultiTenancy)
{
return true;
}

var marketRole = _userContext.CurrentUser.Actor.MarketRole;

if (marketRole == FrontendActorMarketRole.GridAccessProvider)
if (marketRole == MarketRole.GridAccessProvider)
{
if (!string.IsNullOrWhiteSpace(req.Filter.EnergySupplier))
{
Expand All @@ -161,12 +165,12 @@ private bool IsValid(SettlementReportRequestDto req)
return req.Filter.GridAreas.All(x => _userContext.CurrentUser.Actor.GridAreas.Contains(x.Key));
}

if (marketRole == FrontendActorMarketRole.EnergySupplier)
if (marketRole == MarketRole.EnergySupplier)
{
return req.Filter.EnergySupplier == _userContext.CurrentUser.Actor.ActorNumber;
}

if (marketRole == FrontendActorMarketRole.SystemOperator &&
if (marketRole == MarketRole.SystemOperator &&
req.Filter.CalculationType != CalculationType.BalanceFixing &&
req.Filter.CalculationType != CalculationType.Aggregation)
{
Expand Down

0 comments on commit 68e8669

Please sign in to comment.