From 2d12725e28f14a2cc1e1f69df328a0ebeb6be4e7 Mon Sep 17 00:00:00 2001 From: Jon P Smith Date: Fri, 20 Aug 2021 17:27:26 +0100 Subject: [PATCH] Renamed SyncAuthUserChange + updated Example1 --- .../AdminCode/IAuthUsersAdminService.cs | 2 +- .../Services/AuthUsersAdminService.cs | 18 ++--- ...rChanges.cs => SyncAuthUserChangeTypes.cs} | 2 +- .../AdminCode/SyncAuthUserWithChange.cs | 20 +++--- .../Pages/AuthUsers/ListUsers.cshtml | 65 +++++++++++++++++++ .../Pages/AuthUsers/ListUsers.cshtml.cs | 30 +++++++++ .../Pages/AuthUsers/SyncUsers.cshtml | 50 ++++++++++++++ .../Pages/AuthUsers/SyncUsers.cshtml.cs | 33 ++++++++++ .../Pages/Shared/_Layout.cshtml | 11 +++- .../Pages/{ => UserInfo}/UserClaims.cshtml | 0 .../Pages/{ => UserInfo}/UserClaims.cshtml.cs | 3 +- .../Startup.cs | 4 +- .../Controllers/AuthUsersController.cs | 15 ++--- .../Controllers/LoggedInUserController.cs | 1 + .../Models/AuthIdAndChange.cs | 2 +- .../Views/AuthUsers/Create.cshtml | 2 +- .../Views/AuthUsers/Delete.cshtml | 2 +- .../Views/AuthUsers/Edit.cshtml | 2 +- .../Views/AuthUsers/Index.cshtml | 2 +- .../Views/AuthUsers/SyncUsers.cshtml | 6 +- .../Views/LoggedInUser/AuthUserInfo.cshtml | 2 +- .../CommonAdmin}/AuthUserDisplay.cs | 2 +- .../CommonAdmin/SetupManualUserChange.cs | 16 ++--- .../TestAuthUsersAdminService_UserSync.cs | 4 +- .../TestExample4AdminDisplayUpdate.cs | 6 +- 25 files changed, 242 insertions(+), 58 deletions(-) rename AuthPermissions/AdminCode/{SyncAuthUserChanges.cs => SyncAuthUserChangeTypes.cs} (96%) create mode 100644 Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/ListUsers.cshtml create mode 100644 Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/ListUsers.cshtml.cs create mode 100644 Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/SyncUsers.cshtml create mode 100644 Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/SyncUsers.cshtml.cs rename Example1.RazorPages.IndividualAccounts/Pages/{ => UserInfo}/UserClaims.cshtml (100%) rename Example1.RazorPages.IndividualAccounts/Pages/{ => UserInfo}/UserClaims.cshtml.cs (75%) rename {Example4.MvcWebApp.IndividualAccounts/Models => ExamplesCommonCode/CommonAdmin}/AuthUserDisplay.cs (97%) diff --git a/AuthPermissions/AdminCode/IAuthUsersAdminService.cs b/AuthPermissions/AdminCode/IAuthUsersAdminService.cs index 2eb22aa5..4732f61f 100644 --- a/AuthPermissions/AdminCode/IAuthUsersAdminService.cs +++ b/AuthPermissions/AdminCode/IAuthUsersAdminService.cs @@ -95,7 +95,7 @@ Task UpdateUserAsync(string userId, string email, /// /// This receives a list of and applies them to the AuthP database. - /// This uses the parameter to define what to change + /// This uses the parameter to define what to change /// /// /// Status diff --git a/AuthPermissions/AdminCode/Services/AuthUsersAdminService.cs b/AuthPermissions/AdminCode/Services/AuthUsersAdminService.cs index 5b567d8f..56e9eb92 100644 --- a/AuthPermissions/AdminCode/Services/AuthUsersAdminService.cs +++ b/AuthPermissions/AdminCode/Services/AuthUsersAdminService.cs @@ -304,7 +304,7 @@ public async Task> SyncAndShowChangesAsync() { //check if its a change or not var syncChange = new SyncAuthUserWithChange(authenticationUser, authUser); - if (syncChange.FoundChange == SyncAuthUserChanges.Update) + if (syncChange.FoundChangeType == SyncAuthUserChangeTypes.Update) //The two are different so add to the result result.Add(syncChange); //Removed the authUser as has been handled @@ -325,7 +325,7 @@ public async Task> SyncAndShowChangesAsync() /// /// This receives a list of and applies them to the AuthP database. - /// This uses the parameter to define what to change + /// This uses the parameter to define what to change /// /// /// Status @@ -335,19 +335,19 @@ public async Task ApplySyncChangesAsync(IEnumerable ApplySyncChangesAsync(IEnumerable().ToList() - .Select(x => $"{x} = {changesToApply.Count(y => y.FoundChange == x)}"); + var changeStrings = Enum.GetValues().ToList() + .Select(x => $"{x} = {changesToApply.Count(y => y.FoundChangeType == x)}"); status.Message = $"Sync successful: {(string.Join(", ", changeStrings))}"; return status; diff --git a/AuthPermissions/AdminCode/SyncAuthUserChanges.cs b/AuthPermissions/AdminCode/SyncAuthUserChangeTypes.cs similarity index 96% rename from AuthPermissions/AdminCode/SyncAuthUserChanges.cs rename to AuthPermissions/AdminCode/SyncAuthUserChangeTypes.cs index ad6269ba..d3deb3e2 100644 --- a/AuthPermissions/AdminCode/SyncAuthUserChanges.cs +++ b/AuthPermissions/AdminCode/SyncAuthUserChangeTypes.cs @@ -7,7 +7,7 @@ namespace AuthPermissions.AdminCode /// The type of changes between the authentication provider's user and the AuthPermission's AuthUser /// Also used to confirm that the change should be made /// - public enum SyncAuthUserChanges + public enum SyncAuthUserChangeTypes { /// /// Ignore this change - can be set by the user diff --git a/AuthPermissions/AdminCode/SyncAuthUserWithChange.cs b/AuthPermissions/AdminCode/SyncAuthUserWithChange.cs index 4cf604db..61782d0e 100644 --- a/AuthPermissions/AdminCode/SyncAuthUserWithChange.cs +++ b/AuthPermissions/AdminCode/SyncAuthUserWithChange.cs @@ -58,10 +58,10 @@ internal SyncAuthUserWithChange(SyncAuthenticationUser authenticationUser, AuthU //Now work out what the change is if (Email == OldEmail && UserName == OldUserName) - FoundChange = SyncAuthUserChanges.NoChange; + FoundChangeType = SyncAuthUserChangeTypes.NoChange; else if (authenticationUser == null) { - FoundChange = SyncAuthUserChanges.Delete; + FoundChangeType = SyncAuthUserChangeTypes.Delete; //Need to set the Email and UserName so that can show the AuthP user's values Email = authUser.Email; UserName = authUser.UserName; @@ -70,9 +70,9 @@ internal SyncAuthUserWithChange(SyncAuthenticationUser authenticationUser, AuthU OldUserName = null; } else if (authUser == null) - FoundChange = SyncAuthUserChanges.Create; + FoundChangeType = SyncAuthUserChangeTypes.Create; else - FoundChange = SyncAuthUserChanges.Update; + FoundChangeType = SyncAuthUserChangeTypes.Update; } @@ -80,7 +80,7 @@ internal SyncAuthUserWithChange(SyncAuthenticationUser authenticationUser, AuthU /// /// This is set to the difference between authentication provider's user and the AuthPermission's AuthUser /// - public SyncAuthUserChanges FoundChange { get; set; } + public SyncAuthUserChangeTypes FoundChangeType { get; set; } /// /// The userId of the user (NOTE: this is not shown) @@ -125,15 +125,15 @@ internal SyncAuthUserWithChange(SyncAuthenticationUser authenticationUser, AuthU /// public override string ToString() { - switch (FoundChange) + switch (FoundChangeType) { - case SyncAuthUserChanges.NoChange: + case SyncAuthUserChangeTypes.NoChange: throw new AuthPermissionsException("Shouldn't have this in the list"); - case SyncAuthUserChanges.Create: + case SyncAuthUserChangeTypes.Create: return $"CREATE: Email = {Email}, UserName = {UserName}"; - case SyncAuthUserChanges.Update: + case SyncAuthUserChangeTypes.Update: return $"UPDATE: Email {(EmailChanged ? "CHANGED" : "same")}, UserName {(UserNameChanged ? "CHANGED" : "same")}"; - case SyncAuthUserChanges.Delete: + case SyncAuthUserChangeTypes.Delete: return $"DELETE: Email = {Email}, UserName = {UserName}"; default: throw new ArgumentOutOfRangeException(); diff --git a/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/ListUsers.cshtml b/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/ListUsers.cshtml new file mode 100644 index 00000000..c92157a5 --- /dev/null +++ b/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/ListUsers.cshtml @@ -0,0 +1,65 @@ +@page +@model ListUsersModel + +

Auth users

+ +@if (!string.IsNullOrEmpty(Model.Message)) +{ +

@Model.Message

+} + +Sync with authentication provider's users +

+ + + + + + + + + + + + @foreach (var item in @Model.AuthUserList) + { + + + + + + + } + +
+ UserName + + Email + + AuthRoles + + Edit | Delete +
+ @Html.DisplayFor(modelItem => item.UserName) + + @Html.DisplayFor(modelItem => item.Email) + + @string.Join(", ", item.RoleNames) + + Edit + | + Delete +
+ + + +@section Scripts{ + + + +} + diff --git a/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/ListUsers.cshtml.cs b/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/ListUsers.cshtml.cs new file mode 100644 index 00000000..9cf0c6c4 --- /dev/null +++ b/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/ListUsers.cshtml.cs @@ -0,0 +1,30 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using AuthPermissions.AdminCode; +using ExamplesCommonCode.CommonAdmin; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; + +namespace Example1.RazorPages.IndividualAccounts.Pages.AuthUsers +{ + public class ListUsersModel : PageModel + { + private readonly IAuthUsersAdminService _authUsersAdmin; + + public ListUsersModel(IAuthUsersAdminService authUsersAdmin) + { + _authUsersAdmin = authUsersAdmin; + } + + public List AuthUserList { get; private set; } + public string Message { get; set; } + + public async Task OnGet(string message) + { + Message = message; + var userQuery = _authUsersAdmin.QueryAuthUsers(); + AuthUserList = await AuthUserDisplay.SelectQuery(userQuery.OrderBy(x => x.Email)).ToListAsync(); + } + } +} diff --git a/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/SyncUsers.cshtml b/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/SyncUsers.cshtml new file mode 100644 index 00000000..fadfe81b --- /dev/null +++ b/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/SyncUsers.cshtml @@ -0,0 +1,50 @@ +@page +@using global::AuthPermissions.AdminCode +@model Example1.RazorPages.IndividualAccounts.Pages.AuthUsers.SyncUsersModel + +@if (!@Model.Data.Any()) +{ +

There are no changes to apply to the AuthUsers

+ return; +} + +

Changes needed based on authentication provider's users

+
+ + + + + + + + + + + @for (int i = 0; i < Model.Data.Count; i++) + { + + + + + + + + } + + +
Change typeEmailUserNameRoles Count
+ @Model.Data[i].FoundChangeType + @Html.Hidden($"Data[{i}].{nameof(SyncAuthUserWithChange.UserId)}", Model.Data[i].UserId) + @Html.Hidden($"Data[{i}].{nameof(SyncAuthUserWithChange.FoundChangeType)}", Model.Data[i].FoundChangeType) + + @Model.Data[i].Email + @Html.Hidden($"Data[{i}].{nameof(SyncAuthUserWithChange.Email)}", Model.Data[i].Email) + + @Model.Data[i].UserName + @Html.Hidden($"Data[{i}].{nameof(SyncAuthUserWithChange.UserName)}", Model.Data[i].UserName) + @Model.Data[i].NumRoles
+ + + +
+ diff --git a/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/SyncUsers.cshtml.cs b/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/SyncUsers.cshtml.cs new file mode 100644 index 00000000..2b65ac38 --- /dev/null +++ b/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/SyncUsers.cshtml.cs @@ -0,0 +1,33 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using AuthPermissions.AdminCode; +using AuthPermissions.CommonCode; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace Example1.RazorPages.IndividualAccounts.Pages.AuthUsers +{ + public class SyncUsersModel : PageModel + { + private readonly IAuthUsersAdminService _authUsersAdmin; + + public SyncUsersModel(IAuthUsersAdminService authUsersAdmin) + { + _authUsersAdmin = authUsersAdmin; + } + + [BindProperty] + public List Data { get; set; } + + public async Task OnGet() + { + Data = await _authUsersAdmin.SyncAndShowChangesAsync(); + } + + public async Task OnPost() + { + var status = await _authUsersAdmin.ApplySyncChangesAsync(Data); + return RedirectToPage("ListUsers", new { message = status.Message }); + } + } +} diff --git a/Example1.RazorPages.IndividualAccounts/Pages/Shared/_Layout.cshtml b/Example1.RazorPages.IndividualAccounts/Pages/Shared/_Layout.cshtml index ef1f4c7c..8059e570 100644 --- a/Example1.RazorPages.IndividualAccounts/Pages/Shared/_Layout.cshtml +++ b/Example1.RazorPages.IndividualAccounts/Pages/Shared/_Layout.cshtml @@ -21,8 +21,15 @@ - diff --git a/Example1.RazorPages.IndividualAccounts/Pages/UserClaims.cshtml b/Example1.RazorPages.IndividualAccounts/Pages/UserInfo/UserClaims.cshtml similarity index 100% rename from Example1.RazorPages.IndividualAccounts/Pages/UserClaims.cshtml rename to Example1.RazorPages.IndividualAccounts/Pages/UserInfo/UserClaims.cshtml diff --git a/Example1.RazorPages.IndividualAccounts/Pages/UserClaims.cshtml.cs b/Example1.RazorPages.IndividualAccounts/Pages/UserInfo/UserClaims.cshtml.cs similarity index 75% rename from Example1.RazorPages.IndividualAccounts/Pages/UserClaims.cshtml.cs rename to Example1.RazorPages.IndividualAccounts/Pages/UserInfo/UserClaims.cshtml.cs index bbb3a2f4..bd4a6a85 100644 --- a/Example1.RazorPages.IndividualAccounts/Pages/UserClaims.cshtml.cs +++ b/Example1.RazorPages.IndividualAccounts/Pages/UserInfo/UserClaims.cshtml.cs @@ -1,8 +1,7 @@ using System.Security.Claims; -using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -namespace Example1.RazorPages.IndividualAccounts.Pages +namespace Example1.RazorPages.IndividualAccounts.Pages.UserInfo { public class UserClaimsModel : PageModel { diff --git a/Example1.RazorPages.IndividualAccounts/Startup.cs b/Example1.RazorPages.IndividualAccounts/Startup.cs index 25e1cf74..7eaf47a6 100644 --- a/Example1.RazorPages.IndividualAccounts/Startup.cs +++ b/Example1.RazorPages.IndividualAccounts/Startup.cs @@ -44,12 +44,14 @@ public void ConfigureServices(IServiceCollection services) //These are methods from the ExamplesCommonCode set up some demo users in the individual accounts database //NOTE: they are run in the order that they are registered services.AddHostedService>(); //and create db on startup - services.AddHostedService(); //reads a comma delimited list of emails from appsettings.json + //reads a comma delimited list of emails from appsettings.json and creates users in the Individual Account + services.AddHostedService(); services.RegisterAuthPermissions() .UsingInMemoryDatabase() .AddRolesPermissionsIfEmpty(AppAuthSetupData.ListOfRolesWithPermissions) .AddAuthUsersIfEmpty(AppAuthSetupData.UsersRolesDefinition) + .RegisterAuthenticationProviderReader() .RegisterFindUserInfoService() .AddSuperUserToIndividualAccounts() .SetupAspNetCoreAndDatabase(); diff --git a/Example4.MvcWebApp.IndividualAccounts/Controllers/AuthUsersController.cs b/Example4.MvcWebApp.IndividualAccounts/Controllers/AuthUsersController.cs index 8660dfc6..b52fb8f9 100644 --- a/Example4.MvcWebApp.IndividualAccounts/Controllers/AuthUsersController.cs +++ b/Example4.MvcWebApp.IndividualAccounts/Controllers/AuthUsersController.cs @@ -61,21 +61,21 @@ public async Task Create(string userId) /// public async Task EditFromSync(SetupManualUserChange input) { - switch (input.FoundChange) + switch (input.FoundChangeType) { - case SyncAuthUserChanges.NoChange: + case SyncAuthUserChangeTypes.NoChange: return RedirectToAction(nameof(Index), new { message = "The entry was marked as 'No Change' so it was ignored." }); - case SyncAuthUserChanges.Create: + case SyncAuthUserChangeTypes.Create: var createData = await SetupManualUserChange.PrepareForCreateAsync(input.UserId, _context); return View(nameof(Create), createData); - case SyncAuthUserChanges.Update: + case SyncAuthUserChangeTypes.Update: var status = await SetupManualUserChange.PrepareForUpdateAsync(input.UserId, _authUsersAdmin, _context); if (status.HasErrors) return RedirectToAction(nameof(ErrorDisplay), new { errorMessage = status.GetAllErrors() }); return View(nameof(Edit), status.Result); - case SyncAuthUserChanges.Delete: + case SyncAuthUserChangeTypes.Delete: return View(nameof(Delete), new { userId = input.UserId }); } @@ -90,7 +90,7 @@ public async Task CreateUpdate(SetupManualUserChange input) if (!ModelState.IsValid) { await input.SetupDropDownListsAsync(_context);//refresh dropdown - return View(input.FoundChange); + return View(input.FoundChangeType); } var status = await input.ChangeAuthUserFromDataAsync(_authUsersAdmin, _context); @@ -113,9 +113,6 @@ public async Task SyncUsers() //NOTE: the input be called "data" because we are using JavaScript to send that info back public async Task SyncUsers(IEnumerable data) { - return RedirectToAction("Index"); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - - var status = await _authUsersAdmin.ApplySyncChangesAsync(data); if (status.HasErrors) return RedirectToAction(nameof(ErrorDisplay), diff --git a/Example4.MvcWebApp.IndividualAccounts/Controllers/LoggedInUserController.cs b/Example4.MvcWebApp.IndividualAccounts/Controllers/LoggedInUserController.cs index 2b032bea..e059f8db 100644 --- a/Example4.MvcWebApp.IndividualAccounts/Controllers/LoggedInUserController.cs +++ b/Example4.MvcWebApp.IndividualAccounts/Controllers/LoggedInUserController.cs @@ -8,6 +8,7 @@ using AuthPermissions.CommonCode; using AuthPermissions.PermissionsCode; using Example4.MvcWebApp.IndividualAccounts.Models; +using ExamplesCommonCode.CommonAdmin; namespace Example4.MvcWebApp.IndividualAccounts.Controllers { diff --git a/Example4.MvcWebApp.IndividualAccounts/Models/AuthIdAndChange.cs b/Example4.MvcWebApp.IndividualAccounts/Models/AuthIdAndChange.cs index 9366cf37..e0e48a7c 100644 --- a/Example4.MvcWebApp.IndividualAccounts/Models/AuthIdAndChange.cs +++ b/Example4.MvcWebApp.IndividualAccounts/Models/AuthIdAndChange.cs @@ -7,7 +7,7 @@ namespace Example4.MvcWebApp.IndividualAccounts.Models { public class AuthIdAndChange { - public SyncAuthUserChanges FoundChange { get; set; } + public SyncAuthUserChangeTypes FoundChangeType { get; set; } public string UserId { get; set; } } } \ No newline at end of file diff --git a/Example4.MvcWebApp.IndividualAccounts/Views/AuthUsers/Create.cshtml b/Example4.MvcWebApp.IndividualAccounts/Views/AuthUsers/Create.cshtml index b7f31b14..46614eb8 100644 --- a/Example4.MvcWebApp.IndividualAccounts/Views/AuthUsers/Create.cshtml +++ b/Example4.MvcWebApp.IndividualAccounts/Views/AuthUsers/Create.cshtml @@ -14,7 +14,7 @@
@Html.HiddenFor(x => x.UserId) - @Html.HiddenFor(x => x.FoundChange) + @Html.HiddenFor(x => x.FoundChangeType)
diff --git a/Example4.MvcWebApp.IndividualAccounts/Views/AuthUsers/Delete.cshtml b/Example4.MvcWebApp.IndividualAccounts/Views/AuthUsers/Delete.cshtml index 71e5b306..0ca2dcc3 100644 --- a/Example4.MvcWebApp.IndividualAccounts/Views/AuthUsers/Delete.cshtml +++ b/Example4.MvcWebApp.IndividualAccounts/Views/AuthUsers/Delete.cshtml @@ -1,4 +1,4 @@ -@model AuthUserDisplay +@model ExamplesCommonCode.CommonAdmin.AuthUserDisplay @{ ViewData["Title"] = "Delete"; diff --git a/Example4.MvcWebApp.IndividualAccounts/Views/AuthUsers/Edit.cshtml b/Example4.MvcWebApp.IndividualAccounts/Views/AuthUsers/Edit.cshtml index a11e49df..9965b384 100644 --- a/Example4.MvcWebApp.IndividualAccounts/Views/AuthUsers/Edit.cshtml +++ b/Example4.MvcWebApp.IndividualAccounts/Views/AuthUsers/Edit.cshtml @@ -14,7 +14,7 @@
@Html.HiddenFor(x => x.UserId) - @Html.HiddenFor(x => x.FoundChange) + @Html.HiddenFor(x => x.FoundChangeType)
diff --git a/Example4.MvcWebApp.IndividualAccounts/Views/AuthUsers/Index.cshtml b/Example4.MvcWebApp.IndividualAccounts/Views/AuthUsers/Index.cshtml index 868c37a4..06553e3f 100644 --- a/Example4.MvcWebApp.IndividualAccounts/Views/AuthUsers/Index.cshtml +++ b/Example4.MvcWebApp.IndividualAccounts/Views/AuthUsers/Index.cshtml @@ -1,7 +1,7 @@ @using AuthPermissions.PermissionsCode @using Example4.MvcWebApp.IndividualAccounts.PermissionsCode @using Microsoft.AspNetCore.Routing.Template -@model IEnumerable +@model IEnumerable @{ ViewData["Title"] = "Auth Users"; diff --git a/Example4.MvcWebApp.IndividualAccounts/Views/AuthUsers/SyncUsers.cshtml b/Example4.MvcWebApp.IndividualAccounts/Views/AuthUsers/SyncUsers.cshtml index 1be41c7c..766d1d3d 100644 --- a/Example4.MvcWebApp.IndividualAccounts/Views/AuthUsers/SyncUsers.cshtml +++ b/Example4.MvcWebApp.IndividualAccounts/Views/AuthUsers/SyncUsers.cshtml @@ -28,7 +28,7 @@ @foreach (var item in Model) { - @item.FoundChange + @item.FoundChangeType @item.Email @item.UserName @@ -39,9 +39,9 @@ @Html.Hidden(nameof(SyncAuthUserWithChange.UserId), item.UserId) @Html.Hidden(nameof(SyncAuthUserWithChange.Email), item.Email) @Html.Hidden(nameof(SyncAuthUserWithChange.UserName), item.UserName) - @Html.Hidden(nameof(SyncAuthUserWithChange.FoundChange), item.FoundChange) + @Html.Hidden(nameof(SyncAuthUserWithChange.FoundChangeType), item.FoundChangeType) - + diff --git a/Example4.MvcWebApp.IndividualAccounts/Views/LoggedInUser/AuthUserInfo.cshtml b/Example4.MvcWebApp.IndividualAccounts/Views/LoggedInUser/AuthUserInfo.cshtml index 5f1bf58e..b60befe0 100644 --- a/Example4.MvcWebApp.IndividualAccounts/Views/LoggedInUser/AuthUserInfo.cshtml +++ b/Example4.MvcWebApp.IndividualAccounts/Views/LoggedInUser/AuthUserInfo.cshtml @@ -1,5 +1,5 @@ @using Microsoft.AspNetCore.Mvc.Filters -@model Example4.MvcWebApp.IndividualAccounts.Models.AuthUserDisplay +@model ExamplesCommonCode.CommonAdmin.AuthUserDisplay @{ ViewData["Title"] = "AuthUserInfo"; diff --git a/Example4.MvcWebApp.IndividualAccounts/Models/AuthUserDisplay.cs b/ExamplesCommonCode/CommonAdmin/AuthUserDisplay.cs similarity index 97% rename from Example4.MvcWebApp.IndividualAccounts/Models/AuthUserDisplay.cs rename to ExamplesCommonCode/CommonAdmin/AuthUserDisplay.cs index 6961e1cc..5492fc0b 100644 --- a/Example4.MvcWebApp.IndividualAccounts/Models/AuthUserDisplay.cs +++ b/ExamplesCommonCode/CommonAdmin/AuthUserDisplay.cs @@ -6,7 +6,7 @@ using AuthPermissions.DataLayer.Classes; using AuthPermissions.DataLayer.Classes.SupportTypes; -namespace Example4.MvcWebApp.IndividualAccounts.Models +namespace ExamplesCommonCode.CommonAdmin { public class AuthUserDisplay { diff --git a/ExamplesCommonCode/CommonAdmin/SetupManualUserChange.cs b/ExamplesCommonCode/CommonAdmin/SetupManualUserChange.cs index 6a19398a..64032803 100644 --- a/ExamplesCommonCode/CommonAdmin/SetupManualUserChange.cs +++ b/ExamplesCommonCode/CommonAdmin/SetupManualUserChange.cs @@ -21,7 +21,7 @@ public class SetupManualUserChange /// /// This is used by SyncUsers to define what to do /// - public SyncAuthUserChanges FoundChange { get; set; } + public SyncAuthUserChangeTypes FoundChangeType { get; set; } /// /// The userId of the user (NOTE: this is not show) @@ -66,7 +66,7 @@ public static async Task> PrepareForUpdate var result = new SetupManualUserChange { - FoundChange = SyncAuthUserChanges.Update, + FoundChangeType = SyncAuthUserChangeTypes.Update, UserId = authUser.UserId, UserName = authUser.UserName, Email = authUser.Email, @@ -84,7 +84,7 @@ public static async Task PrepareForCreateAsync(string use { var result = new SetupManualUserChange { - FoundChange = SyncAuthUserChanges.Create, + FoundChangeType = SyncAuthUserChangeTypes.Create, UserId = userId, }; await result.SetupDropDownListsAsync(context); @@ -102,20 +102,20 @@ public async Task ChangeAuthUserFromDataAsync(IAuthUsersAdminSer { var status = new StatusGenericHandler(); - switch (FoundChange) + switch (FoundChangeType) { - case SyncAuthUserChanges.NoChange: + case SyncAuthUserChangeTypes.NoChange: status.Message = $"The user {UserName ?? Email} was marked as NoChange, so no change was applied"; break; - case SyncAuthUserChanges.Create: + case SyncAuthUserChangeTypes.Create: status.CombineStatuses( await authUsersAdmin.AddNewUserAsync(UserId, Email, UserName, RoleNames, TenantName)); break; - case SyncAuthUserChanges.Update: + case SyncAuthUserChangeTypes.Update: status.CombineStatuses( await authUsersAdmin.UpdateUserAsync(UserId, Email, UserName, RoleNames, TenantName)); break; - case SyncAuthUserChanges.Delete: + case SyncAuthUserChangeTypes.Delete: throw new AuthPermissionsException("You should direct a Delete change to a Delete confirm page."); default: throw new ArgumentOutOfRangeException(); diff --git a/Test/UnitTests/TestAuthPermissionsAdmin/TestAuthUsersAdminService_UserSync.cs b/Test/UnitTests/TestAuthPermissionsAdmin/TestAuthUsersAdminService_UserSync.cs index 7dd3cbe0..b3d07ef3 100644 --- a/Test/UnitTests/TestAuthPermissionsAdmin/TestAuthUsersAdminService_UserSync.cs +++ b/Test/UnitTests/TestAuthPermissionsAdmin/TestAuthUsersAdminService_UserSync.cs @@ -47,7 +47,7 @@ public async Task TestSyncAndShowChangesAsyncOk() { _output.WriteLine(synChange.ToString()); } - changes.Select(x => x.FoundChange.ToString()).ShouldEqual(new []{ "Update", "Create", "Delete" }); + changes.Select(x => x.FoundChangeType.ToString()).ShouldEqual(new []{ "Update", "Create", "Delete" }); changes.Select(x => x.ToString()).ShouldEqual(new[] { "UPDATE: Email CHANGED, UserName CHANGED", @@ -79,7 +79,7 @@ public async Task TestSyncAndShowChangesAsyncCheckEmailAndUserName() { _output.WriteLine(synChange.ToString()); } - changes.Select(x => x.FoundChange.ToString()).ShouldEqual(new[] { "Update", "Create", "Delete" }); + changes.Select(x => x.FoundChangeType.ToString()).ShouldEqual(new[] { "Update", "Create", "Delete" }); changes.Select(x => x.Email).ShouldEqual(new[] { "User2@NewGmail.com", "User99@gmail.com", "User3@gmail.com" }); changes.Select(x => x.UserName).ShouldEqual(new[] { "new name", "user 99", "first last 2" }); changes.Select(x => x.ToString()).ShouldEqual(new[] diff --git a/Test/UnitTests/TestExamples/TestExample4AdminDisplayUpdate.cs b/Test/UnitTests/TestExamples/TestExample4AdminDisplayUpdate.cs index 11e4c567..12c04d56 100644 --- a/Test/UnitTests/TestExamples/TestExample4AdminDisplayUpdate.cs +++ b/Test/UnitTests/TestExamples/TestExample4AdminDisplayUpdate.cs @@ -159,7 +159,7 @@ public async Task TestExample4AuthUserUpdateChangeAuthUserFromDataAsyncChangeRol var authUserUpdate = (await SetupManualUserChange.PrepareForUpdateAsync(userId, adminUserService, cAnds.context)).Result; //ATTEMPT - authUserUpdate.FoundChange = SyncAuthUserChanges.Update; + authUserUpdate.FoundChangeType = SyncAuthUserChangeTypes.Update; authUserUpdate.RoleNames = new List {"Area Manager", "App Admin"}; var status = await authUserUpdate.ChangeAuthUserFromDataAsync(adminUserService, cAnds.context); @@ -183,7 +183,7 @@ public async Task TestExample4AuthUserUpdateChangeAuthUserFromDataAsyncAddNewUse var authUserUpdate = (await SetupManualUserChange.PrepareForUpdateAsync("admin@4uInc.com", adminUserService, cAnds.context)).Result; //ATTEMPT - authUserUpdate.FoundChange = SyncAuthUserChanges.Create; + authUserUpdate.FoundChangeType = SyncAuthUserChangeTypes.Create; authUserUpdate.UserId = "newuser@gmail.com"; authUserUpdate.Email = "newuser@gmail.com"; authUserUpdate.UserName = "newuser@gmail.com"; @@ -210,7 +210,7 @@ public async Task TestExample4AuthUserUpdateChangeAuthUserFromDataAsyncBadTenant var authUserUpdate = (await SetupManualUserChange.PrepareForUpdateAsync(userId, adminUserService, cAnds.context)).Result; //ATTEMPT - authUserUpdate.FoundChange = SyncAuthUserChanges.Update; + authUserUpdate.FoundChangeType = SyncAuthUserChangeTypes.Update; authUserUpdate.TenantName = "Bad tenant name"; var status = await authUserUpdate.ChangeAuthUserFromDataAsync(adminUserService, cAnds.context);