From 07728d1048f34e1d048da63684b341ab30bc1d06 Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Mon, 16 Oct 2023 02:01:27 +1100 Subject: FeedService and AclDialog --- Pages/Component/AclDialog.razor | 93 ++++++++++++++++++++++++++++------------- 1 file changed, 65 insertions(+), 28 deletions(-) (limited to 'Pages/Component/AclDialog.razor') diff --git a/Pages/Component/AclDialog.razor b/Pages/Component/AclDialog.razor index 691e984..c924b98 100644 --- a/Pages/Component/AclDialog.razor +++ b/Pages/Component/AclDialog.razor @@ -1,20 +1,24 @@ @using System.Numerics; @inject HBContext db +@inject ISecurityService securityService @implements IDialog
- @if(obj?.Acl is not null) { - - - - - - - - @foreach(var rule in obj.Acl.Rules.OrderByDescending(r => r.Action)) { + obj.Owner = sid) + @ref=ownerSelect/> +
ActionSubjectPermissions
+ + + + + + @if(obj?.Acl is not null) { + @foreach(var rule in obj.Acl.Rules) { + - } -
ActionSubjectPermissions
@@ -24,24 +28,37 @@
- @rule.Principal.ToString() + @if(rule.Principal != WellKnownSid.NullSid) { + @(securityService.TranslateName(rule.Principal)) + } else { + Select a user/group! + } + + @if(rule.Permissions == 0) { + None + } else { + @GetActivePermissions(rule); + } @GetActivePermissions(rule) EditRule(rule))>🖉 RemoveRule(rule))>✖
-
-
Add new
- } + } + +
+
Add new
@if(ruleToEdit is not null && permissionCheckboxes is not null) { - - var permissions = Acl.GetPermissionDescriptions(obj) + ruleToEdit.Principal = sid) + @ref=subjectSelect/> + var permissions = Acl.GetPermissionDescriptions(obj!) .OrderByDescending(kv => BitOperations.PopCount(kv.Value)) .ThenBy(kv => kv.Value); foreach(var perm in permissionCheckboxes) { @@ -60,7 +77,7 @@ @if(obj?.Acl is not null) { - } @@ -91,7 +108,9 @@ private string? editOwner; private string? editSubject; - private Dialog dialog; + private Dialog dialog; + private MiniPrincipalSelect ownerSelect; + private MiniPrincipalSelect? subjectSelect; public void Show() => Visible = true; public void Hide() => Visible = false; @@ -107,6 +126,8 @@ editOwner = null; CancelEditRule(); + db.ChangeTracker.Clear(); + obj = db.Objects .Include(o => o.Acl) .First(o => o.ObjectId == value.ObjectId); @@ -121,22 +142,29 @@ addedAcl = true; } + ownerSelect.SecurityIdentifier = obj.Owner; lastHashCode = GetAclHashCode(obj.Acl); } } public bool ApplyDisabled => - #if DEBUG - false; - #else GetAclHashCode(obj.Acl!) == lastHashCode || obj.Acl!.Rules.Select(r => r.Principal).Contains(WellKnownSid.NullSid); - #endif + + protected override void OnAfterRender(bool firstRender) { + if(subjectSelect is null || ruleToEdit is null) + return; + if(subjectSelect.SecurityIdentifier is not null) + return; + + subjectSelect.SecurityIdentifier = ruleToEdit.Principal; + StateHasChanged(); + } private string GetActivePermissions(AclRule rule) { var perms = Acl.GetPermissionDescriptions(obj) - .Where(kv => (rule.Permissions & kv.Value) == kv.Value) - .ToList(); + .Where(kv => (rule.Permissions & kv.Value) == kv.Value) + .ToList(); // Filter the list of matching permissions to include the // most relevant encapsulation permissions only. E.g. if @@ -159,6 +187,12 @@ } private void ApplyAcl() { + if(obj.Acl!.Rules.Count() == 0) { + obj.Acl = null; + if(!addedAcl) + db.Remove(obj.Acl!); + } + db.SaveChanges(); Hide(); } @@ -198,14 +232,17 @@ // Special hash function to identify only the elements of // the ACL that may have been changed by the user via this // dialog. - private int GetAclHashCode(Acl acl) => - !acl.Rules.Any() ? 0 : acl.Rules + private int GetAclHashCode(Acl acl) { + var aclHash = !acl.Rules.Any() ? 0 : acl.Rules .Select(r => ( r.Action, r.Permissions, r.Principal.GetHashCode()).GetHashCode()) .Aggregate((a, v) => HashCode.Combine(a, v)); + return HashCode.Combine(aclHash, obj.Owner.GetHashCode()); + } + private class PermissionCheckbox { public string Description { get; private init; } @@ -228,4 +265,4 @@ } } } -} \ No newline at end of file +} -- cgit v1.3