diff options
Diffstat (limited to 'Pages/Component/AclDialog.razor')
| -rw-r--r-- | Pages/Component/AclDialog.razor | 93 |
1 files changed, 65 insertions, 28 deletions
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 <Dialog HeightPixels=500 WidthPixels=900 Title="Edit permissions" @ref=dialog> <div class="vcontainer"> <div class="hcontainer"> <div> - @if(obj?.Acl is not null) { - <MiniPrincipalSelect Label="Owner"/> - <table class="data-table"> - <tr> - <th>Action</th> - <th>Subject</th> - <th colspan="2">Permissions</th> - </tr> - @foreach(var rule in obj.Acl.Rules.OrderByDescending(r => r.Action)) { + <MiniPrincipalSelect + Label="Owner" + OnChange=@((sid) => obj.Owner = sid) + @ref=ownerSelect/> + <table class="data-table"> + <tr> + <th>Action</th> + <th>Subject</th> + <th colspan="2">Permissions</th> + </tr> + @if(obj?.Acl is not null) { + @foreach(var rule in obj.Acl.Rules) { <tr> <td> <div> @@ -24,24 +28,37 @@ </div> </td> <td> - @rule.Principal.ToString() + @if(rule.Principal != WellKnownSid.NullSid) { + @(securityService.TranslateName(rule.Principal)) + } else { + <i style="color:var(--col-error-pri);">Select a user/group!</i> + } + </td> + <td> + @if(rule.Permissions == 0) { + <i>None</i> + } else { + @GetActivePermissions(rule); + } </td> - <td>@GetActivePermissions(rule)</td> <td> <a title="Edit" href="javascript:;" @onclick=@(() => EditRule(rule))>🖉</a> <a title="Delete" href="javascript:;" @onclick=@(() => RemoveRule(rule))>✖</a> </td> </tr> } - </table> - <br/> - <center><a href="javascript:;" @onclick=AddRule>Add new</a></center> - } + } + </table> + <br/> + <center><a href="javascript:;" @onclick=AddRule>Add new</a></center> </div> <div> @if(ruleToEdit is not null && permissionCheckboxes is not null) { - <MiniPrincipalSelect Label="Subject"/> - var permissions = Acl.GetPermissionDescriptions(obj) + <MiniPrincipalSelect + Label="Subject" + OnChange=@((sid) => 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 @@ <ButtonContainer> <button class="secondary" @onclick=Hide>Cancel</button> @if(obj?.Acl is not null) { - <button data-keyboard-shortcut="a" @onclick=ApplyAcl disabled=@(ApplyDisabled)> + <button data-keyboard-shortcut="a" @onclick=ApplyAcl disabled=@ApplyDisabled> <u>A</u>pply </button> } @@ -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 +} |
