Skip to content

Commit

Permalink
Merge pull request #638 from bcgov/prodmerge
Browse files Browse the repository at this point in the history
Prodmerge promote
  • Loading branch information
leewrigh authored Sep 8, 2024
2 parents 7ec26b0 + 05714c7 commit 9b518d8
Show file tree
Hide file tree
Showing 81 changed files with 822 additions and 428 deletions.
97 changes: 0 additions & 97 deletions .github/workflows/build-push-sso-dev.yml

This file was deleted.

90 changes: 0 additions & 90 deletions .github/workflows/sso-ci.yml

This file was deleted.

5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,8 @@ FodyWeavers.xsd
/diam-config/.idea/workspace.xml
/diam-admin-react
/Infra/terraform/keycloak
/auth
/BlazorAdmin
/backend/DIAMAdminServer
/keycloak/extensions
/backend/service.edt/appsettings.Development.json
7 changes: 5 additions & 2 deletions backend/ApprovalFlow/ApprovalFlow.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Version>1.1.5</Version>
<Version>1.1.7</Version>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\common\Common.csproj" />
</ItemGroup>
<ProjectReference Include="..\CommonModels\CommonModels.csproj" />
<ProjectReference Include="..\CommonConstants\CommonConstants.csproj" />

</ItemGroup>

<ItemGroup>
<Folder Include="API\v1\" />
Expand Down
2 changes: 1 addition & 1 deletion backend/ApprovalFlow/Data/Approval/ApprovalHistory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ApprovalHistory : BaseAuditable
public string DecisionNote { get; set; } = string.Empty;
public string Approver { get; set; } = string.Empty;
public int RequestId { get; set; }
public Request AccessRequest { get; set; }
public Request AccessRequest { get; set; } = default!;
public Instant? Deleted { get; set; }
public ApprovalStatus Status { get; set; } = ApprovalStatus.PENDING;

Expand Down
19 changes: 16 additions & 3 deletions backend/ApprovalFlow/Data/Approval/ApprovalRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public class ApprovalRequest : BaseAuditable
{
[Key]
public int Id { get; set; }
public string Reason { get; set; } = string.Empty;
[Required]
public string MessageKey { get; set; } = string.Empty;
public string UserId { get; set; } = string.Empty;
Expand All @@ -21,9 +20,23 @@ public class ApprovalRequest : BaseAuditable
public string RequiredAccess { get; set; } = string.Empty;
public Instant? Approved { get; set; }
public Instant? Completed { get; set; }
public ICollection<PersonalIdentity> PersonalIdentities { get; set; } = new List<PersonalIdentity>();
public ICollection<PersonalIdentity> PersonalIdentities { get; set; } = [];
public ICollection<ApprovalRequestReasons> Reasons { get; set; } = [];

public ICollection<Request> Requests { get; set; } = [];

}

[Table(nameof(ApprovalRequestReasons))]
public class ApprovalRequestReasons : BaseAuditable
{
[Key]
public int Id { get; set; }
[Required]
public string Reason { get; set; } = string.Empty;
public ApprovalRequest ApprovalRequest { get; set; } = default!;
public int ApprovalRequestId { get; set; }

public ICollection<Request> Requests { get; set; } = new List<Request>();

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
modelBuilder.HasDefaultSchema("approvalflow");
base.OnModelCreating(modelBuilder);


modelBuilder
.Entity<Request>()
.Property(d => d.ApprovalType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace ApprovalFlow.Features.Approvals;
using Newtonsoft.Json;
using Serilog;

public class ApprovalResponseCommand : IRequestHandler<ApproveDenyInput, ApprovalModel>
public class ApprovalResponseCommand : IRequestHandler<ApprovalResponseInput, ApprovalModel>
{
private readonly ApprovalFlowDataStoreDbContext dbContext;
private readonly IClock clock;
Expand All @@ -36,15 +36,15 @@ public ApprovalResponseCommand(ApprovalFlowDataStoreDbContext dbContext,



public class CommandValidator : AbstractValidator<ApproveDenyInput>
public class CommandValidator : AbstractValidator<ApprovalResponseInput>
{
public CommandValidator()
{
this.RuleFor(x => x.ApprovalRequestId).GreaterThan(0);
}
}

public async Task<ApprovalModel> Handle(ApproveDenyInput input, CancellationToken cancellationToken)
public async Task<ApprovalModel> Handle(ApprovalResponseInput input, CancellationToken cancellationToken)
{
Serilog.Log.Information($"Handling incoming approval request {input.ApprovalRequestId} Approver {input.ApproverUserId} - Approved {input.Approved}");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task<ActionResult<IList<ApprovalModel>>> GetPendingApprovals([FromQ
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[Authorize(Policy = Policies.ApprovalAuthorization)]

public async Task<ActionResult<ApprovalModel>> PostApprovalResponse([FromBody] ApproveDenyInput command)
public async Task<ActionResult<ApprovalModel>> PostApprovalResponse([FromBody] ApprovalResponseInput command)
{
var user = HttpContext.User.Identities.First().Claims.FirstOrDefault( claim => claim.Type.Equals(Claims.PreferredUsername))?.Value;
command.ApproverUserId = user;
Expand Down
23 changes: 18 additions & 5 deletions backend/ApprovalFlow/Features/Approvals/ApprovalsQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,44 @@ public class PendingApprovalQueryHandler : IRequestHandler<ApprovalsQuery, IList
{
private readonly ApprovalFlowDataStoreDbContext context;
private readonly IMapper mapper;
public PendingApprovalQueryHandler(ApprovalFlowDataStoreDbContext context, IMapper mapper)
public PendingApprovalQueryHandler(ApprovalFlowDataStoreDbContext context)
{
this.context = context;
this.mapper = mapper;

var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<ApprovalRequest, ApprovalModel>();
cfg.CreateMap<ApprovalRequestReasons, ReasonModel>();
cfg.CreateMap<PersonalIdentity, PersonalIdentityModel>();
cfg.CreateMap<Request, RequestModel>();
});
this.mapper = config.CreateMapper();
}


public async Task<IList<ApprovalModel>> Handle(ApprovalsQuery request, CancellationToken cancellationToken)
{
List<ApprovalRequest> results;
if (request.PendingOnly)
{
results = this.context.ApprovalRequests.AsSplitQuery().Include(req => req.PersonalIdentities).Include(req => req.Requests).ThenInclude(req => req.History).Where(req => req.Completed == null).ToList();
results = this.context.ApprovalRequests.AsSplitQuery().Include(req => req.Reasons).Include(req => req.PersonalIdentities).Include(req => req.Requests).ThenInclude(req => req.History).Where(req => req.Completed == null).ToList();

}
else
{
results = this.context.ApprovalRequests.AsSplitQuery().Include(req => req.PersonalIdentities).Include(req => req.Requests).ThenInclude(req => req.History).ToList();
results = this.context.ApprovalRequests.AsSplitQuery().Include(req => req.Reasons).Include(req => req.PersonalIdentities).Include(req => req.Requests).ThenInclude(req => req.History).ToList();

}


if (results.Any())
{
Serilog.Log.Information($"Found {results.Count()} results");
return this.mapper.Map<List<ApprovalModel>>(results);
var mappedResults = this.mapper.Map<List<ApprovalModel>>(results);

return mappedResults;
}
else
{
Expand Down
Loading

0 comments on commit 9b518d8

Please sign in to comment.