From 99f764f1a1071a83059c887089be111d3dcb98f9 Mon Sep 17 00:00:00 2001 From: Chris Jacobsen Date: Mon, 1 Apr 2024 14:45:37 -0400 Subject: [PATCH 1/2] minor fixes --- BLAZAM/BLAZAM.csproj | 2 +- BLAZAM/Pages/API/Token.cshtml.cs | 2 +- BLAZAM/Pages/Benchmark.razor | 4 +-- BLAZAM/Pages/Configure/Fields.razor | 2 +- BLAZAM/Pages/Configure/Templates.razor | 13 +++++---- .../Pages/Error/UnhandledExceptionPage.razor | 2 +- BLAZAM/Pages/Groups/CreateGroup.razor | 2 +- BLAZAM/Pages/Home.razor | 6 ++-- BLAZAM/Pages/Login.razor | 28 ++++++++----------- BLAZAM/Pages/OU/CreateOU.razor | 2 +- BLAZAM/Pages/OU/ViewOU.razor | 2 +- BLAZAM/Pages/Printers/ViewPrinter.razor | 6 ++-- BLAZAM/Pages/Users/CreateUser.razor | 2 +- BLAZAM/Pages/Users/ViewUser.razor | 2 +- BLAZAM/Program.cs | 2 +- BLAZAMGui/UI/AppModal.razor | 5 +++- 16 files changed, 42 insertions(+), 40 deletions(-) diff --git a/BLAZAM/BLAZAM.csproj b/BLAZAM/BLAZAM.csproj index de94ab50..8eacd36f 100644 --- a/BLAZAM/BLAZAM.csproj +++ b/BLAZAM/BLAZAM.csproj @@ -6,7 +6,7 @@ enable false 0.9.0 - 2024.04.01.1814 + 2024.04.01.1841 false BLAZAM False diff --git a/BLAZAM/Pages/API/Token.cshtml.cs b/BLAZAM/Pages/API/Token.cshtml.cs index 0ccc7a38..222acdff 100644 --- a/BLAZAM/Pages/API/Token.cshtml.cs +++ b/BLAZAM/Pages/API/Token.cshtml.cs @@ -27,7 +27,7 @@ public TokenModel(IDatabaseContext context) public JsonResult OnGet() { JwtTokenHandler = new JwtSecurityTokenHandler(); - var user = this.User.Identity.Name; + var user = this.User.Identity?.Name; if (string.IsNullOrEmpty(user)) { throw new InvalidOperationException("Name is not specified."); diff --git a/BLAZAM/Pages/Benchmark.razor b/BLAZAM/Pages/Benchmark.razor index 5b9c7a25..8a46cd81 100644 --- a/BLAZAM/Pages/Benchmark.razor +++ b/BLAZAM/Pages/Benchmark.razor @@ -40,9 +40,9 @@ else } *@ @code { #nullable disable warnings - ActiveDirectoryContext ad; + //ActiveDirectoryContext ad; bool Running = false; - bool adTree; + //bool adTree; int runCount = 1; int cycle; double elapsed; diff --git a/BLAZAM/Pages/Configure/Fields.razor b/BLAZAM/Pages/Configure/Fields.razor index 6b83d36e..dd3120e1 100644 --- a/BLAZAM/Pages/Configure/Fields.razor +++ b/BLAZAM/Pages/Configure/Fields.razor @@ -121,7 +121,7 @@ } async Task SaveChanges() { - if (await Context.SaveChangesAsync() > 0) + if (Context != null && await Context.SaveChangesAsync() > 0) { SnackBarService.Success("Field Updated"); } diff --git a/BLAZAM/Pages/Configure/Templates.razor b/BLAZAM/Pages/Configure/Templates.razor index c17f6fcc..e30c1ab4 100644 --- a/BLAZAM/Pages/Configure/Templates.razor +++ b/BLAZAM/Pages/Configure/Templates.razor @@ -82,7 +82,7 @@ } - @if (Templates.Any(t => t.DeletedAt != null)) + @if (Templates?.Any(t => t.DeletedAt != null)==true) { @@ -227,10 +227,13 @@ } private async Task DeleteTemplate() { - SelectedTemplate.DeletedAt = DateTime.Now; - await Context.SaveChangesAsync(); - SelectedTemplate = null; - await InvokeAsync(StateHasChanged); + if (SelectedTemplate != null) + { + SelectedTemplate.DeletedAt = DateTime.Now; + await Context.SaveChangesAsync(); + SelectedTemplate = null; + await InvokeAsync(StateHasChanged); + } } private async void RestoreSelectedTemplates() { diff --git a/BLAZAM/Pages/Error/UnhandledExceptionPage.razor b/BLAZAM/Pages/Error/UnhandledExceptionPage.razor index 48646424..c4fb7dc9 100644 --- a/BLAZAM/Pages/Error/UnhandledExceptionPage.razor +++ b/BLAZAM/Pages/Error/UnhandledExceptionPage.razor @@ -40,7 +40,7 @@ Stack Trace:
@( - (MarkupString)_error.StackTrace.Replace("\n", "

") + (MarkupString)_error.StackTrace?.Replace("\n", "

") )
diff --git a/BLAZAM/Pages/Groups/CreateGroup.razor b/BLAZAM/Pages/Groups/CreateGroup.razor index 461a7b1b..8c02e303 100644 --- a/BLAZAM/Pages/Groups/CreateGroup.razor +++ b/BLAZAM/Pages/Groups/CreateGroup.razor @@ -106,7 +106,7 @@ { LoadingData = true; await InvokeAsync(StateHasChanged); - newGroup = parentOU.CreateGroup(newGroupName); + newGroup = parentOU?.CreateGroup(newGroupName); diff --git a/BLAZAM/Pages/Home.razor b/BLAZAM/Pages/Home.razor index 2609a8dd..4fe2f0cb 100644 --- a/BLAZAM/Pages/Home.razor +++ b/BLAZAM/Pages/Home.razor @@ -44,7 +44,7 @@ { try { - MOTD = (MarkupString)Context?.AppSettings.FirstOrDefault().MOTD; + MOTD = (MarkupString)Context?.AppSettings.FirstOrDefault()?.MOTD; } catch { @@ -68,10 +68,10 @@ return true; }); IJobStep step2 = new JobStep("Regular Step Fails", (step) => { Task.Delay(2000).Wait(); return false; }); - IJobStep step3 = new JobStep("Regular Step Throws", (step) => { Task.Delay(2000).Wait(); throw new ApplicationException("Test exception"); return false; }); + IJobStep step3 = new JobStep("Regular Step Throws", bool(step) => { Task.Delay(2000).Wait(); throw new ApplicationException("Test exception"); }); IJobStep step4 = new JobStep("Nested Step Passes", (step) => { Task.Delay(2000).Wait(); return true; }); IJobStep step5 = new JobStep("Nested Step Fails", (step) => { Task.Delay(2000).Wait(); return false; }); - IJobStep step6 = new JobStep("Nested Step Throws", (step) => { Task.Delay(2000).Wait(); throw new ApplicationException("Test exception"); return false; }); + IJobStep step6 = new JobStep("Nested Step Throws", bool(step) => { Task.Delay(2000).Wait(); throw new ApplicationException("Test exception"); }); job.Steps.Add(step1); job.Steps.Add(step2); diff --git a/BLAZAM/Pages/Login.razor b/BLAZAM/Pages/Login.razor index 64a57a22..2fe12f94 100644 --- a/BLAZAM/Pages/Login.razor +++ b/BLAZAM/Pages/Login.razor @@ -100,11 +100,6 @@ - - - - - @code { - MudTextField? _usernameTextField; - MudTextField? _passwordTextField; - string? _modalUri; + MudTextField _usernameTextField; + MudTextField _passwordTextField; bool attemptingSignIn = false; string redirectUrl; AppModal? _mfaModal; @@ -154,8 +148,8 @@ { attemptingSignIn = true; await InvokeAsync(StateHasChanged); - LoginRequest? authenticationResult; - if (ValidateInput(out authenticationResult)) + LoginRequest? authenticationResult=null; + if (ValidateInput(LoginRequest)) try { var response = await JSRuntime.InvokeAsync("attemptSignIn", LoginRequest); @@ -206,10 +200,9 @@ break; case LoginResultStatus.OK: attemptingSignIn = true; - if (!_mfaModal.IsShown) - { - Nav.NavigateTo(redirectUrl, true); - } + + Nav.NavigateTo(redirectUrl, true); + break; } @@ -217,9 +210,12 @@ await InvokeAsync(StateHasChanged); } - bool ValidateInput(out LoginRequest? validationResult) + bool ValidateInput(LoginRequest? validationResult) { - validationResult = null; + if(validationResult == null) + { + validationResult = new(); + } if (LoginRequest.Valid || (ApplicationInfo.InDemoMode && !DemoCustomLogin)) return true; diff --git a/BLAZAM/Pages/OU/CreateOU.razor b/BLAZAM/Pages/OU/CreateOU.razor index b9435261..8dc500cc 100644 --- a/BLAZAM/Pages/OU/CreateOU.razor +++ b/BLAZAM/Pages/OU/CreateOU.razor @@ -101,7 +101,7 @@ { LoadingData = true; await InvokeAsync(StateHasChanged); - newOU = parentOU.CreateOU(newOUName); + newOU = parentOU?.CreateOU(newOUName); diff --git a/BLAZAM/Pages/OU/ViewOU.razor b/BLAZAM/Pages/OU/ViewOU.razor index e55581f6..7cad7cfa 100644 --- a/BLAZAM/Pages/OU/ViewOU.razor +++ b/BLAZAM/Pages/OU/ViewOU.razor @@ -69,7 +69,7 @@ } @code { - IADOrganizationalUnit OU => DirectoryEntry as IADOrganizationalUnit; + IADOrganizationalUnit? OU => DirectoryEntry as IADOrganizationalUnit; IADOrganizationalUnit? parentOU; protected override async Task OnInitializedAsync() { diff --git a/BLAZAM/Pages/Printers/ViewPrinter.razor b/BLAZAM/Pages/Printers/ViewPrinter.razor index 6db0abaa..b8774ad1 100644 --- a/BLAZAM/Pages/Printers/ViewPrinter.razor +++ b/BLAZAM/Pages/Printers/ViewPrinter.razor @@ -136,8 +136,8 @@ { try { - Printer.Delete(); - SnackBarService.Success(Printer.CanonicalName + " has been deleted."); + Printer?.Delete(); + SnackBarService.Success(Printer?.CanonicalName + " has been deleted."); Nav.NavigateTo("/search"); @@ -153,7 +153,7 @@ { if (await MessageService.Confirm("Are you sure you want to save the changes?", "Save Changes")) { - await Printer.CommitChangesAsync(); + await Printer?.CommitChangesAsync(); EditMode = false; Nav.WarnOnNavigation = false; SnackBarService.Success("The changes made to this printer have been saved."); diff --git a/BLAZAM/Pages/Users/CreateUser.razor b/BLAZAM/Pages/Users/CreateUser.razor index 25023539..b584372b 100644 --- a/BLAZAM/Pages/Users/CreateUser.razor +++ b/BLAZAM/Pages/Users/CreateUser.razor @@ -49,7 +49,7 @@ @foreach (var template in Templates.Where(t => t.DeletedAt == null && t.Visible)) { - {SetTemplate(template);}) Variant="Variant.Filled" Color="Color.Primary" Size="Size.Large">@template.Name + {await SetTemplate(template);}) Variant="Variant.Filled" Color="Color.Primary" Size="Size.Large">@template.Name } diff --git a/BLAZAM/Pages/Users/ViewUser.razor b/BLAZAM/Pages/Users/ViewUser.razor index 30ca4894..73664ee0 100644 --- a/BLAZAM/Pages/Users/ViewUser.razor +++ b/BLAZAM/Pages/Users/ViewUser.razor @@ -208,7 +208,7 @@ + Disabled=@(User?.NewEntry==false) /> diff --git a/BLAZAM/Program.cs b/BLAZAM/Program.cs index 29c9b718..24204b67 100644 --- a/BLAZAM/Program.cs +++ b/BLAZAM/Program.cs @@ -81,7 +81,7 @@ public static void Main(string[] args) builder.IntializeProperties(); - _ = new Encryption(Configuration.GetValue("EncryptionKey")); + _ = new Encryption(Configuration?.GetValue("EncryptionKey")); //Setup host logging so it can catch the earliest logs possible diff --git a/BLAZAMGui/UI/AppModal.razor b/BLAZAMGui/UI/AppModal.razor index f9499092..f8e25ac9 100644 --- a/BLAZAMGui/UI/AppModal.razor +++ b/BLAZAMGui/UI/AppModal.razor @@ -10,7 +10,10 @@ - @ChildContent + @if (IsShown) + { + @ChildContent + } From e62153b93366abbc62c92bb0c63ac9656b7b74c8 Mon Sep 17 00:00:00 2001 From: Chris Jacobsen Date: Mon, 1 Apr 2024 17:45:19 -0400 Subject: [PATCH 2/2] Add Changed Widget --- BLAZAMActiveDirectory/Searchers/ADSearch.cs | 4 +- .../Searchers/ADSearchFields.cs | 2 +- .../Widgets/ChangedEntriesWidget.razor | 70 +++++++++++++++++++ 3 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 BLAZAMGui/UI/Dashboard/Widgets/ChangedEntriesWidget.razor diff --git a/BLAZAMActiveDirectory/Searchers/ADSearch.cs b/BLAZAMActiveDirectory/Searchers/ADSearch.cs index 45470acf..0bf30c17 100644 --- a/BLAZAMActiveDirectory/Searchers/ADSearch.cs +++ b/BLAZAMActiveDirectory/Searchers/ADSearch.cs @@ -188,8 +188,8 @@ public async Task> SearchAsync() if (!Fields.CN.IsNullOrEmpty()) FilterQuery += $"(cn=*{Fields.CN}*)"; - if (!Fields.Changed.IsNullOrEmpty()) - FilterQuery += $"(whenChanged>={Fields.Changed})"; + if (Fields.Changed != null) + FilterQuery += $"(whenChanged>={Fields.Changed.Value.ToString("yyyyMMddHHmmss.fZ")})"; if (Fields.Created != null) FilterQuery += $"(whenCreated>={Fields.Created.Value.ToString("yyyyMMddHHmmss.fZ")})"; if (!Fields.SamAccountName.IsNullOrEmpty()) diff --git a/BLAZAMActiveDirectory/Searchers/ADSearchFields.cs b/BLAZAMActiveDirectory/Searchers/ADSearchFields.cs index a5e9e220..dd6274e4 100644 --- a/BLAZAMActiveDirectory/Searchers/ADSearchFields.cs +++ b/BLAZAMActiveDirectory/Searchers/ADSearchFields.cs @@ -20,7 +20,7 @@ public class ADSearchFields public DateTime? Created { get; set; } - public string? Changed { get; set; } + public DateTime? Changed { get; set; } public string? PasswordLastSet { get; set; } diff --git a/BLAZAMGui/UI/Dashboard/Widgets/ChangedEntriesWidget.razor b/BLAZAMGui/UI/Dashboard/Widgets/ChangedEntriesWidget.razor new file mode 100644 index 00000000..92001cc7 --- /dev/null +++ b/BLAZAMGui/UI/Dashboard/Widgets/ChangedEntriesWidget.razor @@ -0,0 +1,70 @@ +@inherits Widget +@attribute [Authorize] + + + + + + + + + + + + @context.Item?.CanonicalName + + + + + + + + + + + + + + + +@code { + List deletedObjects { get; set; } = new(); + + protected override async Task OnInitializedAsync() + { + await base.OnInitializedAsync(); + + var search = new ADSearch(); + search.Fields.Changed = DateTime.Now.AddDays(-1); + deletedObjects = await search.SearchAsync(); + LoadingData = false; + await InvokeAsync(StateHasChanged); + + + } + void RowClicked(DataGridRowClickEventArgs args) + { + if (args.Item != null) + { + GoTo(args.Item); + } + } + + void GoTo(IDirectoryEntryAdapter args) + { + Nav.NavigateTo(args.SearchUri); + } +}