diff --git a/src/SFA.DAS.EmployerAccounts.UnitTests/Authorisation/EmployerFeatureAuthorisationHandlerTests.cs b/src/SFA.DAS.EmployerAccounts.UnitTests/Authorisation/EmployerFeatureAuthorisationHandlerTests.cs index b776d053b4..0ad7e0fe62 100644 --- a/src/SFA.DAS.EmployerAccounts.UnitTests/Authorisation/EmployerFeatureAuthorisationHandlerTests.cs +++ b/src/SFA.DAS.EmployerAccounts.UnitTests/Authorisation/EmployerFeatureAuthorisationHandlerTests.cs @@ -146,9 +146,9 @@ public EmployerFeatureAuthorisationHandlerTestsFixture SetMediatorResponse(int a StatusId = agreementStatus, AccountLegalEntity = new AccountLegalEntity { - SignedAgreementVersion = agreementVersion + SignedAgreementVersion = agreementStatus == EmployerAgreementStatus.Signed ? (int?)agreementVersion : null, + PendingAgreementVersion = agreementStatus == EmployerAgreementStatus.Pending ? (int?)agreementVersion : null } - } } }; diff --git a/src/SFA.DAS.EmployerAccounts/Authorisation/EmployerFeatureAuthorisationHandler.cs b/src/SFA.DAS.EmployerAccounts/Authorisation/EmployerFeatureAuthorisationHandler.cs index f7adfe8b70..8783114819 100644 --- a/src/SFA.DAS.EmployerAccounts/Authorisation/EmployerFeatureAuthorisationHandler.cs +++ b/src/SFA.DAS.EmployerAccounts/Authorisation/EmployerFeatureAuthorisationHandler.cs @@ -44,14 +44,9 @@ public async Task GetAuthorizationResult(IReadOnlyCollectio var (accountId, _) = authorizationContext.GetEmployerFeatureValues(); var agreements = await _mediator.SendAsync(new GetEmployerAgreementsByAccountIdRequest { AccountId = accountId.GetValueOrDefault(0) }).ConfigureAwait(false); + var minAgreementVersion = agreements.EmployerAgreements.Select(ea => ea.AccountLegalEntity.SignedAgreementVersion.GetValueOrDefault(0)).Min(); - var minAgreementVersion = agreements.EmployerAgreements. - Where(a => a.StatusId == Models.EmployerAgreement.EmployerAgreementStatus.Signed && - a.AccountLegalEntity.SignedAgreementVersion.GetValueOrDefault(0) > 0).Select(b => b.AccountLegalEntity.SignedAgreementVersion ?? 0) - .DefaultIfEmpty() - .Min(); - - if (minAgreementVersion < featureToggle.EnabledByAgreementVersion || agreements.EmployerAgreements.Any(a => a.StatusId == Models.EmployerAgreement.EmployerAgreementStatus.Pending)) + if (minAgreementVersion < featureToggle.EnabledByAgreementVersion) { authorizationResult.AddError(new EmployerFeatureAgreementNotSigned()); }