Merge pull request #32 from Moonlight-Panel/ServerDelete

Added server delete. Tweaked setting names
This commit is contained in:
Marcel Baumgartner 2023-04-04 16:05:39 +02:00 committed by GitHub
commit 3de1718a7b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 17 deletions

View file

@ -1,11 +1,9 @@
using Logging.Net;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Moonlight.App.Database;
using Moonlight.App.Database.Entities;
using Moonlight.App.Exceptions;
using Moonlight.App.Helpers;
using Moonlight.App.Models.Files;
using Moonlight.App.Models.Files.Accesses;
using Moonlight.App.Helpers.Files;
using Moonlight.App.Models.Misc;
using Moonlight.App.Models.Wings;
using Moonlight.App.Models.Wings.Requests;
@ -13,6 +11,7 @@ using Moonlight.App.Models.Wings.Resources;
using Moonlight.App.Repositories;
using Moonlight.App.Repositories.Servers;
using Moonlight.App.Services.LogServices;
using FileAccess = Moonlight.App.Helpers.Files.FileAccess;
namespace Moonlight.App.Services;
@ -30,7 +29,6 @@ public class ServerService
private readonly SecurityLogService SecurityLogService;
private readonly AuditLogService AuditLogService;
private readonly ErrorLogService ErrorLogService;
private readonly string AppUrl;
public ServerService(
ServerRepository serverRepository,
@ -58,8 +56,6 @@ public class ServerService
SecurityLogService = securityLogService;
AuditLogService = auditLogService;
ErrorLogService = errorLogService;
AppUrl = ConfigService.GetSection("Moonlight").GetValue<string>("AppUrl");
}
private Server EnsureNodeData(Server s)
@ -225,17 +221,17 @@ public class ServerService
return $"https://{server.Node.Fqdn}:{server.Node.HttpPort}/download/backup?token={token}";
}
public Task<IFileAccess> CreateFileAccess(Server s, User user) // We need the user to create the launch url
public Task<FileAccess> CreateFileAccess(Server s, User user) // We need the user to create the launch url
{
Server server = EnsureNodeData(s);
return Task.FromResult(
(IFileAccess)new WingsFileAccess(
(FileAccess)new WingsFileAccess(
WingsApiHelper,
server,
user,
WingsJwtHelper,
AppUrl
server,
ConfigService,
user
)
);
}
@ -383,4 +379,20 @@ public class ServerService
throw new Exception("User and owner id do not match");
}
}
public async Task Sync(Server s)
{
var server = EnsureNodeData(s);
await WingsApiHelper.Post(server.Node, $"api/servers/{server.Uuid}/sync", null);
}
public async Task Delete(Server s)
{
var server = EnsureNodeData(s);
await WingsApiHelper.Delete(server.Node, $"api/servers/{server.Uuid}", null);
ServerRepository.Delete(s);
}
}

View file

@ -1,5 +1,4 @@
@using PteroConsole.NET
@using Moonlight.App.Database.Entities
@using Moonlight.App.Database.Entities
@using Moonlight.Shared.Components.ServerControl.Settings
@using Microsoft.AspNetCore.Components.Rendering
@ -53,9 +52,11 @@
if(Tags.Contains("pythonfile"))
Settings.Add("Python file", typeof(PythonFileSetting));
Settings.Add("Server rename", typeof(ServerRenameSetting));
Settings.Add("Rename", typeof(ServerRenameSetting));
Settings.Add("Server reset", typeof(ServerResetSetting));
Settings.Add("Reset", typeof(ServerResetSetting));
Settings.Add("Delete", typeof(ServerDeleteSetting));
return Task.CompletedTask;
}

View file

@ -0,0 +1,29 @@
@using Moonlight.App.Database.Entities
@using Moonlight.App.Services
@using Moonlight.App.Services.Interop
@inject SmartTranslateService SmartTranslateService
@inject AlertService AlertService
@inject NavigationManager NavigationManager
@inject ServerService ServerService
<WButton Text="@(SmartTranslateService.Translate("Delete"))"
WorkingText="@(SmartTranslateService.Translate("Deleting"))"
CssClasses="btn-danger"
OnClick="OnClick">
</WButton>
@code
{
[CascadingParameter]
public Server CurrentServer { get; set; }
private async Task OnClick()
{
if (await AlertService.ConfirmMath())
{
await ServerService.Delete(CurrentServer);
NavigationManager.NavigateTo("/servers", true);
}
}
}

View file

@ -8,6 +8,7 @@
@inject SmartTranslateService SmartTranslateService
@inject ServerRepository ServerRepository
@inject ServerService ServerService
@inject ImageRepository ImageRepository
<OnlyAdmin>
@ -197,7 +198,8 @@
private async Task Save()
{
ServerRepository.Update(Server);
ServerRepository.Update(Server!);
//await ServerService.Sync(Server!); I dont know if we need this, because wings should resync the data while restarting anyway
await LazyLoader.Reload();
}