-
Notifications
You must be signed in to change notification settings - Fork 1
TD-4383 Warn centre admins that active admin account exists when inactivating delegate account #2799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rshrirohit
merged 5 commits into
Release-2024.38
from
Develop/Features/TD-4383-Warncentreadminsthatactiveadminaccountexistswheninactivatingdelegateaccount
Sep 18, 2024
Merged
TD-4383 Warn centre admins that active admin account exists when inactivating delegate account #2799
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1d75f46
TD-4383 Warn centre admins that active admin account exists when inac…
sherif-olaboye b175fc0
TD-4383 Warn centre admins that active admin account exists when inac…
sherif-olaboye 66ae70e
Merge branch 'Release-2024.38' into Develop/Features/TD-4383-Warncent…
sherif-olaboye 5c56306
TD-4383 removing unneeded line of code
sherif-olaboye 4210151
TD-4383 Resolving clicking deactivate account showing 404 error
sherif-olaboye File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...earningSolutions.Web/Controllers/TrackingSystem/Delegates/DeactivateDelegateController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| | ||
|
|
||
| namespace DigitalLearningSolutions.Web.Controllers.TrackingSystem.Delegates | ||
| { | ||
| using System.Collections.Generic; | ||
| using System.Globalization; | ||
| using System.Linq; | ||
| using DigitalLearningSolutions.Data.Enums; | ||
| using DigitalLearningSolutions.Data.Models.User; | ||
| using DigitalLearningSolutions.Web.Attributes; | ||
| using DigitalLearningSolutions.Web.Helpers; | ||
| using DigitalLearningSolutions.Web.Models.Enums; | ||
| using DigitalLearningSolutions.Web.ServiceFilter; | ||
| using DigitalLearningSolutions.Web.Services; | ||
| using DigitalLearningSolutions.Web.ViewModels.TrackingSystem.Delegates.DeactivateDelegate; | ||
| using Microsoft.AspNetCore.Authorization; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Microsoft.FeatureManagement.Mvc; | ||
|
|
||
|
|
||
| [FeatureGate(FeatureFlags.RefactoredTrackingSystem)] | ||
| [Authorize(Policy = CustomPolicies.UserCentreAdmin)] | ||
| [ServiceFilter(typeof(VerifyAdminUserCanAccessDelegateUser))] | ||
| [Route("TrackingSystem/Delegates/{delegateId:int}/Deactivate")] | ||
| [SetDlsSubApplication(nameof(DlsSubApplication.TrackingSystem))] | ||
| [SetSelectedTab(nameof(NavMenuTab.Delegates))] | ||
| public class DeactivateDelegateController : Controller | ||
| { | ||
| private readonly IUserService userService; | ||
| public DeactivateDelegateController( | ||
| IUserService userService | ||
| ) | ||
| { | ||
| this.userService = userService; | ||
| } | ||
| [HttpGet] | ||
| public IActionResult Index(int delegateId) | ||
| { | ||
| var checkDelegate = userService.CheckDelegateIsActive(delegateId); | ||
| if (checkDelegate != delegateId) | ||
| { | ||
| return RedirectToAction("StatusCode", "LearningSolutions", new { code = 410 }); | ||
| } | ||
| var centreId = User.GetCentreId(); | ||
| var delegateEntity = userService.GetDelegateById(delegateId)!; | ||
| var userEntity = userService.GetUserById(delegateEntity.DelegateAccount.UserId); | ||
| var adminAccount = userEntity!.GetCentreAccountSet(centreId)?.AdminAccount; | ||
| var roles = GetRoles(adminAccount, userEntity); | ||
| var model = new DeactivateDelegateAccountViewModel | ||
| { | ||
| DelegateId = delegateId, | ||
| Name = delegateEntity.UserAccount.FirstName + " " + delegateEntity.UserAccount.LastName, | ||
| Roles = roles, | ||
| Email = delegateEntity.UserAccount.PrimaryEmail, | ||
| UserId = delegateEntity.UserAccount.Id | ||
| }; | ||
| return View(model); | ||
| } | ||
|
|
||
| [HttpPost] | ||
| public IActionResult Index(DeactivateDelegateAccountViewModel deactivateDelegateAccountViewModel) | ||
| { | ||
| var centreId = User.GetCentreId(); | ||
| if (!ModelState.IsValid) | ||
| { | ||
| var delegateEntity = userService.GetDelegateById(deactivateDelegateAccountViewModel.DelegateId)!; | ||
| var userEntity = userService.GetUserById(delegateEntity.DelegateAccount.UserId); | ||
| var adminAccount = userEntity!.GetCentreAccountSet(centreId)?.AdminAccount; | ||
| var roles = GetRoles(adminAccount, userEntity); | ||
| deactivateDelegateAccountViewModel.Roles = roles; | ||
| return View(deactivateDelegateAccountViewModel); | ||
| } | ||
|
|
||
| if (deactivateDelegateAccountViewModel.Deactivate == true ) | ||
| { | ||
| userService.DeactivateDelegateUser(deactivateDelegateAccountViewModel.DelegateId); | ||
| return RedirectToAction("Index", "ViewDelegate", new { deactivateDelegateAccountViewModel.DelegateId }); | ||
| } | ||
| userService.DeactivateDelegateUser(deactivateDelegateAccountViewModel.DelegateId); | ||
| userService.DeactivateAdminAccount(deactivateDelegateAccountViewModel.UserId, centreId.Value); | ||
| return RedirectToAction("Index", "ViewDelegate", new { deactivateDelegateAccountViewModel.DelegateId }); | ||
|
|
||
| } | ||
| private List<string>? GetRoles(AdminAccount? adminAccount, UserEntity userEntity) | ||
| { | ||
| var roles = new List<string>(); | ||
| if (adminAccount != null) | ||
| { | ||
| var adminentity = new AdminEntity(adminAccount, userEntity.UserAccount, null); | ||
| CultureInfo currentCulture = System.Threading.Thread.CurrentThread.CurrentCulture; | ||
rshrirohit marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| roles = FilterableTagHelper.GetCurrentTagsForAdmin(adminentity).Where(s => s.Hidden == false) | ||
| .Select(d => d.DisplayText).ToList<string>(); | ||
| } | ||
| return roles; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...wModels/TrackingSystem/Delegates/DeactivateDelegate/DeactivateDelegateAccountViewModel.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| using FluentMigrator.Infrastructure; | ||
| using System.Collections.Generic; | ||
| using System.ComponentModel.DataAnnotations; | ||
|
|
||
| namespace DigitalLearningSolutions.Web.ViewModels.TrackingSystem.Delegates.DeactivateDelegate | ||
| { | ||
| public class DeactivateDelegateAccountViewModel | ||
| { | ||
| public int DelegateId { get; set; } | ||
| public int UserId { get; set; } | ||
| public string Name { get; set; } | ||
| public string Email { get; set; } | ||
| public List<string> Roles { get; set; } | ||
| [Required(ErrorMessage = "Please select an account you want to deactivate.")] | ||
| public bool? Deactivate { get; set; } | ||
| } | ||
| } |
84 changes: 84 additions & 0 deletions
84
DigitalLearningSolutions.Web/Views/TrackingSystem/Delegates/DeactivateDelegate/Index.cshtml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| @using DigitalLearningSolutions.Web.ViewModels.TrackingSystem.Delegates.DeactivateDelegate | ||
| @model DeactivateDelegateAccountViewModel | ||
|
|
||
|
|
||
| @{ | ||
| var errorHasOccurred = !ViewData.ModelState.IsValid; | ||
| ViewData["Title"] = errorHasOccurred ? "Error: Deactivate account" : "Deactivate account"; | ||
| } | ||
| <div class="nhsuk-grid-row"> | ||
| <div class="nhsuk-grid-column-full"> | ||
| @if (errorHasOccurred) | ||
| { | ||
| <vc:error-summary order-of-property-names="@(new []{ nameof(Model.Name) })" /> | ||
| } | ||
|
|
||
| <h2 class="nhsuk-heading-l word-break">Deactivate account - @Model.Name (@Model.Email)</h2> | ||
| <div class="nhsuk-grid-row"> | ||
| <div class="nhsuk-grid-column-full nhsuk-lede-text"> | ||
| @Model.Name has an active admin account at your centre with following admin roles: | ||
| </div> | ||
| </div> | ||
| <div class="nhsuk-grid-row"> | ||
| <div class="nhsuk-grid-column-full nhsuk-lede-text"> | ||
| <ul> | ||
| @foreach (var role in Model.Roles) | ||
| { | ||
| <li>@role</li> | ||
| } | ||
| </ul> | ||
| </div> | ||
| </div> | ||
|
|
||
| <form class="nhsuk-u-margin-bottom-3" method="post" novalidate asp-action="Index"> | ||
| <fieldset class="nhsuk-fieldset"> | ||
| <legend class="nhsuk-fieldset__legend nhsuk-fieldset__legend--l"> | ||
| <h2 class="nhsuk-fieldset__heading"> | ||
| Which accounts would you like deactivate? | ||
| </h2> | ||
| </legend> | ||
|
|
||
| <nhs-form-group nhs-validation-for="Deactivate"> | ||
| <div class="nhsuk-radios nhsuk-radios--inline"> | ||
| <div class="nhsuk-radios__item"> | ||
| <input class="nhsuk-radios__input" id="rb-accountonly" name="Deactivate" required="required" type="radio" value="true"> | ||
| <label class="nhsuk-label nhsuk-radios__label" for="rb-accountonly"> | ||
| Delegate account only | ||
| </label> | ||
| <div class="nhsuk-hint nhsuk-summary-list" id="cb-verify-item-hint"> | ||
| The user will still be able to login to your centre with the above admin roles | ||
| </div> | ||
| </div> | ||
| <div class="nhsuk-radios__item"> | ||
| <input class="nhsuk-radios__input" id="rb-accountandadmin" name="Deactivate" required="required" type="radio" value="false"> | ||
| <label class="nhsuk-label nhsuk-radios__label" for="rb-accountandadmin"> | ||
| Delegate account and Administrators accounts | ||
| </label> | ||
| <div class="nhsuk-hint nhsuk-summary-list" id="cb-verify-item-hint"> | ||
| The user will no longer be able to login to your centre | ||
| </div> | ||
| </div> | ||
| <span asp-validation-for="Deactivate" class="text-danger"></span> | ||
| </div> | ||
| </nhs-form-group> | ||
| </fieldset> | ||
| <button name="action" class="nhsuk-button delete-button view-delegate-button" value="save">Deactivate account</button> | ||
| <input type="hidden" asp-for="DelegateId" /> | ||
| <input type="hidden" asp-for="Name" /> | ||
| <input type="hidden" asp-for="Email" /> | ||
| <input type="hidden" asp-for="Roles" /> | ||
| <input type="hidden" asp-for="UserId" /> | ||
| </form> | ||
| <div class="nhsuk-back-link"> | ||
| <a class="nhsuk-back-link__link" | ||
| asp-controller="ViewDelegate" | ||
| asp-action="Index" | ||
| asp-route-delegateId="@Model.DelegateId"> | ||
| <svg class="nhsuk-icon nhsuk-icon__chevron-left" focusable="false" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true" focusable="false"> | ||
| <path d="M13.41 12l5.3-5.29a1 1 0 1 0-1.42-1.42L12 10.59l-5.29-5.3a1 1 0 0 0-1.42 1.42l5.3 5.29-5.3 5.29a1 1 0 0 0 0 1.42 1 1 0 0 0 1.42 0l5.29-5.3 5.29 5.3a1 1 0 0 0 1.42 0 1 1 0 0 0 0-1.42z"></path> | ||
| </svg> | ||
| Cancel | ||
| </a> | ||
| </div> | ||
| </div> | ||
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.