diff --git a/Kyoo.Authentication/Controllers/PremissionValidator.cs b/Kyoo.Authentication/Controllers/PremissionValidator.cs
index dc60faa7..62a4843b 100644
--- a/Kyoo.Authentication/Controllers/PremissionValidator.cs
+++ b/Kyoo.Authentication/Controllers/PremissionValidator.cs
@@ -36,7 +36,7 @@ namespace Kyoo.Authentication
///
public IFilterMetadata Create(PermissionAttribute attribute)
{
- return new PermissionValidator(attribute.Type, attribute.Kind, _options);
+ return new PermissionValidator(attribute.Type, attribute.Kind, attribute.Group, _options);
}
///
@@ -58,6 +58,11 @@ namespace Kyoo.Authentication
/// The kind of permission needed
///
private readonly Kind? _kind;
+
+ ///
+ /// The group of he permission
+ ///
+ private readonly Group _group = Group.Overall;
///
/// The permissions options to retrieve default permissions.
///
@@ -68,11 +73,13 @@ namespace Kyoo.Authentication
///
/// The permission to validate
/// The kind of permission needed
+ /// The group of the permission
/// The option containing default values.
- public PermissionValidator(string permission, Kind kind, IOptionsMonitor options)
+ public PermissionValidator(string permission, Kind kind, Group group, IOptionsMonitor options)
{
_permission = permission;
_kind = kind;
+ _group = group;
_options = options;
}
@@ -125,7 +132,7 @@ namespace Kyoo.Authentication
}
string permStr = $"{permission.ToLower()}.{kind.ToString()!.ToLower()}";
- string overallStr = $"overall.{kind.ToString()!.ToLower()}";
+ string overallStr = $"{_group.ToString()}.{kind.ToString()!.ToLower()}";
AuthenticateResult res = await context.HttpContext.AuthenticateAsync(JwtBearerDefaults.AuthenticationScheme);
if (res.Succeeded)
{
diff --git a/Kyoo.Common/Models/Attributes/PermissionAttribute.cs b/Kyoo.Common/Models/Attributes/PermissionAttribute.cs
index 40228782..24de7950 100644
--- a/Kyoo.Common/Models/Attributes/PermissionAttribute.cs
+++ b/Kyoo.Common/Models/Attributes/PermissionAttribute.cs
@@ -7,16 +7,20 @@ namespace Kyoo.Models.Permissions
///
/// The kind of permission needed.
///
- ///
- /// The admin kind is used for configuration or security sensitive permissions to allow one
- /// to use an overall permission without compromising security.
- ///
public enum Kind
{
Read,
Write,
Create,
- Delete,
+ Delete
+ }
+
+ ///
+ /// The group of the permission.
+ ///
+ public enum Group
+ {
+ Overall,
Admin
}
@@ -34,6 +38,10 @@ namespace Kyoo.Models.Permissions
/// The needed permission kind.
///
public Kind Kind { get; }
+ ///
+ /// The group of this permission
+ ///
+ public Group Group { get; }
///
/// Ask a permission to run an action.
@@ -43,12 +51,17 @@ namespace Kyoo.Models.Permissions
/// (if the type ends with api, it will be removed. This allow you to use nameof(YourApi)).
///
/// The kind of permission needed
- public PermissionAttribute(string type, Kind permission)
+ ///
+ /// The group of this permission (allow grouped permission like overall.read
+ /// for all read permissions of this group)
+ ///
+ public PermissionAttribute(string type, Kind permission, Group group = Group.Overall)
{
if (type.EndsWith("API", StringComparison.OrdinalIgnoreCase))
type = type[..^3];
Type = type.ToLower();
Kind = permission;
+ Group = group;
}
///
diff --git a/Kyoo/Views/ConfigurationApi.cs b/Kyoo/Views/ConfigurationApi.cs
index 833d5993..13d7f5ca 100644
--- a/Kyoo/Views/ConfigurationApi.cs
+++ b/Kyoo/Views/ConfigurationApi.cs
@@ -37,7 +37,7 @@ namespace Kyoo.Api
/// Return the configuration value or the list of configurations
/// No configuration exists for the given slug
[HttpGet("{slug}")]
- [Permission(nameof(ConfigurationApi), Kind.Admin)]
+ [Permission(nameof(ConfigurationApi), Kind.Read, Group.Admin)]
public ActionResult