From 7f51bfd1db7ff84ba16df9dcc81d6e8a0abef86e Mon Sep 17 00:00:00 2001 From: Marcel Baumgartner Date: Fri, 21 Apr 2023 16:38:06 +0200 Subject: [PATCH] Removed old support system --- Moonlight/App/Database/DataContext.cs | 3 +- .../App/Database/Entities/SupportMessage.cs | 17 - ...556_RemovedOldSupportChatModel.Designer.cs | 1028 +++++++++++++++++ ...230421143556_RemovedOldSupportChatModel.cs | 67 ++ .../Migrations/DataContextModelSnapshot.cs | 59 - .../Repositories/SupportMessageRepository.cs | 44 - .../Services/Support/SupportAdminService.cs | 132 --- .../Services/Support/SupportClientService.cs | 124 -- .../Services/Support/SupportServerService.cs | 138 --- Moonlight/Program.cs | 12 +- Moonlight/Shared/Layouts/MainLayout.razor | 3 +- 11 files changed, 1099 insertions(+), 528 deletions(-) delete mode 100644 Moonlight/App/Database/Entities/SupportMessage.cs create mode 100644 Moonlight/App/Database/Migrations/20230421143556_RemovedOldSupportChatModel.Designer.cs create mode 100644 Moonlight/App/Database/Migrations/20230421143556_RemovedOldSupportChatModel.cs delete mode 100644 Moonlight/App/Repositories/SupportMessageRepository.cs delete mode 100644 Moonlight/App/Services/Support/SupportAdminService.cs delete mode 100644 Moonlight/App/Services/Support/SupportClientService.cs delete mode 100644 Moonlight/App/Services/Support/SupportServerService.cs diff --git a/Moonlight/App/Database/DataContext.cs b/Moonlight/App/Database/DataContext.cs index 3a352938..9c92b5b8 100644 --- a/Moonlight/App/Database/DataContext.cs +++ b/Moonlight/App/Database/DataContext.cs @@ -30,8 +30,7 @@ public class DataContext : DbContext public DbSet AuditLog { get; set; } public DbSet ErrorLog { get; set; } public DbSet SecurityLog { get; set; } - public DbSet SupportMessages { get; set; } - + public DbSet SharedDomains { get; set; } public DbSet Domains { get; set; } public DbSet Revokes { get; set; } diff --git a/Moonlight/App/Database/Entities/SupportMessage.cs b/Moonlight/App/Database/Entities/SupportMessage.cs deleted file mode 100644 index df1019d4..00000000 --- a/Moonlight/App/Database/Entities/SupportMessage.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Moonlight.App.Models.Misc; - -namespace Moonlight.App.Database.Entities; - -public class SupportMessage -{ - public int Id { get; set; } - public string Message { get; set; } = ""; - public User? Sender { get; set; } = null; - public User? Recipient { get; set; } = null; - public DateTime CreatedAt { get; set; } = DateTime.UtcNow; - public bool IsQuestion { get; set; } = false; - public QuestionType Type { get; set; } - public string Answer { get; set; } = ""; - public bool IsSystem { get; set; } = false; - public bool IsSupport { get; set; } = false; -} \ No newline at end of file diff --git a/Moonlight/App/Database/Migrations/20230421143556_RemovedOldSupportChatModel.Designer.cs b/Moonlight/App/Database/Migrations/20230421143556_RemovedOldSupportChatModel.Designer.cs new file mode 100644 index 00000000..d34006e9 --- /dev/null +++ b/Moonlight/App/Database/Migrations/20230421143556_RemovedOldSupportChatModel.Designer.cs @@ -0,0 +1,1028 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Moonlight.App.Database; + +#nullable disable + +namespace Moonlight.App.Database.Migrations +{ + [DbContext(typeof(DataContext))] + [Migration("20230421143556_RemovedOldSupportChatModel")] + partial class RemovedOldSupportChatModel + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("Moonlight.App.Database.Entities.CloudPanel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("ApiKey") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ApiUrl") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Host") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("CloudPanels"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.DdosAttack", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("Data") + .HasColumnType("bigint"); + + b.Property("Ip") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("NodeId") + .HasColumnType("int"); + + b.Property("Ongoing") + .HasColumnType("tinyint(1)"); + + b.HasKey("Id"); + + b.HasIndex("NodeId"); + + b.ToTable("DdosAttacks"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.DockerImage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Default") + .HasColumnType("tinyint(1)"); + + b.Property("ImageId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.HasIndex("ImageId"); + + b.ToTable("DockerImages"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.Domain", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("OwnerId") + .HasColumnType("int"); + + b.Property("SharedDomainId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("OwnerId"); + + b.HasIndex("SharedDomainId"); + + b.ToTable("Domains"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.Image", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Allocations") + .HasColumnType("int"); + + b.Property("ConfigFiles") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Description") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("InstallDockerImage") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("InstallEntrypoint") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("InstallScript") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Startup") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("StartupDetection") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("StopCommand") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("TagsJson") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Uuid") + .HasColumnType("char(36)"); + + b.HasKey("Id"); + + b.ToTable("Images"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.ImageVariable", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("DefaultValue") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ImageId") + .HasColumnType("int"); + + b.Property("Key") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.HasIndex("ImageId"); + + b.ToTable("ImageVariables"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.LoadingMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Message") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("LoadingMessages"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.LogsEntries.AuditLogEntry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("Ip") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("JsonData") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("System") + .HasColumnType("tinyint(1)"); + + b.Property("Type") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("AuditLog"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.LogsEntries.ErrorLogEntry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Class") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("Ip") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("JsonData") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Stacktrace") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("System") + .HasColumnType("tinyint(1)"); + + b.HasKey("Id"); + + b.ToTable("ErrorLog"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.LogsEntries.SecurityLogEntry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("Ip") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("JsonData") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("System") + .HasColumnType("tinyint(1)"); + + b.Property("Type") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("SecurityLog"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.MySqlDatabase", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Password") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("WebSpaceId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("WebSpaceId"); + + b.ToTable("Databases"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.NewsEntry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Date") + .HasColumnType("datetime(6)"); + + b.Property("Markdown") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Title") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("NewsEntries"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.Node", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Fqdn") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("HttpPort") + .HasColumnType("int"); + + b.Property("MoonlightDaemonPort") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("SftpPort") + .HasColumnType("int"); + + b.Property("Ssl") + .HasColumnType("tinyint(1)"); + + b.Property("Token") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("TokenId") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("Nodes"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.NodeAllocation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("NodeId") + .HasColumnType("int"); + + b.Property("Port") + .HasColumnType("int"); + + b.Property("ServerId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("NodeId"); + + b.HasIndex("ServerId"); + + b.ToTable("NodeAllocations"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.Notification.NotificationAction", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Action") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("NotificationClientId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("NotificationClientId"); + + b.ToTable("NotificationActions"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.Notification.NotificationClient", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("NotificationClients"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.Revoke", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Identifier") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("Revokes"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.Server", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Cpu") + .HasColumnType("int"); + + b.Property("Disk") + .HasColumnType("bigint"); + + b.Property("DockerImageIndex") + .HasColumnType("int"); + + b.Property("ImageId") + .HasColumnType("int"); + + b.Property("Installing") + .HasColumnType("tinyint(1)"); + + b.Property("IsCleanupException") + .HasColumnType("tinyint(1)"); + + b.Property("MainAllocationId") + .HasColumnType("int"); + + b.Property("Memory") + .HasColumnType("bigint"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("NodeId") + .HasColumnType("int"); + + b.Property("OverrideStartup") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("OwnerId") + .HasColumnType("int"); + + b.Property("Suspended") + .HasColumnType("tinyint(1)"); + + b.Property("Uuid") + .HasColumnType("char(36)"); + + b.HasKey("Id"); + + b.HasIndex("ImageId"); + + b.HasIndex("MainAllocationId"); + + b.HasIndex("NodeId"); + + b.HasIndex("OwnerId"); + + b.ToTable("Servers"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.ServerBackup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Bytes") + .HasColumnType("bigint"); + + b.Property("Created") + .HasColumnType("tinyint(1)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ServerId") + .HasColumnType("int"); + + b.Property("Uuid") + .HasColumnType("char(36)"); + + b.HasKey("Id"); + + b.HasIndex("ServerId"); + + b.ToTable("ServerBackups"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.ServerVariable", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Key") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ServerId") + .HasColumnType("int"); + + b.Property("Value") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.HasIndex("ServerId"); + + b.ToTable("ServerVariables"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.SharedDomain", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("CloudflareId") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("SharedDomains"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.StatisticsData", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Chart") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Date") + .HasColumnType("datetime(6)"); + + b.Property("Value") + .HasColumnType("double"); + + b.HasKey("Id"); + + b.ToTable("Statistics"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.Subscription", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Description") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("LimitsJson") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("Subscriptions"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.SupportChatMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Answer") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Attachment") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Content") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("IsQuestion") + .HasColumnType("tinyint(1)"); + + b.Property("QuestionType") + .HasColumnType("int"); + + b.Property("RecipientId") + .HasColumnType("int"); + + b.Property("SenderId") + .HasColumnType("int"); + + b.Property("UpdatedAt") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("RecipientId"); + + b.HasIndex("SenderId"); + + b.ToTable("SupportChatMessages"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Address") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Admin") + .HasColumnType("tinyint(1)"); + + b.Property("City") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Country") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("CurrentSubscriptionId") + .HasColumnType("int"); + + b.Property("DiscordId") + .HasColumnType("bigint unsigned"); + + b.Property("Email") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Password") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("State") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("SubscriptionDuration") + .HasColumnType("int"); + + b.Property("SubscriptionSince") + .HasColumnType("datetime(6)"); + + b.Property("SupportPending") + .HasColumnType("tinyint(1)"); + + b.Property("TokenValidTime") + .HasColumnType("datetime(6)"); + + b.Property("TotpEnabled") + .HasColumnType("tinyint(1)"); + + b.Property("TotpSecret") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("UpdatedAt") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("CurrentSubscriptionId"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.WebSpace", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("CloudPanelId") + .HasColumnType("int"); + + b.Property("Domain") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("OwnerId") + .HasColumnType("int"); + + b.Property("Password") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("VHostTemplate") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.HasIndex("CloudPanelId"); + + b.HasIndex("OwnerId"); + + b.ToTable("WebSpaces"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.DdosAttack", b => + { + b.HasOne("Moonlight.App.Database.Entities.Node", "Node") + .WithMany() + .HasForeignKey("NodeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Node"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.DockerImage", b => + { + b.HasOne("Moonlight.App.Database.Entities.Image", null) + .WithMany("DockerImages") + .HasForeignKey("ImageId"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.Domain", b => + { + b.HasOne("Moonlight.App.Database.Entities.User", "Owner") + .WithMany() + .HasForeignKey("OwnerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Moonlight.App.Database.Entities.SharedDomain", "SharedDomain") + .WithMany() + .HasForeignKey("SharedDomainId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Owner"); + + b.Navigation("SharedDomain"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.ImageVariable", b => + { + b.HasOne("Moonlight.App.Database.Entities.Image", null) + .WithMany("Variables") + .HasForeignKey("ImageId"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.MySqlDatabase", b => + { + b.HasOne("Moonlight.App.Database.Entities.WebSpace", "WebSpace") + .WithMany("Databases") + .HasForeignKey("WebSpaceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("WebSpace"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.NodeAllocation", b => + { + b.HasOne("Moonlight.App.Database.Entities.Node", null) + .WithMany("Allocations") + .HasForeignKey("NodeId"); + + b.HasOne("Moonlight.App.Database.Entities.Server", null) + .WithMany("Allocations") + .HasForeignKey("ServerId"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.Notification.NotificationAction", b => + { + b.HasOne("Moonlight.App.Database.Entities.Notification.NotificationClient", "NotificationClient") + .WithMany() + .HasForeignKey("NotificationClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("NotificationClient"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.Notification.NotificationClient", b => + { + b.HasOne("Moonlight.App.Database.Entities.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.Server", b => + { + b.HasOne("Moonlight.App.Database.Entities.Image", "Image") + .WithMany() + .HasForeignKey("ImageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Moonlight.App.Database.Entities.NodeAllocation", "MainAllocation") + .WithMany() + .HasForeignKey("MainAllocationId"); + + b.HasOne("Moonlight.App.Database.Entities.Node", "Node") + .WithMany() + .HasForeignKey("NodeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Moonlight.App.Database.Entities.User", "Owner") + .WithMany() + .HasForeignKey("OwnerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Image"); + + b.Navigation("MainAllocation"); + + b.Navigation("Node"); + + b.Navigation("Owner"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.ServerBackup", b => + { + b.HasOne("Moonlight.App.Database.Entities.Server", null) + .WithMany("Backups") + .HasForeignKey("ServerId"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.ServerVariable", b => + { + b.HasOne("Moonlight.App.Database.Entities.Server", null) + .WithMany("Variables") + .HasForeignKey("ServerId"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.SupportChatMessage", b => + { + b.HasOne("Moonlight.App.Database.Entities.User", "Recipient") + .WithMany() + .HasForeignKey("RecipientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Moonlight.App.Database.Entities.User", "Sender") + .WithMany() + .HasForeignKey("SenderId"); + + b.Navigation("Recipient"); + + b.Navigation("Sender"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.User", b => + { + b.HasOne("Moonlight.App.Database.Entities.Subscription", "CurrentSubscription") + .WithMany() + .HasForeignKey("CurrentSubscriptionId"); + + b.Navigation("CurrentSubscription"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.WebSpace", b => + { + b.HasOne("Moonlight.App.Database.Entities.CloudPanel", "CloudPanel") + .WithMany() + .HasForeignKey("CloudPanelId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Moonlight.App.Database.Entities.User", "Owner") + .WithMany() + .HasForeignKey("OwnerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("CloudPanel"); + + b.Navigation("Owner"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.Image", b => + { + b.Navigation("DockerImages"); + + b.Navigation("Variables"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.Node", b => + { + b.Navigation("Allocations"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.Server", b => + { + b.Navigation("Allocations"); + + b.Navigation("Backups"); + + b.Navigation("Variables"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.WebSpace", b => + { + b.Navigation("Databases"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Moonlight/App/Database/Migrations/20230421143556_RemovedOldSupportChatModel.cs b/Moonlight/App/Database/Migrations/20230421143556_RemovedOldSupportChatModel.cs new file mode 100644 index 00000000..c89742ee --- /dev/null +++ b/Moonlight/App/Database/Migrations/20230421143556_RemovedOldSupportChatModel.cs @@ -0,0 +1,67 @@ +using System; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Moonlight.App.Database.Migrations +{ + /// + public partial class RemovedOldSupportChatModel : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "SupportMessages"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "SupportMessages", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + RecipientId = table.Column(type: "int", nullable: true), + SenderId = table.Column(type: "int", nullable: true), + Answer = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + CreatedAt = table.Column(type: "datetime(6)", nullable: false), + IsQuestion = table.Column(type: "tinyint(1)", nullable: false), + IsSupport = table.Column(type: "tinyint(1)", nullable: false), + IsSystem = table.Column(type: "tinyint(1)", nullable: false), + Message = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Type = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SupportMessages", x => x.Id); + table.ForeignKey( + name: "FK_SupportMessages_Users_RecipientId", + column: x => x.RecipientId, + principalTable: "Users", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_SupportMessages_Users_SenderId", + column: x => x.SenderId, + principalTable: "Users", + principalColumn: "Id"); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateIndex( + name: "IX_SupportMessages_RecipientId", + table: "SupportMessages", + column: "RecipientId"); + + migrationBuilder.CreateIndex( + name: "IX_SupportMessages_SenderId", + table: "SupportMessages", + column: "SenderId"); + } + } +} diff --git a/Moonlight/App/Database/Migrations/DataContextModelSnapshot.cs b/Moonlight/App/Database/Migrations/DataContextModelSnapshot.cs index 26b48d2e..f6f8d75a 100644 --- a/Moonlight/App/Database/Migrations/DataContextModelSnapshot.cs +++ b/Moonlight/App/Database/Migrations/DataContextModelSnapshot.cs @@ -695,50 +695,6 @@ namespace Moonlight.App.Database.Migrations b.ToTable("SupportChatMessages"); }); - modelBuilder.Entity("Moonlight.App.Database.Entities.SupportMessage", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("Answer") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("CreatedAt") - .HasColumnType("datetime(6)"); - - b.Property("IsQuestion") - .HasColumnType("tinyint(1)"); - - b.Property("IsSupport") - .HasColumnType("tinyint(1)"); - - b.Property("IsSystem") - .HasColumnType("tinyint(1)"); - - b.Property("Message") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("RecipientId") - .HasColumnType("int"); - - b.Property("SenderId") - .HasColumnType("int"); - - b.Property("Type") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("RecipientId"); - - b.HasIndex("SenderId"); - - b.ToTable("SupportMessages"); - }); - modelBuilder.Entity("Moonlight.App.Database.Entities.User", b => { b.Property("Id") @@ -1010,21 +966,6 @@ namespace Moonlight.App.Database.Migrations b.Navigation("Sender"); }); - modelBuilder.Entity("Moonlight.App.Database.Entities.SupportMessage", b => - { - b.HasOne("Moonlight.App.Database.Entities.User", "Recipient") - .WithMany() - .HasForeignKey("RecipientId"); - - b.HasOne("Moonlight.App.Database.Entities.User", "Sender") - .WithMany() - .HasForeignKey("SenderId"); - - b.Navigation("Recipient"); - - b.Navigation("Sender"); - }); - modelBuilder.Entity("Moonlight.App.Database.Entities.User", b => { b.HasOne("Moonlight.App.Database.Entities.Subscription", "CurrentSubscription") diff --git a/Moonlight/App/Repositories/SupportMessageRepository.cs b/Moonlight/App/Repositories/SupportMessageRepository.cs deleted file mode 100644 index 1f6ec2e7..00000000 --- a/Moonlight/App/Repositories/SupportMessageRepository.cs +++ /dev/null @@ -1,44 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Moonlight.App.Database; -using Moonlight.App.Database.Entities; - -namespace Moonlight.App.Repositories; - -public class SupportMessageRepository : IDisposable -{ - private readonly DataContext DataContext; - - public SupportMessageRepository(DataContext dataContext) - { - DataContext = dataContext; - } - - public DbSet Get() - { - return DataContext.SupportMessages; - } - - public SupportMessage Add(SupportMessage message) - { - var x = DataContext.SupportMessages.Add(message); - DataContext.SaveChanges(); - return x.Entity; - } - - public void Update(SupportMessage message) - { - DataContext.SupportMessages.Update(message); - DataContext.SaveChanges(); - } - - public void Delete(SupportMessage message) - { - DataContext.SupportMessages.Remove(message); - DataContext.SaveChanges(); - } - - public void Dispose() - { - DataContext.Dispose(); - } -} \ No newline at end of file diff --git a/Moonlight/App/Services/Support/SupportAdminService.cs b/Moonlight/App/Services/Support/SupportAdminService.cs deleted file mode 100644 index 2dabdef1..00000000 --- a/Moonlight/App/Services/Support/SupportAdminService.cs +++ /dev/null @@ -1,132 +0,0 @@ -using Moonlight.App.Database.Entities; -using Moonlight.App.Services.Sessions; - -namespace Moonlight.App.Services.Support; - -public class SupportAdminService -{ - private readonly SupportServerService SupportServerService; - private readonly IdentityService IdentityService; - private readonly MessageService MessageService; - - public EventHandler OnNewMessage; - - public EventHandler OnUpdateTyping; - private List TypingUsers = new(); - - private User Self; - private User Recipient; - - public SupportAdminService( - SupportServerService supportServerService, - IdentityService identityService, - MessageService messageService) - { - SupportServerService = supportServerService; - IdentityService = identityService; - MessageService = messageService; - } - - public async Task Start(User user) - { - Self = (await IdentityService.Get())!; - Recipient = user; - - MessageService.Subscribe( - $"support.{Recipient.Id}.message", - this, - message => - { - OnNewMessage?.Invoke(this, message); - - return Task.CompletedTask; - }); - - MessageService.Subscribe( - $"support.{Self.Id}.typing", - this, - user => - { - HandleTyping(user); - return Task.CompletedTask; - }); - } - - #region Typing - - private void HandleTyping(User user) - { - var name = $"{user.FirstName} {user.LastName}"; - - lock (TypingUsers) - { - if (!TypingUsers.Contains(name)) - { - TypingUsers.Add(name); - OnUpdateTyping!.Invoke(this, null!); - - Task.Run(async () => - { - await Task.Delay(TimeSpan.FromSeconds(5)); - - if (TypingUsers.Contains(name)) - { - TypingUsers.Remove(name); - OnUpdateTyping!.Invoke(this, null!); - } - }); - } - } - } - - public string[] GetTypingUsers() - { - lock (TypingUsers) - { - return TypingUsers.ToArray(); - } - } - - public Task TriggerTyping() - { - Task.Run(async () => - { - await MessageService.Emit($"support.{Recipient.Id}.admintyping", Self); - }); - - return Task.CompletedTask; - } - - #endregion - - public async Task GetMessages() - { - return await SupportServerService.GetMessages(Recipient); - } - - public async Task SendMessage(string content) - { - var message = new SupportMessage() - { - Message = content - }; - - await SupportServerService.SendMessage( - Recipient, - message, - Self, - true - ); - } - - public async Task Close() - { - await SupportServerService.Close(Recipient); - } - - public void Dispose() - { - MessageService.Unsubscribe($"support.{Recipient.Id}.message", this); - MessageService.Unsubscribe($"support.{Recipient.Id}.typing", this); - } -} \ No newline at end of file diff --git a/Moonlight/App/Services/Support/SupportClientService.cs b/Moonlight/App/Services/Support/SupportClientService.cs deleted file mode 100644 index 5b4f54dc..00000000 --- a/Moonlight/App/Services/Support/SupportClientService.cs +++ /dev/null @@ -1,124 +0,0 @@ -using Moonlight.App.Database.Entities; -using Moonlight.App.Services.Sessions; - -namespace Moonlight.App.Services.Support; - -public class SupportClientService : IDisposable -{ - private readonly SupportServerService SupportServerService; - private readonly IdentityService IdentityService; - private readonly MessageService MessageService; - - public EventHandler OnNewMessage; - - public EventHandler OnUpdateTyping; - private List TypingUsers = new(); - - private User Self; - - public SupportClientService( - SupportServerService supportServerService, - IdentityService identityService, - MessageService messageService) - { - SupportServerService = supportServerService; - IdentityService = identityService; - MessageService = messageService; - } - - public async Task Start() - { - Self = (await IdentityService.Get())!; - - MessageService.Subscribe( - $"support.{Self.Id}.message", - this, - message => - { - OnNewMessage?.Invoke(this, message); - - return Task.CompletedTask; - }); - - MessageService.Subscribe( - $"support.{Self.Id}.admintyping", - this, - user => - { - HandleTyping(user); - return Task.CompletedTask; - }); - } - - #region Typing - - private void HandleTyping(User user) - { - var name = $"{user.FirstName} {user.LastName}"; - - lock (TypingUsers) - { - if (!TypingUsers.Contains(name)) - { - TypingUsers.Add(name); - OnUpdateTyping!.Invoke(this, null!); - - Task.Run(async () => - { - await Task.Delay(TimeSpan.FromSeconds(5)); - - if (TypingUsers.Contains(name)) - { - TypingUsers.Remove(name); - OnUpdateTyping!.Invoke(this, null!); - } - }); - } - } - } - - public string[] GetTypingUsers() - { - lock (TypingUsers) - { - return TypingUsers.ToArray(); - } - } - - public Task TriggerTyping() - { - Task.Run(async () => - { - await MessageService.Emit($"support.{Self.Id}.typing", Self); - }); - - return Task.CompletedTask; - } - - #endregion - - public async Task GetMessages() - { - return await SupportServerService.GetMessages(Self); - } - - public async Task SendMessage(string content) - { - var message = new SupportMessage() - { - Message = content - }; - - await SupportServerService.SendMessage( - Self, - message, - Self - ); - } - - public void Dispose() - { - MessageService.Unsubscribe($"support.{Self.Id}.message", this); - MessageService.Unsubscribe($"support.{Self.Id}.admintyping", this); - } -} \ No newline at end of file diff --git a/Moonlight/App/Services/Support/SupportServerService.cs b/Moonlight/App/Services/Support/SupportServerService.cs deleted file mode 100644 index f2b22b7f..00000000 --- a/Moonlight/App/Services/Support/SupportServerService.cs +++ /dev/null @@ -1,138 +0,0 @@ -using Logging.Net; -using Microsoft.EntityFrameworkCore; -using Moonlight.App.Database.Entities; -using Moonlight.App.Repositories; - -namespace Moonlight.App.Services.Support; - -public class SupportServerService : IDisposable -{ - private SupportMessageRepository SupportMessageRepository; - private MessageService MessageService; - private UserRepository UserRepository; - private readonly IServiceScopeFactory ServiceScopeFactory; - private IServiceScope ServiceScope; - - public SupportServerService(IServiceScopeFactory serviceScopeFactory) - { - ServiceScopeFactory = serviceScopeFactory; - - Task.Run(Run); - } - - public async Task SendMessage(User r, SupportMessage message, User s, bool isSupport = false) - { - var recipient = UserRepository.Get().First(x => x.Id == r.Id); - var sender = UserRepository.Get().First(x => x.Id == s.Id); - - Task.Run(async () => - { - try - { - message.CreatedAt = DateTime.UtcNow; - message.Sender = sender; - message.Recipient = recipient; - message.IsSupport = isSupport; - - SupportMessageRepository.Add(message); - - await MessageService.Emit($"support.{recipient.Id}.message", message); - - if (!recipient.SupportPending) - { - recipient.SupportPending = true; - UserRepository.Update(recipient); - - if (!message.IsSupport) - { - var systemMessage = new SupportMessage() - { - Recipient = recipient, - Sender = null, - IsSystem = true, - Message = "The support team has been notified. Please be patient" - }; - - SupportMessageRepository.Add(systemMessage); - - await MessageService.Emit($"support.{recipient.Id}.message", systemMessage); - } - - await MessageService.Emit($"support.new", recipient); - - Logger.Info("Support ticket created: " + recipient.Id); - //TODO: Ping or so - } - } - catch (Exception e) - { - Logger.Error("Error sending message"); - Logger.Error(e); - } - }); - } - - public async Task Close(User user) - { - var recipient = UserRepository.Get().First(x => x.Id == user.Id); - - recipient.SupportPending = false; - UserRepository.Update(recipient); - - var systemMessage = new SupportMessage() - { - Recipient = recipient, - Sender = null, - IsSystem = true, - Message = "The ticket is now closed. Type a message to open it again" - }; - - SupportMessageRepository.Add(systemMessage); - - await MessageService.Emit($"support.{recipient.Id}.message", systemMessage); - await MessageService.Emit($"support.close", recipient); - } - - public Task GetMessages(User r) - { - var recipient = UserRepository.Get().First(x => x.Id == r.Id); - - var messages = SupportMessageRepository - .Get() - .Include(x => x.Recipient) - .Include(x => x.Sender) - .Where(x => x.Recipient.Id == recipient.Id) - .AsEnumerable() - .TakeLast(50) - .OrderBy(x => x.Id) - .ToArray(); - - return Task.FromResult(messages); - } - - private Task Run() - { - ServiceScope = ServiceScopeFactory.CreateScope(); - - SupportMessageRepository = ServiceScope - .ServiceProvider - .GetRequiredService(); - - MessageService = ServiceScope - .ServiceProvider - .GetRequiredService(); - - UserRepository = ServiceScope - .ServiceProvider - .GetRequiredService(); - - return Task.CompletedTask; - } - - public void Dispose() - { - SupportMessageRepository.Dispose(); - UserRepository.Dispose(); - ServiceScope.Dispose(); - } -} \ No newline at end of file diff --git a/Moonlight/Program.cs b/Moonlight/Program.cs index 77c21a0e..c6eb1710 100644 --- a/Moonlight/Program.cs +++ b/Moonlight/Program.cs @@ -19,7 +19,6 @@ using Moonlight.App.Services.Notifications; using Moonlight.App.Services.OAuth2; using Moonlight.App.Services.Sessions; using Moonlight.App.Services.Statistics; -using Moonlight.App.Services.Support; using Moonlight.App.Services.SupportChat; namespace Moonlight @@ -63,7 +62,6 @@ namespace Moonlight builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); - builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); @@ -125,11 +123,6 @@ namespace Moonlight builder.Services.AddScoped(); builder.Services.AddSingleton(); - // Support TODO: Remove - builder.Services.AddSingleton(); - builder.Services.AddScoped(); - builder.Services.AddScoped(); - // Support chat builder.Services.AddSingleton(); builder.Services.AddScoped(); @@ -175,10 +168,7 @@ namespace Moonlight app.MapBlazorHub(); app.MapFallbackToPage("/_Host"); - - // Support service - var supportServerService = app.Services.GetRequiredService(); - + // AutoStart services _ = app.Services.GetRequiredService(); _ = app.Services.GetRequiredService(); diff --git a/Moonlight/Shared/Layouts/MainLayout.razor b/Moonlight/Shared/Layouts/MainLayout.razor index cc7d02d1..7ca0314b 100644 --- a/Moonlight/Shared/Layouts/MainLayout.razor +++ b/Moonlight/Shared/Layouts/MainLayout.razor @@ -164,6 +164,7 @@ NavigationManager.LocationChanged += (sender, args) => { SessionService.Refresh(); }; + /* MessageService.Subscribe( $"support.{User.Id}.message", this, @@ -173,7 +174,7 @@ { await ToastService.Info($"Support: {message.Message}"); } - }); + });*/ RunDelayedMenu(0); RunDelayedMenu(1);