From 66d8aed518392d12a7d58693548e4c5e6fc5a388 Mon Sep 17 00:00:00 2001 From: Rohit Shrivastava Date: Thu, 13 Mar 2025 15:57:27 +0000 Subject: [PATCH 1/2] TD-3713- Update LastAccessed Date For AdminAccounts And DelegateAccounts --- .../DataServices/LoginDataService.cs | 30 +++++++++++++++++++ .../Controllers/LoginController.cs | 6 ++-- .../Services/LoginService.cs | 14 +++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/DigitalLearningSolutions.Data/DataServices/LoginDataService.cs b/DigitalLearningSolutions.Data/DataServices/LoginDataService.cs index 37faf67778..109d5a9273 100644 --- a/DigitalLearningSolutions.Data/DataServices/LoginDataService.cs +++ b/DigitalLearningSolutions.Data/DataServices/LoginDataService.cs @@ -6,6 +6,10 @@ public interface ILoginDataService { void UpdateLastAccessedForUsersTable(int Id); + + void UpdateLastAccessedForDelegatesAccountsTable(int Id); + + void UpdateLastAccessedForAdminAccountsTable(int Id); } public class LoginDataService : ILoginDataService @@ -29,5 +33,31 @@ public void UpdateLastAccessedForUsersTable(int Id) } ); } + + public void UpdateLastAccessedForDelegatesAccountsTable(int Id) + { + connection.Execute( + @"UPDATE DelegateAccounts SET + LastAccessed = GetUtcDate() + WHERE ID = @Id", + new + { + Id + } + ); + } + + public void UpdateLastAccessedForAdminAccountsTable(int Id) + { + connection.Execute( + @"UPDATE AdminAccounts SET + LastAccessed = GetUtcDate() + WHERE ID = @Id", + new + { + Id + } + ); + } } } diff --git a/DigitalLearningSolutions.Web/Controllers/LoginController.cs b/DigitalLearningSolutions.Web/Controllers/LoginController.cs index 284530a481..f9fb365dff 100644 --- a/DigitalLearningSolutions.Web/Controllers/LoginController.cs +++ b/DigitalLearningSolutions.Web/Controllers/LoginController.cs @@ -226,11 +226,13 @@ int centreIdToLogInto IsPersistent = rememberMe, IssuedUtc = clockUtility.UtcNow, }; + var centreAccountSet = userEntity?.GetCentreAccountSet(centreIdToLogInto); + loginService.UpdateLastAccessedForDelegatesAccountsTable(centreAccountSet.DelegateAccount.Id); - var adminAccount = userEntity!.GetCentreAccountSet(centreIdToLogInto)?.AdminAccount; - + var adminAccount = centreAccountSet?.AdminAccount; if (adminAccount?.Active == true) { + loginService.UpdateLastAccessedForAdminAccountsTable(adminAccount.Id); sessionService.StartAdminSession(adminAccount.Id); } diff --git a/DigitalLearningSolutions.Web/Services/LoginService.cs b/DigitalLearningSolutions.Web/Services/LoginService.cs index 6960e920cf..dc52aca0b5 100644 --- a/DigitalLearningSolutions.Web/Services/LoginService.cs +++ b/DigitalLearningSolutions.Web/Services/LoginService.cs @@ -32,6 +32,10 @@ List idsOfCentresWithUnverifiedEmails void UpdateLastAccessedForUsersTable(int Id); + void UpdateLastAccessedForDelegatesAccountsTable(int Id); + + void UpdateLastAccessedForAdminAccountsTable(int Id); + Task HandleLoginResult( LoginResult loginResult, TicketReceivedContext context, @@ -59,6 +63,16 @@ public void UpdateLastAccessedForUsersTable(int Id) loginDataService.UpdateLastAccessedForUsersTable(Id); } + public void UpdateLastAccessedForDelegatesAccountsTable(int Id) + { + loginDataService.UpdateLastAccessedForDelegatesAccountsTable(Id); + } + + public void UpdateLastAccessedForAdminAccountsTable(int Id) + { + loginDataService.UpdateLastAccessedForAdminAccountsTable(Id); + } + public LoginResult AttemptLogin(string username, string password) { var userEntity = userService.GetUserByUsername(username); From 01774db0ec21281d0c406d6849d054f140324ee1 Mon Sep 17 00:00:00 2001 From: Rohit Shrivastava Date: Thu, 13 Mar 2025 16:55:29 +0000 Subject: [PATCH 2/2] TD-3713 Addressing test fail for the case when only admin account is present --- DigitalLearningSolutions.Web/Controllers/LoginController.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/DigitalLearningSolutions.Web/Controllers/LoginController.cs b/DigitalLearningSolutions.Web/Controllers/LoginController.cs index f9fb365dff..968535144d 100644 --- a/DigitalLearningSolutions.Web/Controllers/LoginController.cs +++ b/DigitalLearningSolutions.Web/Controllers/LoginController.cs @@ -227,7 +227,11 @@ int centreIdToLogInto IssuedUtc = clockUtility.UtcNow, }; var centreAccountSet = userEntity?.GetCentreAccountSet(centreIdToLogInto); - loginService.UpdateLastAccessedForDelegatesAccountsTable(centreAccountSet.DelegateAccount.Id); + + if (centreAccountSet?.DelegateAccount?.Id != null) + { + loginService.UpdateLastAccessedForDelegatesAccountsTable(centreAccountSet.DelegateAccount.Id); + } var adminAccount = centreAccountSet?.AdminAccount; if (adminAccount?.Active == true)