Add group support to partial permissions

This commit is contained in:
Zoe Roux 2024-02-03 18:02:02 +01:00
parent c26a95ed60
commit cee7ca2ca0
3 changed files with 18 additions and 3 deletions

View File

@ -42,7 +42,7 @@ namespace Kyoo.Abstractions.Models.Permissions
/// <summary>
/// The group of this permission.
/// </summary>
public Group? Group { get; set; }
public Group Group { get; set; }
/// <summary>
/// Ask a permission to run an action.

View File

@ -54,6 +54,11 @@ namespace Kyoo.Abstractions.Models.Permissions
/// </summary>
public enum Group
{
/// <summary>
/// Default group indicating no value.
/// </summary>
None,
/// <summary>
/// Allow all operations on basic items types.
/// </summary>

View File

@ -93,7 +93,7 @@ namespace Kyoo.Authentication
/// <summary>
/// The group of he permission.
/// </summary>
private readonly Group _group = Group.Overall;
private Group _group;
/// <summary>
/// The permissions options to retrieve default permissions.
@ -146,7 +146,7 @@ namespace Kyoo.Authentication
);
}
if (group != null)
if (group is not null and not Group.None)
_group = group.Value;
_options = options;
}
@ -159,6 +159,16 @@ namespace Kyoo.Authentication
if (permission == null || kind == null)
{
if (
context.HttpContext.Items["PermissionGroup"]
is Group group and not Group.None
)
_group = group;
else if (_group == Group.None)
_group = Group.Overall;
else
context.HttpContext.Items["PermissionGroup"] = _group;
switch (context.HttpContext.Items["PermissionType"])
{
case string perm: