From 2c30354c4af308bf9856a3651d9ba3a686eed936 Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Fri, 6 Oct 2023 16:18:30 +1100 Subject: More work on AclDialog --- Pages/Component/AclDialog.razor | 127 ++++++++++++++++++++++++++++++------ Pages/Component/AclDialog.razor.css | 14 ++-- 2 files changed, 114 insertions(+), 27 deletions(-) (limited to 'Pages/Component') diff --git a/Pages/Component/AclDialog.razor b/Pages/Component/AclDialog.razor index 6df9320..0d24530 100644 --- a/Pages/Component/AclDialog.razor +++ b/Pages/Component/AclDialog.razor @@ -7,10 +7,19 @@
@if(obj?.Acl is not null) { - +
+ @if(editOwner is not null) { + + + + + } else { + + editOwner = obj.Owner.ToString())> + @obj.Owner.ToString() + + } +
@@ -21,42 +30,54 @@ }
Action
- @(WellKnownSid.TranslateSid(rule.Principal) ?? rule.Principal.ToString()) + @rule.Principal.ToString() @GetActivePermissions(rule) - 🖉 - + EditRule(rule))>🖉 + RemoveRule(rule))>✖

-
Add new
+
Add new
} else {

This item does not have any permissions set!

}
- @if(obj?.Acl is not null) { + @if(ruleToEdit is not null && permissionCheckboxes is not null) {
- - + @if(editSubject is not null) { + + + + + } else { + + editSubject = ruleToEdit.Principal.ToString())> + @if(ruleToEdit.Principal == WellKnownSid.NullSid) { + Select a user or group + } else { + @ruleToEdit.Principal.ToString() + } + + }
- var permissions = Acl.GetPermissionDescriptions(obj) + var permissions = Acl.GetPermissionDescriptions(obj!) .OrderByDescending(kv => BitOperations.PopCount(kv.Value)) .ThenBy(kv => kv.Value); - foreach(var kv in permissions) { + foreach(var perm in permissionCheckboxes) { } } else { -

Click Edit next to an ACL to edit it's permissions

+

Click 'Edit' next to a rule to edit it's permissions

}
@@ -79,7 +100,12 @@ } } - private HBObject? obj; + private HBObject? obj; + private AclRule? ruleToEdit; + private PermissionCheckbox[]? permissionCheckboxes; + + private string? editOwner; + private string? editSubject; private Dialog dialog; @@ -94,6 +120,9 @@ public HBObject? Object { get => obj; set { + editOwner = null; + CancelEditRule(); + if(value is null) { obj = null; return; @@ -110,7 +139,7 @@ } } - public string GetActivePermissions(AclRule rule) { + private string GetActivePermissions(AclRule rule) { var perms = Acl.GetPermissionDescriptions(obj!) .Where(kv => (rule.Permissions & kv.Value) == kv.Value) .ToList(); @@ -125,6 +154,7 @@ if(i != j) if((perms[i].Value & perms[j].Value) == perms[i].Value) toRemove.Add(i); + toRemove = toRemove.Order().Distinct().ToList(); for(int i = toRemove.Count() - 1; i >= 0; i--) perms.RemoveAt(toRemove[i]); @@ -133,4 +163,59 @@ .ThenBy(kv => kv.Value) .Select(kv => kv.Key)); } + + private void AddRule() { + var rule = new AclRule() { + Principal = WellKnownSid.NullSid, + Action = AclRuleAction.Allow, + Permissions = 0 + }; + + obj!.Acl!.Rules.Add(rule); + EditRule(rule); + } + + private void RemoveRule(AclRule rule) { + if(rule == ruleToEdit) + CancelEditRule(); + obj!.Acl!.Rules.Remove(rule); + } + + private void EditRule(AclRule rule) { + ruleToEdit = rule; + editSubject = null; + permissionCheckboxes = Acl.GetPermissionDescriptions(obj!) + .OrderByDescending(kv => BitOperations.PopCount(kv.Value)) + .ThenBy(kv => kv.Value) + .Select(kv => new PermissionCheckbox(rule, kv)) + .ToArray(); + } + + private void CancelEditRule() { + ruleToEdit = null; + permissionCheckboxes = null; + } + + private class PermissionCheckbox { + public string Description { get; private init; } + + private AclRule rule; + private ulong mask; + + public PermissionCheckbox(AclRule rule, KeyValuePair kv) { + this.rule = rule; + this.mask = kv.Value; + Description = kv.Key; + } + + public bool Value { + get => (rule.Permissions & mask) == mask; + set { + if(value) + rule.Permissions |= mask; + else + rule.Permissions &= ~mask; + } + } + } } \ No newline at end of file diff --git a/Pages/Component/AclDialog.razor.css b/Pages/Component/AclDialog.razor.css index 74e405f..c9ac518 100644 --- a/Pages/Component/AclDialog.razor.css +++ b/Pages/Component/AclDialog.razor.css @@ -34,6 +34,7 @@ div.principal-select { align-items: center; display: flex; flex-direction: row; + margin-bottom: 16px; } div.principal-select * { @@ -61,16 +62,11 @@ table tr { } table td { - white-space: nowrap; text-overflow: ellipsis; font-size: 8pt; font-family: 'Lucida Console'; } -table td:last-child { - font-size: 12pt; -} - table td:nth-last-child(2) { border-right: none !important; } @@ -79,9 +75,15 @@ table tr:nth-child(2n+1) td:not(:first-child) { background: rgba(255, 255, 255, 0.1); } -table td:nth-child(2n) { +table td:first-child { + width: 1px; +} + +table td:last-child { width: 1px; white-space: nowrap; + text-align: right; + font-size: 12pt; } table td > div { -- cgit v1.3