Implemented API key management with permission checks, database schema, and frontend integration. Adjusted string lengths for Role and API key attributes.
This commit is contained in:
14
Moonlight.Shared/Http/Requests/ApiKeys/CreateApiKeyDto.cs
Normal file
14
Moonlight.Shared/Http/Requests/ApiKeys/CreateApiKeyDto.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Moonlight.Shared.Http.Requests.ApiKeys;
|
||||
|
||||
public class CreateApiKeyDto
|
||||
{
|
||||
[MaxLength(30)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[MaxLength(300)]
|
||||
public string Description { get; set; }
|
||||
|
||||
public string[] Permissions { get; set; }
|
||||
}
|
||||
14
Moonlight.Shared/Http/Requests/ApiKeys/UpdateApiKeyDto.cs
Normal file
14
Moonlight.Shared/Http/Requests/ApiKeys/UpdateApiKeyDto.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Moonlight.Shared.Http.Requests.ApiKeys;
|
||||
|
||||
public class UpdateApiKeyDto
|
||||
{
|
||||
[MaxLength(30)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[MaxLength(300)]
|
||||
public string Description { get; set; }
|
||||
|
||||
public string[] Permissions { get; set; }
|
||||
}
|
||||
@@ -4,9 +4,9 @@ namespace Moonlight.Shared.Http.Requests.Roles;
|
||||
|
||||
public class CreateRoleDto
|
||||
{
|
||||
[Required] [MaxLength(15)] public string Name { get; set; }
|
||||
[Required] [MaxLength(30)] public string Name { get; set; }
|
||||
|
||||
[MaxLength(100)] public string Description { get; set; } = "";
|
||||
[MaxLength(300)] public string Description { get; set; } = "";
|
||||
|
||||
[Required] public string[] Permissions { get; set; }
|
||||
}
|
||||
@@ -4,9 +4,9 @@ namespace Moonlight.Shared.Http.Requests.Roles;
|
||||
|
||||
public class UpdateRoleDto
|
||||
{
|
||||
[Required] [MaxLength(15)] public string Name { get; set; }
|
||||
[Required] [MaxLength(30)] public string Name { get; set; }
|
||||
|
||||
[MaxLength(100)] public string Description { get; set; } = "";
|
||||
[MaxLength(300)] public string Description { get; set; } = "";
|
||||
|
||||
[Required] public string[] Permissions { get; set; }
|
||||
}
|
||||
3
Moonlight.Shared/Http/Responses/ApiKeys/ApiKeyDto.cs
Normal file
3
Moonlight.Shared/Http/Responses/ApiKeys/ApiKeyDto.cs
Normal file
@@ -0,0 +1,3 @@
|
||||
namespace Moonlight.Shared.Http.Responses.ApiKeys;
|
||||
|
||||
public record ApiKeyDto(int Id, string Name, string Description, string[] Permissions, string Key, DateTimeOffset CreatedAt, DateTimeOffset UpdatedAt);
|
||||
@@ -1,8 +1,10 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using Moonlight.Shared.Http.Requests.ApiKeys;
|
||||
using Moonlight.Shared.Http.Requests.Roles;
|
||||
using Moonlight.Shared.Http.Requests.Users;
|
||||
using Moonlight.Shared.Http.Responses;
|
||||
using Moonlight.Shared.Http.Responses.Admin;
|
||||
using Moonlight.Shared.Http.Responses.ApiKeys;
|
||||
using Moonlight.Shared.Http.Responses.Auth;
|
||||
using Moonlight.Shared.Http.Responses.Users;
|
||||
|
||||
@@ -20,6 +22,11 @@ namespace Moonlight.Shared.Http;
|
||||
[JsonSerializable(typeof(RoleDto))]
|
||||
[JsonSerializable(typeof(CreateRoleDto))]
|
||||
[JsonSerializable(typeof(UpdateRoleDto))]
|
||||
[JsonSerializable(typeof(CreateApiKeyDto))]
|
||||
[JsonSerializable(typeof(UpdateApiKeyDto))]
|
||||
[JsonSerializable(typeof(UpdateApiKeyDto))]
|
||||
[JsonSerializable(typeof(PagedData<ApiKeyDto>))]
|
||||
[JsonSerializable(typeof(ApiKeyDto))]
|
||||
public partial class SerializationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
@@ -16,6 +16,16 @@ public static class Permissions
|
||||
public const string Logout = $"{Prefix}{Section}.{nameof(Logout)}";
|
||||
}
|
||||
|
||||
public static class ApiKeys
|
||||
{
|
||||
private const string Section = "ApiKeys";
|
||||
|
||||
public const string View = $"{Prefix}{Section}.{nameof(View)}";
|
||||
public const string Edit = $"{Prefix}{Section}.{nameof(Edit)}";
|
||||
public const string Create = $"{Prefix}{Section}.{nameof(Create)}";
|
||||
public const string Delete = $"{Prefix}{Section}.{nameof(Delete)}";
|
||||
}
|
||||
|
||||
public static class Roles
|
||||
{
|
||||
private const string Section = "Roles";
|
||||
|
||||
Reference in New Issue
Block a user