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