Skip to content

Commit

Permalink
terms and condition changes
Browse files Browse the repository at this point in the history
  • Loading branch information
hkf-tech committed Aug 27, 2021
1 parent b14a909 commit ba4c5b2
Show file tree
Hide file tree
Showing 18 changed files with 329 additions and 40 deletions.
3 changes: 2 additions & 1 deletion src/SFA.DAS.EAS.Employer_Account.Database/Tables/User.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
[Email] NVARCHAR(255) NOT NULL UNIQUE,
[FirstName] NVARCHAR(MAX) NULL,
[LastName] NVARCHAR(MAX) NULL,
[CorrelationId] NVARCHAR(255) NULL
[CorrelationId] NVARCHAR(255) NULL,
[TermAndConditionsAcceptedOn] DATETIME NULL
)
GO

Expand Down
24 changes: 22 additions & 2 deletions src/SFA.DAS.EmployerAccounts.Web/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ public async Task<ActionResult> Index()
{
return Redirect(ConfigurationFactory.Current.Get().AccountActivationUrl);
}

var userRef = OwinWrapper.GetClaimValue(ControllerConstants.UserRefClaimKeyName);
var email = OwinWrapper.GetClaimValue(ControllerConstants.EmailClaimKeyName);
var firstName = OwinWrapper.GetClaimValue(DasClaimTypes.GivenName);
var lastName = OwinWrapper.GetClaimValue(DasClaimTypes.FamilyName);

await _homeOrchestrator.SaveUpdatedIdentityAttributes(userRef, email, firstName, lastName);

accounts = await _homeOrchestrator.GetUserAccounts(userId);
accounts = await _homeOrchestrator.GetUserAccounts(userId, _configuration.LastTermsAndConditionsUpdate);
}
else
{
Expand Down Expand Up @@ -110,6 +110,26 @@ public async Task<ActionResult> Index()
return RedirectToAction(ControllerConstants.GetApprenticeshipFundingActionName, ControllerConstants.EmployerAccountControllerName);
}


[HttpGet]
[DasAuthorize]
[Route("termsAndConditions")]
public ActionResult TermsAndConditions(string returnUrl)
{
var termsAndConditionViewModel = new TermsAndConditionViewModel { ReturnUrl = returnUrl };
return View(termsAndConditionViewModel);
}

[HttpPost]
[DasAuthorize]
[Route("termsAndConditions")]
public async Task<ActionResult> TermsAndConditions(TermsAndConditionViewModel termsAndConditionViewModel)
{
var userRef = OwinWrapper.GetClaimValue(ControllerConstants.UserRefClaimKeyName);
await _homeOrchestrator.UpdateTermAndConditionsAcceptedOn(userRef);
return RedirectToAction(nameof(Index));
}

[DasAuthorize]
[Route("SaveAndSearch")]
public async Task<ActionResult> SaveAndSearch(string returnUrl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using SFA.DAS.EmployerAccounts.Commands.RemoveTeamMember;
using SFA.DAS.EmployerAccounts.Commands.ResendInvitation;
using SFA.DAS.EmployerAccounts.Commands.UpdateShowWizard;
using SFA.DAS.EmployerAccounts.Configuration;
using SFA.DAS.EmployerAccounts.Interfaces;
using SFA.DAS.EmployerAccounts.Models;
using SFA.DAS.EmployerAccounts.Models.Account;
Expand All @@ -24,6 +25,7 @@
using SFA.DAS.EmployerAccounts.Queries.GetMember;
using SFA.DAS.EmployerAccounts.Queries.GetTeamUser;
using SFA.DAS.EmployerAccounts.Queries.GetUser;
using SFA.DAS.EmployerAccounts.Queries.GetUserByRef;
using SFA.DAS.EmployerAccounts.Web.ViewModels;
using SFA.DAS.Validation;
using System;
Expand All @@ -41,17 +43,20 @@ public class EmployerTeamOrchestrator : UserVerificationOrchestratorBase
private readonly ICurrentDateTime _currentDateTime;
private readonly IAccountApiClient _accountApiClient;
private readonly IMapper _mapper;
private readonly EmployerAccountsConfiguration _configuration;

public EmployerTeamOrchestrator(IMediator mediator,
ICurrentDateTime currentDateTime,
IAccountApiClient accountApiClient,
IMapper mapper)
IMapper mapper,
EmployerAccountsConfiguration configuration)
: base(mediator)
{
_mediator = mediator;
_currentDateTime = currentDateTime;
_accountApiClient = accountApiClient;
_mapper = mapper;
_configuration = configuration;
}
//Needed for tests
protected EmployerTeamOrchestrator()
Expand Down Expand Up @@ -179,14 +184,20 @@ public virtual async Task<OrchestratorResponse<AccountDashboardViewModel>> GetAc
ExternalUserId = externalUserId
});

await Task.WhenAll(apiGetAccountTask, accountStatsResponseTask, userRoleResponseTask, userResponseTask, accountStatsResponseTask, agreementsResponseTask).ConfigureAwait(false);
var userQueryResponseTask = _mediator.SendAsync(new GetUserByRefQuery
{
UserRef = externalUserId
});

await Task.WhenAll(apiGetAccountTask, accountStatsResponseTask, userRoleResponseTask, userResponseTask, accountStatsResponseTask, agreementsResponseTask, userQueryResponseTask).ConfigureAwait(false);

var accountResponse = accountResponseTask.Result;
var userRoleResponse = userRoleResponseTask.Result;
var userResponse = userResponseTask.Result;
var accountStatsResponse = accountStatsResponseTask.Result;
var agreementsResponse = agreementsResponseTask.Result;
var accountDetailViewModel = apiGetAccountTask.Result;
var userQueryResponse = userQueryResponseTask.Result;

var apprenticeshipEmployerType = (ApprenticeshipEmployerType)Enum.Parse(typeof(ApprenticeshipEmployerType), accountDetailViewModel.ApprenticeshipEmployerType, true);

Expand Down Expand Up @@ -219,7 +230,9 @@ public virtual async Task<OrchestratorResponse<AccountDashboardViewModel>> GetAc
SignedAgreementCount = agreementsResponse.EmployerAgreements.Count(x => x.HasSignedAgreement),
PendingAgreements = pendingAgreements,
ApprenticeshipEmployerType = apprenticeshipEmployerType,
AgreementInfo = _mapper.Map<AccountDetailViewModel, AgreementInfoViewModel>(accountDetailViewModel)
AgreementInfo = _mapper.Map<AccountDetailViewModel, AgreementInfoViewModel>(accountDetailViewModel),
TermAndConditionsAcceptedOn = userQueryResponse.User.TermAndConditionsAcceptedOn,
LastTermsAndConditionsUpdate = _configuration.LastTermsAndConditionsUpdate
};

//note: ApprenticeshipEmployerType is already returned by GetEmployerAccountHashedQuery, but we need to transition to calling the api instead.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using SFA.DAS.Common.Domain.Types;
using SFA.DAS.EmployerAccounts.Web.Models;
using SFA.DAS.NLog.Logger;
using SFA.DAS.EmployerAccounts.Configuration;

namespace SFA.DAS.EmployerAccounts.Web.Orchestrators
{
Expand All @@ -38,8 +39,9 @@ public EmployerTeamOrchestratorWithCallToAction(
IAccountApiClient accountApiClient,
IMapper mapper,
ICookieStorageService<AccountContext> accountContext,
ILog logger)
: base(mediator, currentDateTime, accountApiClient, mapper)
ILog logger,
EmployerAccountsConfiguration configuration)
: base(mediator, currentDateTime, accountApiClient, mapper, configuration)
{
_employerTeamOrchestrator = employerTeamOrchestrator;
_accountContext = accountContext;
Expand Down
22 changes: 19 additions & 3 deletions src/SFA.DAS.EmployerAccounts.Web/Orchestrators/HomeOrchestrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using SFA.DAS.EmployerAccounts.Queries.GetUserAccounts;
using SFA.DAS.EmployerAccounts.Queries.GetUserInvitations;
using SFA.DAS.EmployerAccounts.Queries.GetUsers;
using SFA.DAS.EmployerAccounts.Queries.GetUser;
using SFA.DAS.EmployerAccounts.Queries.GetUserByRef;

namespace SFA.DAS.EmployerAccounts.Web.Orchestrators
{
Expand Down Expand Up @@ -44,7 +46,7 @@ public virtual async Task<SignInUserViewModel> GetUsers()
};
}

public virtual async Task<OrchestratorResponse<UserAccountsViewModel>> GetUserAccounts(string userId)
public virtual async Task<OrchestratorResponse<UserAccountsViewModel>> GetUserAccounts(string userId, DateTime? LastTermsAndConditionsUpdate = null)
{
var getUserAccountsQueryResponse = await _mediator.SendAsync(new GetUserAccountsQuery
{
Expand All @@ -54,12 +56,18 @@ public virtual async Task<OrchestratorResponse<UserAccountsViewModel>> GetUserAc
{
UserId = userId
});
var getUserQueryResponse = await _mediator.SendAsync(new GetUserByRefQuery
{
UserRef = userId
});
return new OrchestratorResponse<UserAccountsViewModel>
{
Data = new UserAccountsViewModel
{
Accounts = getUserAccountsQueryResponse.Accounts,
Invitations = getUserInvitationsResponse.NumberOfInvites
Invitations = getUserInvitationsResponse.NumberOfInvites,
TermAndConditionsAcceptedOn = getUserQueryResponse.User.TermAndConditionsAcceptedOn,
LastTermsAndConditionsUpdate = LastTermsAndConditionsUpdate
}
};
}
Expand Down Expand Up @@ -108,6 +116,14 @@ await _mediator.SendAsync(new UpsertRegisteredUserCommand
FirstName = firstName,
CorrelationId = correlationId
});
}
}

public virtual async Task UpdateTermAndConditionsAcceptedOn(string userRef)
{
await _mediator.SendAsync(new UpdateTermAndConditionsAcceptedOnCommand
{
UserRef = userRef
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@
<Compile Include="Models\AccountContext.cs" />
<Compile Include="Models\ReturnUrlModel.cs" />
<Compile Include="Models\HashedAccountIdModel.cs" />
<Compile Include="ViewModels\TermsAndConditionViewModel.cs" />
<Compile Include="ViewModels\TriageViewModel.cs" />
<Compile Include="OrchestratorResponse.cs" />
<Compile Include="Orchestrators\EmployerAccountOrchestrator.cs" />
Expand Down Expand Up @@ -873,6 +874,7 @@
<Content Include="Views\Shared\_Agreement_v5.cshtml" />
<Content Include="Views\Shared\_Agreement_v6.cshtml" />
<Content Include="Views\SearchOrganisation\ConfirmOrganisationDetails.cshtml" />
<Content Include="Views\Home\TermsAndConditions.cshtml" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SFA.DAS.Account.Api.Client\SFA.DAS.EAS.Account.Api.Client.csproj">
Expand Down Expand Up @@ -942,4 +944,4 @@
</Target>
<Target Name="AfterBuild">
</Target> -->
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using SFA.DAS.EmployerAccounts.Interfaces;
using SFA.DAS.EmployerAccounts.Models;
using SFA.DAS.EmployerAccounts.Models.Account;
using System;
using System.Collections.Generic;

namespace SFA.DAS.EmployerAccounts.Web.ViewModels
Expand Down Expand Up @@ -29,5 +30,23 @@ public class AccountDashboardViewModel : IAccountIdentifier
public ApprenticeshipEmployerType ApprenticeshipEmployerType { get; set; }
public CallToActionViewModel CallToActionViewModel { get; set; }
public bool HideTasksBar { get; set; }
public DateTime? TermAndConditionsAcceptedOn { get; set; }
public DateTime? LastTermsAndConditionsUpdate { get; set; }
public bool ShowTermsAndConditionBanner
{
get
{
if (LastTermsAndConditionsUpdate.HasValue)
{
if (!TermAndConditionsAcceptedOn.HasValue ||
(TermAndConditionsAcceptedOn.Value < LastTermsAndConditionsUpdate.Value))
{
return true;
}
}

return false;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace SFA.DAS.EmployerAccounts.Web.ViewModels
{
public class TermsAndConditionViewModel
{
public string ReturnUrl { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SFA.DAS.EmployerAccounts.Models.Account;
using System;

namespace SFA.DAS.EmployerAccounts.Web.ViewModels
{
Expand All @@ -8,5 +9,21 @@ public class UserAccountsViewModel
public int Invitations;
public FlashMessageViewModel FlashMessage;
public string ErrorMessage;
public DateTime? TermAndConditionsAcceptedOn { get; set; }
public DateTime? LastTermsAndConditionsUpdate { get; set; }
public bool ShowTermsAndConditionBanner { get
{
if (LastTermsAndConditionsUpdate.HasValue)
{
if (!TermAndConditionsAcceptedOn.HasValue ||
(TermAndConditionsAcceptedOn.Value < LastTermsAndConditionsUpdate.Value))
{
return true;
}
}

return false;
}
}
}
}
18 changes: 17 additions & 1 deletion src/SFA.DAS.EmployerAccounts.Web/Views/EmployerTeam/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@
}
}


@if (Model.Data.ShowTermsAndConditionBanner)
{
<div class="govuk-notification-banner" role="region" aria-labelledby="govuk-notification-banner-title" data-module="govuk-notification-banner">
<div class="govuk-notification-banner__header">
<h2 class="govuk-notification-banner__title" id="govuk-notification-banner-title">
Action required
</h2>
</div>
<div class="govuk-notification-banner__content">
<p class="govuk-notification-banner__heading">
We've updated our <a class="govuk-notification-banner__link" href="@Url.Action("TermsAndConditions", "Home")" target="_blank">terms of use</a>. By continuing to use this service you are accepting the updated terms.
</p>
</div>
</div>
}
<h1 class="heading-secondary dashboard-heading">
Account ID: @Model.Data.Account.PublicHashedId
</h1>
Expand Down Expand Up @@ -103,7 +119,7 @@ else
</div>
}

@if (Model.Data.ApprenticeshipEmployerType == ApprenticeshipEmployerType.Levy
@if (Model.Data.ApprenticeshipEmployerType == ApprenticeshipEmployerType.Levy
&& Html.IsAuthorized("EmployerFeature.TransfersMatching"))
{
<div class="card">
Expand Down
Loading

0 comments on commit ba4c5b2

Please sign in to comment.