Skip to content
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

Fix for slow performing OU TreeView's #517

Merged
merged 8 commits into from
Aug 28, 2024
2 changes: 1 addition & 1 deletion BLAZAM.Tests/BLAZAM.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
2 changes: 1 addition & 1 deletion BLAZAM/BLAZAM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<ServerGarbageCollection>false</ServerGarbageCollection>
<AssemblyVersion>1.0.1</AssemblyVersion>
<Version>2024.08.22.2343</Version>
<Version>2024.08.28.2018</Version>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<RootNamespace>BLAZAM</RootNamespace>
<GenerateDocumentationFile>False</GenerateDocumentationFile>
Expand Down
50 changes: 27 additions & 23 deletions BLAZAM/Pages/Browse/ViewDirectoryEntry.razor
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
@inject IStringLocalizer<AppLocalization> AppLocalization
<CascadingValue Value="ChangeHistoryModal">
@switch (DirectoryEntry?.ObjectType)
{
case ActiveDirectoryObjectType.User:
<ViewUser DirectoryEntry="DirectoryEntry" />
break;
case ActiveDirectoryObjectType.Group:
<ViewGroup DirectoryEntry="DirectoryEntry" />
break;
case ActiveDirectoryObjectType.Computer:
<ViewComputer DirectoryEntry="DirectoryEntry" />
break;
case ActiveDirectoryObjectType.OU:
<ViewOU DirectoryEntry="DirectoryEntry" />
break;
case ActiveDirectoryObjectType.Printer:
<ViewPrinter DirectoryEntry="DirectoryEntry" />
break;
case ActiveDirectoryObjectType.BitLocker:
<ViewBitLocker DirectoryEntry="DirectoryEntry" />
break;
}
@switch (DirectoryEntry?.ObjectType)
{
case ActiveDirectoryObjectType.User:
<ViewUser DirectoryEntry="DirectoryEntry" />
break;
case ActiveDirectoryObjectType.Group:
<ViewGroup DirectoryEntry="DirectoryEntry" />
break;
case ActiveDirectoryObjectType.Computer:
<ViewComputer DirectoryEntry="DirectoryEntry" />
break;
case ActiveDirectoryObjectType.OU:
<ViewOU DirectoryEntry="DirectoryEntry" />
break;
case ActiveDirectoryObjectType.Printer:
<ViewPrinter DirectoryEntry="DirectoryEntry" />
break;
case ActiveDirectoryObjectType.BitLocker:
<ViewBitLocker DirectoryEntry="DirectoryEntry" />
break;
}
</CascadingValue>
<AppModal Title=@AppLocalization["Change History"] @ref=@ChangeHistoryModal Options=@(new DialogOptions(){FullWidth=true,MaxWidth=MaxWidth.ExtraExtraLarge})>
<AppModal Title=@AppLocalization["Change History"]
@ref=@ChangeHistoryModal
Options=@(new DialogOptions(){FullWidth=true,
MaxWidth=MaxWidth.ExtraExtraLarge,
CloseButton=true})>
@if (ChangeHistoryModal?.IsShown == true)
{
<ChangeHistoryModalContent Model="DirectoryEntry" />
Expand All @@ -34,5 +38,5 @@
[Parameter]
public IDirectoryEntryAdapter? DirectoryEntry { get; set; }

protected AppModal? ChangeHistoryModal{ get; set; }
protected AppModal? ChangeHistoryModal { get; set; }
}
50 changes: 40 additions & 10 deletions BLAZAM/Pages/Computers/ViewComputer.razor
Original file line number Diff line number Diff line change
Expand Up @@ -300,24 +300,54 @@
{
if (Computer != null && await MessageService.Confirm("Are you sure you want to save the changes?"))
{
var jobResults = await Computer.CommitChangesAsync();
if (jobResults.Result == JobResult.Passed)
SavingChanges = true;
await RefreshEntryComponents();
try
{

var changes = Computer.Changes;
var assignTo = Computer.ToAssignTo;
var unassignFrom = Computer.ToUnassignFrom;
var jobResults = await Computer.CommitChangesAsync();
if (jobResults.Result == JobResult.Passed)
{
foreach (var assignment in assignTo)
{
await AuditLogger.Computer.Assigned(assignment.Member, assignment.Group);
await AuditLogger.Group.MemberAdded(assignment.Group, assignment.Member);
}

await AuditLogger.Computer.Changed(Computer, Computer.Changes);
_ = OUNotificationService.PostAsync(Computer, NotificationType.Modify);
foreach (var assignment in unassignFrom)
{
await AuditLogger.Computer.Unassigned(assignment.Member, assignment.Group);
await AuditLogger.Group.MemberRemoved(assignment.Group, assignment.Member);
}
if (changes.Any(c => c.Field != ActiveDirectoryFields.MemberOf.FieldName))
{
_ = OUNotificationService.PostAsync(Computer, NotificationType.Modify);
await AuditLogger.User.Changed(Computer, changes.Where(c => c.Field != ActiveDirectoryFields.MemberOf.FieldName).ToList());
}

EditMode = false;
Nav.WarnOnNavigation = false;
SnackBarService.Success("The changes made to this computer have been saved.");
await RefreshEntryComponents();


EditMode = false;
Nav.WarnOnNavigation = false;
SnackBarService.Success("The changes made to this computer have been saved.");
await RefreshEntryComponents();
}
else
{
await jobResults.ShowJobDetailsDialogAsync(MessageService);
}
}
else
catch (ApplicationException ex)
{
await jobResults.ShowJobDetailsDialogAsync(MessageService);
SnackBarService.Error(ex.Message);

}
SavingChanges = false;

await RefreshEntryComponents();

}
}
Expand Down
26 changes: 23 additions & 3 deletions BLAZAM/Pages/Groups/ViewGroup.razor
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,32 @@
if (await MessageService.Confirm("Are you sure you want to save the changes to " + Group.CanonicalName + "?", "Save Changes"))
{


var changes = Group.Changes;
var assignTo = Group.MembersToAdd;
var unassignFrom = Group.MembersToRemove;
var jobResults = await Group.CommitChangesAsync();
if (jobResults.Result == JobResult.Passed)
{
await AuditLogger.Group.Changed(Group, Group.Changes);

_ = OUNotificationService.PostAsync(Group, NotificationType.Modify);
foreach (var assignment in assignTo)
{
await AuditLogger.User.Assigned(assignment.Member, assignment.Group);
await AuditLogger.Group.MemberAdded(assignment.Group, assignment.Member);
}

foreach (var assignment in unassignFrom)
{
await AuditLogger.User.Unassigned(assignment.Member, assignment.Group);
await AuditLogger.Group.MemberRemoved(assignment.Group, assignment.Member);
}
if (changes.Any(c => c.Field != "member"))
{
_ = OUNotificationService.PostAsync(Group, NotificationType.Modify);
await AuditLogger.Group.Changed(Group, changes.Where(c => c.Field != ActiveDirectoryFields.MemberOf.FieldName).ToList());
}
//await AuditLogger.Group.Changed(Group, Group.Changes);

//_ = OUNotificationService.PostAsync(Group, NotificationType.Modify);

EditMode = false;
Nav.WarnOnNavigation = false;
Expand Down
4 changes: 2 additions & 2 deletions BLAZAMActiveDirectory/Adapters/ADGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace BLAZAM.ActiveDirectory.Adapters

public class ADGroup : GroupableDirectoryAdapter, IADGroup
{
protected List<GroupMembership> MembersToRemove = new List<GroupMembership>();
protected List<GroupMembership> MembersToAdd = new List<GroupMembership>();
public List<GroupMembership> MembersToRemove { get; private set; } = new List<GroupMembership>();
public List<GroupMembership> MembersToAdd { get; private set; } = new List<GroupMembership>();
public override string? DisplayName { get => base.CanonicalName; set => base.CanonicalName = value; }
public string? GroupName
{
Expand Down
5 changes: 4 additions & 1 deletion BLAZAMActiveDirectory/Interfaces/IADGroup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.DirectoryServices;
using BLAZAM.ActiveDirectory.Adapters;
using System.DirectoryServices;

namespace BLAZAM.ActiveDirectory.Interfaces
{
Expand All @@ -11,6 +12,8 @@ public interface IADGroup : IGroupableDirectoryAdapter, IComparable
List<IGroupableDirectoryAdapter> Members { get; }
List<string>? MembersAsStrings { get; }
IEnumerable<IGroupableDirectoryAdapter> NestedMembers { get; }
List<GroupMembership> MembersToRemove { get; }
List<GroupMembership> MembersToAdd { get; }

void AssignMember(IGroupableDirectoryAdapter member);
void UnassignMember(IGroupableDirectoryAdapter member);
Expand Down
2 changes: 1 addition & 1 deletion BLAZAMCommon.Tests/BLAZAMCommon.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.8" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />
<PackageReference Include="System.Security.Permissions" Version="8.0.0" />
<PackageReference Include="xunit" Version="2.9.0" />
Expand Down
2 changes: 1 addition & 1 deletion BLAZAMGui/UI/Inputs/TreeViews/OUTreeView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@bind-SelectedValue="SelectedEntry">
<ItemTemplate>
<MudTreeViewItem Value="@context.Value"
Items=@GetItems(context.Value)
Items=@GetChildren(context.Value)
LoadingIconColor="Color.Info"
@bind-Expanded="@context.Expanded"
@bind-Activated=context.Selected
Expand Down
21 changes: 21 additions & 0 deletions BLAZAMServices/Audit/ComputerAudit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,27 @@ public override async Task<bool> Deleted(IDirectoryEntryAdapter deletedEntry)
=> await Log(t => t.DirectoryEntryAuditLogs,
AuditActions.Computer_Deleted, deletedEntry);

public async Task<bool> Assigned(IDirectoryEntryAdapter member, IDirectoryEntryAdapter parent)
{
await Log(c => c.DirectoryEntryAuditLogs,
AuditActions.Computer_Assigned,
member,
null,
"Assigned to " + parent.DN);

return true;
}
public async Task<bool> Unassigned(IDirectoryEntryAdapter member, IDirectoryEntryAdapter parent)
{
await Log(c => c.DirectoryEntryAuditLogs,
AuditActions.Computer_Unassigned,
member,
null,
"Unassigned from " + parent.DN);

return true;
}

public override async Task<bool> Searched(IDirectoryEntryAdapter searchedComputer) => await Log(AuditActions.Computer_Searched, (IADComputer)searchedComputer);

private async Task<bool> Log(string action, IADComputer searchedComputer)
Expand Down
2 changes: 1 addition & 1 deletion BLAZAMServices/Audit/GroupAudit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ await Log(c => c.DirectoryEntryAuditLogs,
public async Task<bool> MemberRemoved(IDirectoryEntryAdapter parent, IDirectoryEntryAdapter member)
{
await Log(c => c.DirectoryEntryAuditLogs,
AuditActions.Group_Member_Added,
AuditActions.Group_Member_Removed,
parent,
null,
"Removed member " + member.DN);
Expand Down
10 changes: 5 additions & 5 deletions BLAZAMServices/Background/OUNotificationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,36 +43,36 @@ public async Task PostAsync(IDirectoryEntryAdapter source, NotificationType noti
{
case NotificationType.Create:
notificationTitle += _appLocalization["Created"];
notificationBody += _appLocalization["was created at"] + source.Created?.ToLocalTime();
notificationBody += _appLocalization["was created at "] + source.Created?.ToLocalTime();
var createdMessage = NotificationType.Create.ToNotification<EntryCreatedEmailMessage>();
createdMessage.EntryName = source.CanonicalName;
emailMessage = createdMessage;
break;
case NotificationType.Delete:
notificationTitle += _appLocalization["Deleted"];
notificationBody += _appLocalization["was deleted at"] + source.LastChanged?.ToLocalTime();
notificationBody += _appLocalization["was deleted at "] + source.LastChanged?.ToLocalTime();
var deletedMessage = NotificationType.Delete.ToNotification<EntryDeletedEmailMessage>();
deletedMessage.EntryName = source.CanonicalName;
emailMessage = deletedMessage;
break;
case NotificationType.Modify:
notificationTitle += _appLocalization["Modified"];
notificationBody += _appLocalization["was modified at"] + source.LastChanged?.ToLocalTime();
notificationBody += _appLocalization["was modified at "] + source.LastChanged?.ToLocalTime();
var editedMessage = NotificationType.Modify.ToNotification<EntryEditedEmailMessage>();
editedMessage.EntryName = source.CanonicalName;
emailMessage = editedMessage;
break;
case NotificationType.GroupAssignment:
notificationTitle += _appLocalization["Group Membership Changed"];
notificationBody += _appLocalization["was modified at"] + source.LastChanged?.ToLocalTime();
notificationBody += _appLocalization["was modified at "] + source.LastChanged?.ToLocalTime();

var groupMembershipMessage = NotificationType.GroupAssignment.ToNotification<EntryGroupAssignmentEmailMessage>();
groupMembershipMessage.EntryName = source.CanonicalName;
emailMessage = groupMembershipMessage;
break;
case NotificationType.PasswordChange:
notificationTitle += _appLocalization["Password Reset"];
notificationBody += _appLocalization["had a password reset at"] + source.LastChanged?.ToLocalTime();
notificationBody += _appLocalization["had a password reset at "] + source.LastChanged?.ToLocalTime();
var passwordChangeMessage = NotificationType.PasswordChange.ToNotification<PasswordChangedEmailMessage>();
passwordChangeMessage.EntryName = source.CanonicalName;
emailMessage = passwordChangeMessage;
Expand Down
4 changes: 2 additions & 2 deletions PlaywrightTests/PlaywrightTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="NUnit" Version="4.2.1" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0">
<PrivateAssets>all</PrivateAssets>
Expand Down
Loading