From 6657bae0cd42c40c8a8415f03b90279b94901941 Mon Sep 17 00:00:00 2001 From: ChiaraBm Date: Tue, 15 Apr 2025 13:42:30 +0200 Subject: [PATCH] Improved api key ux --- .../Admin/ApiKeys/ApiKeysController.cs | 2 -- .../UI/Views/Admin/Api/Create.razor | 12 ++++++++++-- .../UI/Views/Admin/Api/Update.razor | 18 +++++------------- .../Admin/ApiKeys/UpdateApiKeyRequest.cs | 6 ------ 4 files changed, 15 insertions(+), 23 deletions(-) diff --git a/Moonlight.ApiServer/Http/Controllers/Admin/ApiKeys/ApiKeysController.cs b/Moonlight.ApiServer/Http/Controllers/Admin/ApiKeys/ApiKeysController.cs index f7075e97..055fe9dd 100644 --- a/Moonlight.ApiServer/Http/Controllers/Admin/ApiKeys/ApiKeysController.cs +++ b/Moonlight.ApiServer/Http/Controllers/Admin/ApiKeys/ApiKeysController.cs @@ -118,8 +118,6 @@ public class ApiKeysController : Controller throw new HttpApiException("No api key with that id found", 404); apiKey.Description = request.Description; - apiKey.PermissionsJson = request.PermissionsJson; - apiKey.ExpiresAt = request.ExpiresAt; await ApiKeyRepository.Update(apiKey); diff --git a/Moonlight.Client/UI/Views/Admin/Api/Create.razor b/Moonlight.Client/UI/Views/Admin/Api/Create.razor index ac47304c..a102d988 100644 --- a/Moonlight.Client/UI/Views/Admin/Api/Create.razor +++ b/Moonlight.Client/UI/Views/Admin/Api/Create.razor @@ -8,6 +8,7 @@ @inject NavigationManager Navigation @inject ToastService ToastService @inject AlertService AlertService +@inject DownloadService DownloadService @@ -38,7 +39,7 @@
- +
@@ -57,11 +58,18 @@ private async Task OnSubmit() { + Request.ExpiresAt = Request.ExpiresAt.ToUniversalTime(); + var response = await ApiClient.PostJson("api/admin/apikeys", Request); + await DownloadService.DownloadString( + $"moonlight-key-{response.Id}.txt", + response.Secret + ); + await AlertService.Success( "API Key successfully created", - $"Copy the following secret. It wont be shown again. '{response.Secret}'" + "The API Key has been downloaded. Dont lose it, you cant view it anymore" ); await ToastService.Success("Successfully created api key"); diff --git a/Moonlight.Client/UI/Views/Admin/Api/Update.razor b/Moonlight.Client/UI/Views/Admin/Api/Update.razor index d12eec9e..322e1bb9 100644 --- a/Moonlight.Client/UI/Views/Admin/Api/Update.razor +++ b/Moonlight.Client/UI/Views/Admin/Api/Update.razor @@ -29,18 +29,6 @@ -
- -
- -
-
-
- -
- -
-
@@ -56,7 +44,11 @@ private async Task Load(LazyLoader _) { var detail = await ApiClient.GetJson($"api/admin/apikeys/{Id}"); - Request = Mapper.Map(detail); + + Request = new() + { + Description = detail.Description + }; } private async Task OnSubmit() diff --git a/Moonlight.Shared/Http/Requests/Admin/ApiKeys/UpdateApiKeyRequest.cs b/Moonlight.Shared/Http/Requests/Admin/ApiKeys/UpdateApiKeyRequest.cs index 3dfd206a..78bd77f9 100644 --- a/Moonlight.Shared/Http/Requests/Admin/ApiKeys/UpdateApiKeyRequest.cs +++ b/Moonlight.Shared/Http/Requests/Admin/ApiKeys/UpdateApiKeyRequest.cs @@ -6,10 +6,4 @@ public class UpdateApiKeyRequest { [Required(ErrorMessage = "You need to specify a description")] public string Description { get; set; } - - [Required(ErrorMessage = "You need to specify permissions for the api key")] - public string PermissionsJson { get; set; } = "[]"; - - [Required(ErrorMessage = "You need to specify an expire date")] - public DateTime ExpiresAt { get; set; } } \ No newline at end of file