Skip to content

Commit

Permalink
updates to validation
Browse files Browse the repository at this point in the history
  • Loading branch information
leewrigh committed Nov 8, 2024
1 parent 2e20e24 commit d976521
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 43 deletions.
54 changes: 25 additions & 29 deletions backend/webapi/Features/AccessRequests/ValidateUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ IKafkaProducer<string, Notification> kafkaNotificationProducer
public async Task<IDomainResult<UserValidationResponse>> HandleAsync(Command command)
{

var sameCodeEntered = false;
// see if this code is already active and complete
var priorAccessRequest = dbContext.DigitalEvidencePublicDisclosures.Where(req => req.KeyData == command.Code).FirstOrDefault();

Expand All @@ -69,8 +70,6 @@ public async Task<IDomainResult<UserValidationResponse>> HandleAsync(Command com

}

// start a transaction
using var transaction = dbContext.Database.BeginTransaction();
try
{

Expand Down Expand Up @@ -103,13 +102,7 @@ public async Task<IDomainResult<UserValidationResponse>> HandleAsync(Command com

};

if (retries >= configuration.EdtClient.MaxClientValidations)
{
response.TooManyAttempts = true;
await this.NotifyTooManyAttempts(party, priorRequests);
return DomainResult.Success(response);

}


var validation = new PublicUserValidation
Expand All @@ -120,27 +113,16 @@ public async Task<IDomainResult<UserValidationResponse>> HandleAsync(Command com
IsValid = false
};

if (priorRequests != null && priorRequests.Count > 0)
{
var sameCodeAttempt = priorRequests.FirstOrDefault(req => req.Party == party && req.Code == command.Code);
if (sameCodeAttempt != null)
{
Serilog.Log.Information($"User {party.Id} entered duplicated code");
sameCodeAttempt.Modified = clock.GetCurrentInstant();
}
else
{
dbContext.PublicUserValidations.Add(validation);

}
}
else
var sameCodeAttempt = priorRequests.FirstOrDefault(req => req.Party == party && req.Code == command.Code);
if (sameCodeAttempt != null)
{
dbContext.PublicUserValidations.Add(validation);
Serilog.Log.Information($"User {party.Id} entered duplicated code");
validation = sameCodeAttempt;
sameCodeEntered = true;
}



// get the user primaryParticipant from the EdtService
EdtPersonDto? primaryParticipant = null;

Expand Down Expand Up @@ -173,30 +155,44 @@ public async Task<IDomainResult<UserValidationResponse>> HandleAsync(Command com

// if any users are returned then the OTC is valid for at least one of them
response.Validated = true;

validation.IsValid = true;
dbContext.PublicUserValidations.Add(validation);

var updates = await dbContext.SaveChangesAsync();
Serilog.Log.Debug($"{updates} public request records added");
validation.IsValid = true;

await transaction.CommitAsync();

return DomainResult.Success(response);
}
else
{
if (retries >= configuration.EdtClient.MaxClientValidations)
{
response.TooManyAttempts = true;
await this.NotifyTooManyAttempts(party, priorRequests);
return DomainResult.Success(response);

}

if (!sameCodeEntered)
{
dbContext.PublicUserValidations.Add(validation);
}
else
{
validation.Modified = clock.GetCurrentInstant();

}
var updates = await dbContext.SaveChangesAsync();
Serilog.Log.Debug($"{updates} public request records added");
Serilog.Log.Information($"No users found with identifier {command.Code}");
response.Message = "Invalid code provided";
await transaction.CommitAsync();
return DomainResult.Success(response);
}
}
catch (Exception ex)
{
Serilog.Log.Error($"Person validation error: {ex.Message}");
await transaction.RollbackAsync();
throw;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,22 +163,22 @@ <h4>Current and previous case access requests:</h4>
<div class="col-12">
<div class="col-md-4 col-sm-12 mt-3">
<mat-form-field class="code-entry mat-elevation-z16">
<input class="formControl"
matInput
placeholder="Enter Code"
formControlName="OOCUniqueId"
mask="000-000"
#codeInput
[readonly]="false"
(keyup)="checkCodeInput()" />
<input
id="OOCUniqueId"
class="formControl"
matInput
placeholder="Enter Code"
formControlName="OOCUniqueId"
mask="000-000"
[readonly]="false" />
</mat-form-field>
<div *ngIf="validatingUser" class="col-md-4">
<mat-spinner class="spinner" [diameter]="60"></mat-spinner>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div class="col-12 align-middle my-auto">
<div
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { HttpErrorResponse, HttpStatusCode } from '@angular/common/http';
import { Component, Inject, OnInit, ViewEncapsulation } from '@angular/core';
import {
AfterViewInit,
Component,
ElementRef,
Inject,
OnInit,
ViewChild,
ViewChildren,
} from '@angular/core';
import { FormBuilder, Validators } from '@angular/forms';
import { MatDialog } from '@angular/material/dialog';
import { MatTableDataSource } from '@angular/material/table';
Expand Down Expand Up @@ -312,9 +320,8 @@ export class DigitalEvidencePage
return input;
}

public checkCodeInput(): void {
const codeValue = this.formState.OOCUniqueId.value;
if (codeValue && codeValue.length === 6) {
public checkCodeInput(inputVal: string): void {
if (inputVal && inputVal.length === 6) {
this.checkUniqueID();
}
}
Expand Down Expand Up @@ -526,6 +533,10 @@ export class DigitalEvidencePage
this.formState.AssignedRegions.setValidators([Validators.required]);
}
});

this.formState.form.get('OOCUniqueId')?.valueChanges.subscribe((change) => {
this.checkCodeInput(change);
});
}

public validateDefenceId(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ export class AuthorizedUserService {
if (submittingAgency != null) {
return new SubmittingAgencyResolver(userIdentity);
}
debugger;
if (
userIdentity.accessTokenParsed?.['identity_provider'] === undefined &&
userIdentity.accessTokenParsed.preferred_username.startsWith('tst')
Expand Down

0 comments on commit d976521

Please sign in to comment.