diff options
| author | Jake Mannens <jake@asger.xyz> | 2023-10-03 02:20:13 +1100 |
|---|---|---|
| committer | Jake Mannens <jake@asger.xyz> | 2023-10-03 02:20:13 +1100 |
| commit | 035d2e3858dd55580c294031573c3be9e1999449 (patch) | |
| tree | 643d545aa036b901f185ba7148d4a4353d6c957b /Pages | |
| parent | 7170867a9a2650fa5a98b9e2664fb2114a0bf114 (diff) | |
AclDialog
Diffstat (limited to 'Pages')
| -rw-r--r-- | Pages/Component/AclDialog.razor | 76 | ||||
| -rw-r--r-- | Pages/Component/AclDialog.razor.css | 8 | ||||
| -rw-r--r-- | Pages/Component/Titlebar.razor | 2 | ||||
| -rw-r--r-- | Pages/ViewMedia.razor | 4 |
4 files changed, 85 insertions, 5 deletions
diff --git a/Pages/Component/AclDialog.razor b/Pages/Component/AclDialog.razor index 33d1f03..7c3267d 100644 --- a/Pages/Component/AclDialog.razor +++ b/Pages/Component/AclDialog.razor @@ -1,19 +1,87 @@ -@implements IDialog +@using System.Numerics; +@inject IDbContextFactory<HBContext> dbFactory; +@implements IDialog <Dialog Title="Edit permissions" @ref=dialog> + @if(obj?.Acl is not null) { + <table class="data-table"> + <tr> + <th>Action</th> + <th>Subject</th> + <th>Permissions</th> + </tr> + @foreach(var rule in Object.Acl.Rules) { + <tr> + <td style="font-family:'lucida console';font-size:10pt;">@rule.Action.ToString()</td> + <td style="font-family:'lucida console';font-size:10pt;">@rule.Principal.ToString()</td> + <td style="font-family:'lucida console';font-size:10pt;">@GetActivePermissions(rule)</td> + </tr> + } + </table> + <ButtonContainer> + <button class="secondary" @onclick=Hide>Cancel</button> + </ButtonContainer> + } else { + <center><i>This item does not have any permissions set!</i></center> + <ButtonContainer> + <button class="secondary" @onclick=Hide>Cancel</button> + </ButtonContainer> + } </Dialog> @code { - [Parameter] - public HBObject Object { get; set; } - public bool Visible { get => dialog.Visible; set => dialog.Visible = value; } + private HBObject? obj; + private Dialog dialog; public void Show() => Visible = true; public void Hide() => Visible = false; + + public HBObject? Object { + get => obj; + set { + if(value is null) { + obj = null; + return; + } + + using var db = dbFactory.CreateDbContext(); + + obj = db.Objects + .Include(o => o.Acl) + .First(o => o.ObjectId == value.ObjectId); + + if(obj.Acl is not null) + db.Entry(obj.Acl).Collection(a => a.Rules).Load(); + } + } + + public string GetActivePermissions(AclRule rule) { + var perms = Acl.GetPermissionDescriptions(obj!) + .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 + // 'Full access' includes 'Read' and 'Write', then only + // show 'Full access'. + List<int> toRemove = new(); + for(int i = 0; i < perms.Count(); i++) + for(int j = 0; j < perms.Count(); j++) + if(i != j) + if((perms[i].Value & perms[j].Value) == perms[i].Value) + toRemove.Add(i); + for(int i = toRemove.Count() - 1; i >= 0; i--) + perms.RemoveAt(toRemove[i]); + + return string.Join(", ", perms + .OrderByDescending(kv => BitOperations.PopCount(kv.Value)) + .ThenByDescending(kv => kv.Value) + .Select(kv => kv.Key)); + } }
\ No newline at end of file diff --git a/Pages/Component/AclDialog.razor.css b/Pages/Component/AclDialog.razor.css new file mode 100644 index 0000000..7a7e545 --- /dev/null +++ b/Pages/Component/AclDialog.razor.css @@ -0,0 +1,8 @@ +table td:nth-child(2n) { + white-space: nowrap; + width: 1px; +} + +table p { + margin: 8px 0 8px 0; +}
\ No newline at end of file diff --git a/Pages/Component/Titlebar.razor b/Pages/Component/Titlebar.razor index ad41532..766787a 100644 --- a/Pages/Component/Titlebar.razor +++ b/Pages/Component/Titlebar.razor @@ -74,5 +74,5 @@ private AboutDialog aboutDialog; - private string username => AuthState.GetAwaiter().GetResult().User.Identity?.Name ?? "fugg"; + private string username => AuthState.GetAwaiter().GetResult().User.Identity?.Name!; } diff --git a/Pages/ViewMedia.razor b/Pages/ViewMedia.razor index 444fbc5..607e59f 100644 --- a/Pages/ViewMedia.razor +++ b/Pages/ViewMedia.razor @@ -83,6 +83,7 @@ </div> <div id="button-container"> <ButtonContainer> + <button @onclick=@(() => { aclDialog.Object = media; aclDialog.Show(); }) class="secondary" data-keyboard-shortcut="p">Edit <u>P</u>ermissions</button> <button @onclick=@(() => deleteDialog.Show()) class="warning" data-keyboard-shortcut="d"><u>D</u>elete</button> <button @onclick=@(() => tagDialog.Show()) class="secondary" data-keyboard-shortcut="t">Add <u>T</u>ag</button> <button @onclick=@(() => ocrDialog.Show()) class="secondary" data-keyboard-shortcut="o">View <u>O</u>CR</button> @@ -125,6 +126,8 @@ OnSubmit=AddTags @ref=tagDialog/> +<AclDialog @ref=aclDialog/> + @code { [Parameter] [SupplyParameterFromQuery(Name = "m")] @@ -142,6 +145,7 @@ private Dialog deleteDialog; private Dialog ocrDialog; private TagSelectDialog tagDialog; + private AclDialog aclDialog; private ElementReference shortDescriptionInput; |
