From f81c90e5eeaec09d37120a34ad510814bf9b1ec6 Mon Sep 17 00:00:00 2001 From: Paul Howes <paul.howes@cognetics.net> Date: Tue, 11 Aug 2020 11:29:47 +0100 Subject: [PATCH 1/2] Update EmployerFeatureAuthorisationHandler.cs --- .../Authorisation/EmployerFeatureAuthorisationHandler.cs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) 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<AuthorizationResult> 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()); } From adeaa33ddcae39c97040c8edae0304f3392148e9 Mon Sep 17 00:00:00 2001 From: Paul Howes <paul.howes@cognetics.net> Date: Tue, 11 Aug 2020 13:27:29 +0100 Subject: [PATCH 2/2] Update EmployerFeatureAuthorisationHandlerTests.cs --- .../Authorisation/EmployerFeatureAuthorisationHandlerTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 } - } } };