Added permissions for container helper. Updated rebuild version selection to fetch the available versions from moonlights version api
This commit was merged in pull request #11.
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Moonlight.Api.Configuration;
|
||||
using Moonlight.Api.Mappers;
|
||||
using Moonlight.Api.Services;
|
||||
using Moonlight.Shared.Http.Events;
|
||||
using Moonlight.Shared;
|
||||
using Moonlight.Shared.Http.Requests.Admin.ContainerHelper;
|
||||
using Moonlight.Shared.Http.Responses.Admin;
|
||||
|
||||
@@ -12,6 +13,7 @@ namespace Moonlight.Api.Http.Controllers.Admin;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/admin/ch")]
|
||||
[Authorize(Policy = Permissions.System.Instance)]
|
||||
public class ContainerHelperController : Controller
|
||||
{
|
||||
private readonly ContainerHelperService ContainerHelperService;
|
||||
|
||||
@@ -28,6 +28,7 @@ public sealed class PermissionProvider : IPermissionProvider
|
||||
new Permission(Permissions.System.Info, "Info", "View system info"),
|
||||
new Permission(Permissions.System.Diagnose, "Diagnose", "Run diagnostics"),
|
||||
new Permission(Permissions.System.Versions, "Versions", "Look at the available versions"),
|
||||
new Permission(Permissions.System.Instance, "Instance", "Update the moonlight instance and add plugins"),
|
||||
]),
|
||||
new PermissionCategory("API Keys", typeof(KeyIcon), [
|
||||
new Permission(Permissions.ApiKeys.Create, "Create", "Create new API keys"),
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
<HeartPulseIcon/>
|
||||
Diagnose
|
||||
</TabsTrigger>
|
||||
<TabsTrigger Value="instance">
|
||||
<TabsTrigger Value="instance" Disabled="@(!InstanceResult.Succeeded || !VersionsResult.Succeeded)">
|
||||
<ContainerIcon/>
|
||||
Instance
|
||||
</TabsTrigger>
|
||||
@@ -61,9 +61,12 @@
|
||||
<Moonlight.Frontend.UI.Admin.Views.Sys.Themes.Index />
|
||||
</TabsContent>
|
||||
}
|
||||
@if (InstanceResult.Succeeded && VersionsResult.Succeeded)
|
||||
{
|
||||
<TabsContent Value="instance">
|
||||
<Instance />
|
||||
</TabsContent>
|
||||
}
|
||||
</Tabs>
|
||||
|
||||
@code
|
||||
@@ -76,6 +79,8 @@
|
||||
|
||||
private AuthorizationResult ApiKeyAccess;
|
||||
private AuthorizationResult ThemesAccess;
|
||||
private AuthorizationResult InstanceResult;
|
||||
private AuthorizationResult VersionsResult;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
@@ -83,6 +88,8 @@
|
||||
|
||||
ApiKeyAccess = await AuthorizationService.AuthorizeAsync(authState.User, Permissions.ApiKeys.View);
|
||||
ThemesAccess = await AuthorizationService.AuthorizeAsync(authState.User, Permissions.Themes.View);
|
||||
InstanceResult = await AuthorizationService.AuthorizeAsync(authState.User, Permissions.System.Versions);
|
||||
VersionsResult = await AuthorizationService.AuthorizeAsync(authState.User, Permissions.System.Instance);
|
||||
}
|
||||
|
||||
private void OnTabChanged(string name)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
@using System.Text.RegularExpressions
|
||||
@using LucideBlazor
|
||||
@using Moonlight.Frontend.UI.Admin.Modals
|
||||
@using Moonlight.Shared.Http.Responses.Admin
|
||||
@@ -38,10 +37,12 @@
|
||||
<SelectValue/>
|
||||
</SelectTrigger>
|
||||
<SelectContent ClassName="w-64">
|
||||
<SelectItem Value="v2.1">v2.1</SelectItem>
|
||||
<SelectItem Value="v2.1.1">v2.1.1</SelectItem>
|
||||
<SelectItem Value="feat/ContainerHelper">feat/ContainerHelper
|
||||
@foreach (var version in Versions)
|
||||
{
|
||||
<SelectItem Value="@version.Identifier">
|
||||
@version.Identifier
|
||||
</SelectItem>
|
||||
}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</FieldContent>
|
||||
@@ -118,9 +119,18 @@
|
||||
private string SelectedVersion = "v2.1";
|
||||
private bool NoBuildCache;
|
||||
|
||||
private VersionDto[] Versions;
|
||||
|
||||
private async Task LoadAsync(LazyLoader _)
|
||||
{
|
||||
StatusDto = (await HttpClient.GetFromJsonAsync<ContainerHelperStatusDto>("api/admin/ch/status"))!;
|
||||
|
||||
var currentVersion = await HttpClient.GetFromJsonAsync<VersionDto>("api/admin/versions/instance");
|
||||
|
||||
if (currentVersion != null)
|
||||
SelectedVersion = currentVersion.Identifier;
|
||||
|
||||
Versions = (await HttpClient.GetFromJsonAsync<VersionDto[]>("api/admin/versions"))!;
|
||||
}
|
||||
|
||||
private async Task ApplyAsync()
|
||||
@@ -144,6 +154,8 @@
|
||||
if (string.IsNullOrWhiteSpace(SelectedVersion))
|
||||
return;
|
||||
|
||||
var version = Versions.First(x => x.Identifier == SelectedVersion);
|
||||
|
||||
var shouldContinue = await ConfirmRiskyVersionAsync(
|
||||
"Moonlight Rebuild",
|
||||
"If you continue the moonlight instance will become unavailable during the rebuild process. This will impact users on this instance"
|
||||
@@ -152,7 +164,7 @@
|
||||
if (!shouldContinue)
|
||||
return;
|
||||
|
||||
if (!Regex.IsMatch(SelectedVersion, @"^v\d+(\.\d+)*b?$"))
|
||||
if (version.IsDevelopment)
|
||||
{
|
||||
shouldContinue = await ConfirmRiskyVersionAsync(
|
||||
"Development Version",
|
||||
@@ -161,7 +173,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SelectedVersion.EndsWith('b'))
|
||||
if (version.IsPreRelease)
|
||||
{
|
||||
shouldContinue = await ConfirmRiskyVersionAsync(
|
||||
"Beta / Pre-Release Version",
|
||||
|
||||
@@ -54,5 +54,6 @@ public static class Permissions
|
||||
public const string Info = $"{Prefix}{Section}.{nameof(Info)}";
|
||||
public const string Diagnose = $"{Prefix}{Section}.{nameof(Diagnose)}";
|
||||
public const string Versions = $"{Prefix}{Section}.{nameof(Versions)}";
|
||||
public const string Instance = $"{Prefix}{Section}.{nameof(Instance)}";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user