From daf7c1deea4fcfefe557fd397c6d732674e485b6 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 13 Aug 2018 14:51:40 -0400 Subject: [PATCH] Rename ChatSettings to ChatBot among other things --- .../Models/{ChatSettings.cs => ChatBot.cs} | 6 +-- .../Models/InstanceUser.cs | 4 +- .../Internal/{ChatSettings.cs => ChatBot.cs} | 12 ++--- ...ChatSettingsRights.cs => ChatBotRights.cs} | 22 ++++---- .../Rights/RightsHelper.cs | 2 +- src/Tgstation.Server.Api/Rights/RightsType.cs | 4 +- .../Components/IByondClient.cs | 4 +- ...atSettingsClient.cs => IChatBotsClient.cs} | 30 +++++------ .../Components/IConfigurationClient.cs | 26 ++------- .../Components/IDreamDaemonClient.cs | 9 ++-- .../Components/IDreamMakerClient.cs | 4 +- .../Components/IInstanceClient.cs | 4 +- .../Components/IInstanceUserClient.cs | 27 ++++++---- .../Components/IRepositoryClient.cs | 3 +- .../Components/Chat/Chat.cs | 22 ++++---- .../Components/Chat/ChatFactory.cs | 2 +- .../Components/Chat/IChat.cs | 16 +++--- .../Components/Chat/IChatFactory.cs | 4 +- .../Components/Chat/IProviderFactory.cs | 4 +- .../Components/Chat/ProviderFactory.cs | 2 +- .../Controllers/ChatController.cs | 54 +++++++++---------- .../Controllers/InstanceController.cs | 2 +- .../Controllers/InstanceUserController.cs | 4 +- .../Controllers/TgsAuthorizeAttribute.cs | 4 +- .../Models/{ChatSettings.cs => ChatBot.cs} | 7 ++- .../Models/ChatChannel.cs | 6 +-- .../Models/DatabaseContext.cs | 4 +- .../Models/IDatabaseContext.cs | 4 +- src/Tgstation.Server.Host/Models/Instance.cs | 4 +- .../Models/InstanceUser.cs | 4 +- 30 files changed, 143 insertions(+), 157 deletions(-) rename src/Tgstation.Server.Api/Models/{ChatSettings.cs => ChatBot.cs} (84%) rename src/Tgstation.Server.Api/Models/Internal/{ChatSettings.cs => ChatBot.cs} (64%) rename src/Tgstation.Server.Api/Rights/{ChatSettingsRights.cs => ChatBotRights.cs} (50%) rename src/Tgstation.Server.Client/Components/{IChatSettingsClient.cs => IChatBotsClient.cs} (53%) rename src/Tgstation.Server.Host/Models/{ChatSettings.cs => ChatBot.cs} (72%) diff --git a/src/Tgstation.Server.Api/Models/ChatSettings.cs b/src/Tgstation.Server.Api/Models/ChatBot.cs similarity index 84% rename from src/Tgstation.Server.Api/Models/ChatSettings.cs rename to src/Tgstation.Server.Api/Models/ChatBot.cs index f613a4484a..7c1ee41dd0 100644 --- a/src/Tgstation.Server.Api/Models/ChatSettings.cs +++ b/src/Tgstation.Server.Api/Models/ChatBot.cs @@ -6,16 +6,16 @@ using Tgstation.Server.Api.Rights; namespace Tgstation.Server.Api.Models { /// - public sealed class ChatSettings : Internal.ChatSettings + public sealed class ChatBot : Internal.ChatBot { /// /// Channels the Discord bot should listen/announce in /// - [Permissions(WriteRight = ChatSettingsRights.WriteChannels)] + [Permissions(WriteRight = ChatBotRights.WriteChannels)] public List Channels { get; set; } /// - /// Validates are correct for the + /// Validates are correct for the /// /// public bool ValidateProviderChannelTypes() diff --git a/src/Tgstation.Server.Api/Models/InstanceUser.cs b/src/Tgstation.Server.Api/Models/InstanceUser.cs index 68bd323b81..14727e9812 100644 --- a/src/Tgstation.Server.Api/Models/InstanceUser.cs +++ b/src/Tgstation.Server.Api/Models/InstanceUser.cs @@ -47,10 +47,10 @@ namespace Tgstation.Server.Api.Models public RepositoryRights? RepositoryRights { get; set; } /// - /// The of the + /// The of the /// [Required] - public ChatSettingsRights? ChatSettingsRights { get; set; } + public ChatBotRights? ChatBotRights { get; set; } /// /// The of the diff --git a/src/Tgstation.Server.Api/Models/Internal/ChatSettings.cs b/src/Tgstation.Server.Api/Models/Internal/ChatBot.cs similarity index 64% rename from src/Tgstation.Server.Api/Models/Internal/ChatSettings.cs rename to src/Tgstation.Server.Api/Models/Internal/ChatBot.cs index 2a23052ad8..87e7083b64 100644 --- a/src/Tgstation.Server.Api/Models/Internal/ChatSettings.cs +++ b/src/Tgstation.Server.Api/Models/Internal/ChatBot.cs @@ -6,8 +6,8 @@ namespace Tgstation.Server.Api.Models.Internal /// /// Manage the server chat bots /// - [Model(RightsType.ChatSettings, RequiresInstance = true, CanList = true, CanCrud = true, ReadRight = ChatSettingsRights.Read)] - public class ChatSettings + [Model(RightsType.ChatBots, RequiresInstance = true, CanList = true, CanCrud = true, ReadRight = ChatBotRights.Read)] + public class ChatBot { /// /// The settings id @@ -18,26 +18,26 @@ namespace Tgstation.Server.Api.Models.Internal /// /// The name of the connection /// - [Permissions(WriteRight = ChatSettingsRights.WriteName)] + [Permissions(WriteRight = ChatBotRights.WriteName)] [Required] public string Name { get; set; } /// /// If the connection is enabled /// - [Permissions(WriteRight = ChatSettingsRights.WriteEnabled)] + [Permissions(WriteRight = ChatBotRights.WriteEnabled)] public bool? Enabled { get; set; } /// /// The used for the connection /// - [Permissions(WriteRight = ChatSettingsRights.WriteProvider)] + [Permissions(WriteRight = ChatBotRights.WriteProvider)] public ChatProvider? Provider { get; set; } /// /// The information used to connect to the /// - [Permissions(ReadRight = ChatSettingsRights.ReadConnectionString, WriteRight = ChatSettingsRights.ReadConnectionString)] + [Permissions(ReadRight = ChatBotRights.ReadConnectionString, WriteRight = ChatBotRights.ReadConnectionString)] [Required] public string ConnectionString { get; set; } } diff --git a/src/Tgstation.Server.Api/Rights/ChatSettingsRights.cs b/src/Tgstation.Server.Api/Rights/ChatBotRights.cs similarity index 50% rename from src/Tgstation.Server.Api/Rights/ChatSettingsRights.cs rename to src/Tgstation.Server.Api/Rights/ChatBotRights.cs index 9064bda79c..d9a8c61ff1 100644 --- a/src/Tgstation.Server.Api/Rights/ChatSettingsRights.cs +++ b/src/Tgstation.Server.Api/Rights/ChatBotRights.cs @@ -3,49 +3,49 @@ namespace Tgstation.Server.Api.Rights { /// - /// Rights for + /// Rights for /// [Flags] - public enum ChatSettingsRights : ulong + public enum ChatBotRights : ulong { /// /// User has no rights /// None = 0, /// - /// User can change + /// User can change /// WriteEnabled = 1, /// - /// User can change + /// User can change /// WriteProvider = 2, /// - /// User can change + /// User can change /// WriteChannels = 4, /// - /// User can change + /// User can change /// WriteConnectionString = 8, /// - /// User can read requires + /// User can read requires /// ReadConnectionString = 16, /// - /// User can read all chat settings except + /// User can read all chat settings except /// Read = 32, /// - /// User can change + /// User can change /// WriteName = 32, /// - /// User can create new + /// User can create new /// Create = 64, /// - /// User can delete + /// User can delete /// Delete = 128 } diff --git a/src/Tgstation.Server.Api/Rights/RightsHelper.cs b/src/Tgstation.Server.Api/Rights/RightsHelper.cs index cbd83a7ca5..7c4a9cfa5a 100644 --- a/src/Tgstation.Server.Api/Rights/RightsHelper.cs +++ b/src/Tgstation.Server.Api/Rights/RightsHelper.cs @@ -21,7 +21,7 @@ namespace Tgstation.Server.Api.Rights { RightsType.Byond, typeof(ByondRights) }, { RightsType.DreamMaker, typeof(DreamMakerRights) }, { RightsType.DreamDaemon, typeof(DreamDaemonRights) }, - { RightsType.ChatSettings, typeof(ChatSettingsRights) }, + { RightsType.ChatBots, typeof(ChatBotRights) }, { RightsType.Configuration, typeof(ConfigurationRights) }, { RightsType.InstanceUser, typeof(InstanceUserRights) } }; diff --git a/src/Tgstation.Server.Api/Rights/RightsType.cs b/src/Tgstation.Server.Api/Rights/RightsType.cs index 346f80bcff..5ebd1948e3 100644 --- a/src/Tgstation.Server.Api/Rights/RightsType.cs +++ b/src/Tgstation.Server.Api/Rights/RightsType.cs @@ -30,9 +30,9 @@ /// DreamDaemon, /// - /// + /// /// - ChatSettings, + ChatBots, /// /// /// diff --git a/src/Tgstation.Server.Client/Components/IByondClient.cs b/src/Tgstation.Server.Client/Components/IByondClient.cs index 8ddbe011f2..bfe9e8f003 100644 --- a/src/Tgstation.Server.Client/Components/IByondClient.cs +++ b/src/Tgstation.Server.Client/Components/IByondClient.cs @@ -17,9 +17,9 @@ namespace Tgstation.Server.Client.Components Task Read(CancellationToken cancellationToken); /// - /// Updates the installed BYOND + /// Updates the information /// - /// The information to update + /// The information to update /// The for the operation /// A resulting in the updated information Task Update(Byond byond, CancellationToken cancellationToken); diff --git a/src/Tgstation.Server.Client/Components/IChatSettingsClient.cs b/src/Tgstation.Server.Client/Components/IChatBotsClient.cs similarity index 53% rename from src/Tgstation.Server.Client/Components/IChatSettingsClient.cs rename to src/Tgstation.Server.Client/Components/IChatBotsClient.cs index c0654a6dc2..538fdf72bc 100644 --- a/src/Tgstation.Server.Client/Components/IChatSettingsClient.cs +++ b/src/Tgstation.Server.Client/Components/IChatBotsClient.cs @@ -8,37 +8,37 @@ namespace Tgstation.Server.Client.Components /// /// For managing the chat bots /// - public interface IChatSettingsClient + public interface IChatBotsClient { /// - /// List the + /// List the /// /// The for the operation - /// A resulting in a of the of the server - Task> List(CancellationToken cancellationToken); + /// A resulting in a of the of the server + Task> List(CancellationToken cancellationToken); /// - /// Create a + /// Create a /// - /// The to create + /// The to create /// The for the operation - /// A resulting in the new - Task Create(ChatSettings settings, CancellationToken cancellationToken); + /// A resulting in the new + Task Create(ChatBot settings, CancellationToken cancellationToken); /// - /// Updates a setttings + /// Updates a setttings /// - /// The to update + /// The to update /// The for the operation - /// A resulting in the updated - Task Update(ChatSettings settings, CancellationToken cancellationToken); + /// A resulting in the updated + Task Update(ChatBot settings, CancellationToken cancellationToken); /// - /// Delete a + /// Delete a /// - /// The to delete + /// The to delete /// The for the operation /// A representing the running operation - Task Delete(ChatSettings settings, CancellationToken cancellationToken); + Task Delete(ChatBot settings, CancellationToken cancellationToken); } } diff --git a/src/Tgstation.Server.Client/Components/IConfigurationClient.cs b/src/Tgstation.Server.Client/Components/IConfigurationClient.cs index af84c1ca73..18cf7c4039 100644 --- a/src/Tgstation.Server.Client/Components/IConfigurationClient.cs +++ b/src/Tgstation.Server.Client/Components/IConfigurationClient.cs @@ -1,16 +1,14 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Tgstation.Server.Api.Models; -using Tgstation.Server.Api.Rights; namespace Tgstation.Server.Client.Components { /// /// For managing files /// - public interface IConfigurationClient : IRightsClient + public interface IConfigurationClient { /// /// List configuration files @@ -26,7 +24,7 @@ namespace Tgstation.Server.Client.Components /// The file to read /// The for the operation /// A representing the running operation - Task Read(ConfigurationFile file, CancellationToken cancellationToken); + Task Read(ConfigurationFile file, CancellationToken cancellationToken); /// /// Overwrite a file with integrity checks @@ -34,22 +32,6 @@ namespace Tgstation.Server.Client.Components /// The file to write /// The for the operation /// A representing the running operation - Task Write(ConfigurationFile file, CancellationToken cancellationToken); - - /// - /// Create/overwrite a file - /// - /// The file to write - /// The for the operation - /// A representing the running operation - Task Create(ConfigurationFile file, CancellationToken cancellationToken); - - /// - /// Delete a file - /// - /// The file to delete - /// The for the operation - /// A representing the running operation - Task Delete(ConfigurationFile file, CancellationToken cancellationToken); + Task Write(ConfigurationFile file, CancellationToken cancellationToken); } } diff --git a/src/Tgstation.Server.Client/Components/IDreamDaemonClient.cs b/src/Tgstation.Server.Client/Components/IDreamDaemonClient.cs index 1947c4170d..2078a954d1 100644 --- a/src/Tgstation.Server.Client/Components/IDreamDaemonClient.cs +++ b/src/Tgstation.Server.Client/Components/IDreamDaemonClient.cs @@ -1,14 +1,13 @@ using System.Threading; using System.Threading.Tasks; using Tgstation.Server.Api.Models; -using Tgstation.Server.Api.Rights; namespace Tgstation.Server.Client.Components { /// /// For managing /// - public interface IDreamDaemonClient: IRightsClient + public interface IDreamDaemonClient { /// /// Get the represented by the @@ -22,14 +21,14 @@ namespace Tgstation.Server.Client.Components /// /// The for the operation /// A representing the running operation - Task Start(CancellationToken cancellationToken); + Task Start(CancellationToken cancellationToken); /// /// Shutdown /// /// The for the operation /// A representing the running operation - Task Shutdown(CancellationToken cancellationToken); + Task Shutdown(CancellationToken cancellationToken); /// /// Update . This may trigger @@ -37,6 +36,6 @@ namespace Tgstation.Server.Client.Components /// The to update /// The for the operation /// A representing the running operation - Task Update(DreamDaemon dreamDaemon, CancellationToken cancellationToken); + Task Update(DreamDaemon dreamDaemon, CancellationToken cancellationToken); } } diff --git a/src/Tgstation.Server.Client/Components/IDreamMakerClient.cs b/src/Tgstation.Server.Client/Components/IDreamMakerClient.cs index ef1fb7b29b..f9e04a37d4 100644 --- a/src/Tgstation.Server.Client/Components/IDreamMakerClient.cs +++ b/src/Tgstation.Server.Client/Components/IDreamMakerClient.cs @@ -8,14 +8,14 @@ namespace Tgstation.Server.Client.Components /// /// For managing the compiler /// - public interface IDreamMakerClient : IRightsClient + public interface IDreamMakerClient { /// /// Get the represented by the /// /// The for the operation /// A resulting in the represented by the - Task Read(CancellationToken cancellationToken); + Task Read(CancellationToken cancellationToken); /// /// Updates the setttings diff --git a/src/Tgstation.Server.Client/Components/IInstanceClient.cs b/src/Tgstation.Server.Client/Components/IInstanceClient.cs index e806263fe8..9566815f7a 100644 --- a/src/Tgstation.Server.Client/Components/IInstanceClient.cs +++ b/src/Tgstation.Server.Client/Components/IInstanceClient.cs @@ -39,9 +39,9 @@ namespace Tgstation.Server.Client.Components IInstanceUserClient Users { get; } /// - /// Access the + /// Access the /// - IChatSettingsClient Chat { get; } + IChatBotsClient ChatBots { get; } /// /// Access the diff --git a/src/Tgstation.Server.Client/Components/IInstanceUserClient.cs b/src/Tgstation.Server.Client/Components/IInstanceUserClient.cs index 65248e42d5..6c73e0371f 100644 --- a/src/Tgstation.Server.Client/Components/IInstanceUserClient.cs +++ b/src/Tgstation.Server.Client/Components/IInstanceUserClient.cs @@ -2,14 +2,13 @@ using System.Threading; using System.Threading.Tasks; using Tgstation.Server.Api.Models; -using Tgstation.Server.Api.Rights; namespace Tgstation.Server.Client.Components { /// /// For managing s /// - public interface IInstanceUserClient : IRightsClient + public interface IInstanceUserClient { /// /// Get the s in the @@ -18,12 +17,20 @@ namespace Tgstation.Server.Client.Components /// A resulting in a of s in the instance Task> Read(CancellationToken cancellationToken); - /// - /// Update a - /// - /// The to update - /// The for the operation - /// A representing the running operation - Task Update(InstanceUser instanceUser, CancellationToken cancellationToken); - } + /// + /// Update a + /// + /// The to update + /// The for the operation + /// A representing the running operation + Task Update(InstanceUser instanceUser, CancellationToken cancellationToken); + + /// + /// Create a + /// + /// The to create + /// The for the operation + /// A representing the running operation + Task Create(InstanceUser instanceUser, CancellationToken cancellationToken); + } } \ No newline at end of file diff --git a/src/Tgstation.Server.Client/Components/IRepositoryClient.cs b/src/Tgstation.Server.Client/Components/IRepositoryClient.cs index a3ee2188ad..78259b93c4 100644 --- a/src/Tgstation.Server.Client/Components/IRepositoryClient.cs +++ b/src/Tgstation.Server.Client/Components/IRepositoryClient.cs @@ -2,14 +2,13 @@ using System.Threading; using System.Threading.Tasks; using Tgstation.Server.Api.Models; -using Tgstation.Server.Api.Rights; namespace Tgstation.Server.Client.Components { /// /// For managing the /// - public interface IRepositoryClient : IRightsClient + public interface IRepositoryClient { /// /// Get the represented by the diff --git a/src/Tgstation.Server.Host/Components/Chat/Chat.cs b/src/Tgstation.Server.Host/Components/Chat/Chat.cs index 15121806f3..983155cad5 100644 --- a/src/Tgstation.Server.Host/Components/Chat/Chat.cs +++ b/src/Tgstation.Server.Host/Components/Chat/Chat.cs @@ -44,7 +44,7 @@ namespace Tgstation.Server.Host.Components.Chat readonly Dictionary builtinCommands; /// - /// Map of s in use, keyed by + /// Map of s in use, keyed by /// readonly Dictionary providers; @@ -64,9 +64,9 @@ namespace Tgstation.Server.Host.Components.Chat readonly CancellationTokenSource handlerCts; /// - /// The initial for the + /// The initial for the /// - readonly List initialChatSettings; + readonly List initialChatBots; /// /// The for the @@ -79,7 +79,7 @@ namespace Tgstation.Server.Host.Components.Chat Task chatHandler; /// - /// The that completes when change + /// The that completes when s change /// TaskCompletionSource connectionsUpdated; @@ -100,14 +100,14 @@ namespace Tgstation.Server.Host.Components.Chat /// The value of /// The value of /// The value of - /// The used to populate - public Chat(IProviderFactory providerFactory, IIOManager ioManager, ICommandFactory commandFactory, ILogger logger, IEnumerable initialChatSettings) + /// The used to populate + public Chat(IProviderFactory providerFactory, IIOManager ioManager, ICommandFactory commandFactory, ILogger logger, IEnumerable initialChatBots) { this.providerFactory = providerFactory ?? throw new ArgumentNullException(nameof(providerFactory)); this.ioManager = ioManager ?? throw new ArgumentNullException(nameof(ioManager)); this.commandFactory = commandFactory ?? throw new ArgumentNullException(nameof(commandFactory)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); - this.initialChatSettings = initialChatSettings?.ToList() ?? throw new ArgumentNullException(nameof(initialChatSettings)); + this.initialChatBots = initialChatBots?.ToList() ?? throw new ArgumentNullException(nameof(initialChatBots)); builtinCommands = new Dictionary(); providers = new Dictionary(); @@ -129,7 +129,7 @@ namespace Tgstation.Server.Host.Components.Chat /// /// Remove a from and optionally updating the as well /// - /// The of the to delete + /// The of the to delete /// If should be update /// The for the operation /// A resulting in the being removed if it exists, otherwise @@ -375,7 +375,7 @@ namespace Tgstation.Server.Host.Components.Chat } /// - public async Task ChangeSettings(ChatSettings newSettings, CancellationToken cancellationToken) + public async Task ChangeSettings(ChatBot newSettings, CancellationToken cancellationToken) { if (newSettings == null) throw new ArgumentNullException(nameof(newSettings)); @@ -478,9 +478,9 @@ namespace Tgstation.Server.Host.Components.Chat { foreach (var I in commandFactory.GenerateCommands()) builtinCommands.Add(I.Name.ToUpperInvariant(), I); - await Task.WhenAll(initialChatSettings.Select(x => ChangeSettings(x, cancellationToken))).ConfigureAwait(false); + await Task.WhenAll(initialChatBots.Select(x => ChangeSettings(x, cancellationToken))).ConfigureAwait(false); await Task.WhenAll(providers.Select(x => x.Value).Select(x => x.Connect(cancellationToken))).ConfigureAwait(false); - await Task.WhenAll(initialChatSettings.Select(x => ChangeChannels(x.Id, x.Channels, cancellationToken))).ConfigureAwait(false); + await Task.WhenAll(initialChatBots.Select(x => ChangeChannels(x.Id, x.Channels, cancellationToken))).ConfigureAwait(false); chatHandler = MonitorMessages(handlerCts.Token); started = true; } diff --git a/src/Tgstation.Server.Host/Components/Chat/ChatFactory.cs b/src/Tgstation.Server.Host/Components/Chat/ChatFactory.cs index cd23992477..8e4ab3407b 100644 --- a/src/Tgstation.Server.Host/Components/Chat/ChatFactory.cs +++ b/src/Tgstation.Server.Host/Components/Chat/ChatFactory.cs @@ -45,6 +45,6 @@ namespace Tgstation.Server.Host.Components.Chat } /// - public IChat CreateChat(IEnumerable initialChatSettings) => new Chat(providerFactory, ioManager, commandFactory, loggerFactory.CreateLogger(), initialChatSettings); + public IChat CreateChat(IEnumerable initialChatBots) => new Chat(providerFactory, ioManager, commandFactory, loggerFactory.CreateLogger(), initialChatBots); } } diff --git a/src/Tgstation.Server.Host/Components/Chat/IChat.cs b/src/Tgstation.Server.Host/Components/Chat/IChat.cs index 114669bbca..fb8a1166df 100644 --- a/src/Tgstation.Server.Host/Components/Chat/IChat.cs +++ b/src/Tgstation.Server.Host/Components/Chat/IChat.cs @@ -13,9 +13,9 @@ namespace Tgstation.Server.Host.Components.Chat public interface IChat : IHostedService, IDisposable { /// - /// If a given set of is connected + /// If a given set of is connected /// - /// The of the connection + /// The of the connection /// if it is connected, otherwise bool Connected(long connectionId); @@ -26,17 +26,17 @@ namespace Tgstation.Server.Host.Components.Chat void RegisterCommandHandler(ICustomCommandHandler customCommandHandler); /// - /// Change chat settings. If the is not currently in use, a new connection will be made instead + /// Change chat settings. If the is not currently in use, a new connection will be made instead /// - /// The new + /// The new /// The for the operation - /// A representing the running operation. Will complete immediately if the property of is - Task ChangeSettings(ChatSettings newSettings, CancellationToken cancellationToken); + /// A representing the running operation. Will complete immediately if the property of is + Task ChangeSettings(ChatBot newSettings, CancellationToken cancellationToken); /// /// Disconnects and deletes a given connection /// - /// The of the connection + /// The of the connection /// The for the operation /// A representing the running operation Task DeleteConnection(long connectionId, CancellationToken cancellationToken); @@ -44,7 +44,7 @@ namespace Tgstation.Server.Host.Components.Chat /// /// Change chat channels /// - /// The of the connection + /// The of the connection /// An of the new list of s /// The for the operation /// A representing the running operation diff --git a/src/Tgstation.Server.Host/Components/Chat/IChatFactory.cs b/src/Tgstation.Server.Host/Components/Chat/IChatFactory.cs index 44802b484f..6950552eb7 100644 --- a/src/Tgstation.Server.Host/Components/Chat/IChatFactory.cs +++ b/src/Tgstation.Server.Host/Components/Chat/IChatFactory.cs @@ -10,8 +10,8 @@ namespace Tgstation.Server.Host.Components.Chat /// /// Create a /// - /// The initial for the + /// The initial for the /// A new - IChat CreateChat(IEnumerable initialChatSettings); + IChat CreateChat(IEnumerable initialChatBots); } } diff --git a/src/Tgstation.Server.Host/Components/Chat/IProviderFactory.cs b/src/Tgstation.Server.Host/Components/Chat/IProviderFactory.cs index b4b47f2d5b..2bf9b1651d 100644 --- a/src/Tgstation.Server.Host/Components/Chat/IProviderFactory.cs +++ b/src/Tgstation.Server.Host/Components/Chat/IProviderFactory.cs @@ -11,8 +11,8 @@ namespace Tgstation.Server.Host.Components.Chat /// /// Create a /// - /// The for the new provider + /// The containing settings for the new provider /// A new - IProvider CreateProvider(ChatSettings settings); + IProvider CreateProvider(ChatBot settings); } } diff --git a/src/Tgstation.Server.Host/Components/Chat/ProviderFactory.cs b/src/Tgstation.Server.Host/Components/Chat/ProviderFactory.cs index bb3b6fd20f..ae9633671d 100644 --- a/src/Tgstation.Server.Host/Components/Chat/ProviderFactory.cs +++ b/src/Tgstation.Server.Host/Components/Chat/ProviderFactory.cs @@ -33,7 +33,7 @@ namespace Tgstation.Server.Host.Components.Chat } /// - public IProvider CreateProvider(Api.Models.Internal.ChatSettings settings) + public IProvider CreateProvider(Api.Models.Internal.ChatBot settings) { if (settings == null) throw new ArgumentNullException(nameof(settings)); diff --git a/src/Tgstation.Server.Host/Controllers/ChatController.cs b/src/Tgstation.Server.Host/Controllers/ChatController.cs index 2ac361b428..e2060eeea4 100644 --- a/src/Tgstation.Server.Host/Controllers/ChatController.cs +++ b/src/Tgstation.Server.Host/Controllers/ChatController.cs @@ -19,10 +19,10 @@ using Z.EntityFramework.Plus; namespace Tgstation.Server.Host.Controllers { /// - /// for managing + /// for managing s /// [Route("/" + nameof(Components.Chat.Chat))] - public sealed class ChatController : ModelController + public sealed class ChatController : ModelController { /// /// The for the @@ -56,8 +56,8 @@ namespace Tgstation.Server.Host.Controllers }; /// - [TgsAuthorize(ChatSettingsRights.Create)] - public override async Task Create([FromBody] Api.Models.ChatSettings model, CancellationToken cancellationToken) + [TgsAuthorize(ChatBotRights.Create)] + public override async Task Create([FromBody] Api.Models.ChatBot model, CancellationToken cancellationToken) { if (model == null) throw new ArgumentNullException(nameof(model)); @@ -87,7 +87,7 @@ namespace Tgstation.Server.Host.Controllers return BadRequest(new ErrorMessage { Message = "One or more of channels aren't formatted correctly for the given provider!" }); //try to update das db first - var dbModel = new Models.ChatSettings + var dbModel = new Models.ChatBot { Name = model.Name, ConnectionString = model.ConnectionString, @@ -97,7 +97,7 @@ namespace Tgstation.Server.Host.Controllers Provider = model.Provider, }; - DatabaseContext.ChatSettings.Add(dbModel); + DatabaseContext.ChatBots.Add(dbModel); try { @@ -122,7 +122,7 @@ namespace Tgstation.Server.Host.Controllers catch { //undo the add - DatabaseContext.ChatSettings.Remove(dbModel); + DatabaseContext.ChatBots.Remove(dbModel); await DatabaseContext.Save(default).ConfigureAwait(false); throw; } @@ -135,24 +135,24 @@ namespace Tgstation.Server.Host.Controllers } /// - [TgsAuthorize(ChatSettingsRights.Delete)] + [TgsAuthorize(ChatBotRights.Delete)] public override async Task Delete(long id, CancellationToken cancellationToken) { var instance = instanceManager.GetInstance(Instance); - await Task.WhenAll(instance.Chat.DeleteConnection(id, cancellationToken), DatabaseContext.ChatSettings.Where(x => x.Id == id).DeleteAsync(cancellationToken)).ConfigureAwait(false); + await Task.WhenAll(instance.Chat.DeleteConnection(id, cancellationToken), DatabaseContext.ChatBots.Where(x => x.Id == id).DeleteAsync(cancellationToken)).ConfigureAwait(false); return Ok(); } /// - [TgsAuthorize(ChatSettingsRights.Read)] + [TgsAuthorize(ChatBotRights.Read)] public override async Task List(CancellationToken cancellationToken) { - var query = DatabaseContext.ChatSettings.Where(x => x.InstanceId == Instance.Id).Include(x => x.Channels); + var query = DatabaseContext.ChatBots.Where(x => x.InstanceId == Instance.Id).Include(x => x.Channels); var results = await query.ToListAsync(cancellationToken).ConfigureAwait(false); - var connectionStrings = (AuthenticationContext.GetRight(RightsType.ChatSettings) & (int)ChatSettingsRights.ReadConnectionString) != 0; + var connectionStrings = (AuthenticationContext.GetRight(RightsType.ChatBots) & (int)ChatBotRights.ReadConnectionString) != 0; if (!connectionStrings) foreach (var I in results) @@ -162,16 +162,16 @@ namespace Tgstation.Server.Host.Controllers } /// - [TgsAuthorize(ChatSettingsRights.Read)] + [TgsAuthorize(ChatBotRights.Read)] public override async Task GetId(long id, CancellationToken cancellationToken) { - var query = DatabaseContext.ChatSettings.Where(x => x.Id == id).Include(x => x.Channels); + var query = DatabaseContext.ChatBots.Where(x => x.Id == id).Include(x => x.Channels); var results = await query.FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false); if (results == default) return NotFound(); - var connectionStrings = (AuthenticationContext.GetRight(RightsType.ChatSettings) & (int)ChatSettingsRights.ReadConnectionString) != 0; + var connectionStrings = (AuthenticationContext.GetRight(RightsType.ChatBots) & (int)ChatBotRights.ReadConnectionString) != 0; if (!connectionStrings) results.ConnectionString = null; @@ -180,24 +180,24 @@ namespace Tgstation.Server.Host.Controllers } /// - [TgsAuthorize(ChatSettingsRights.WriteChannels | ChatSettingsRights.WriteConnectionString | ChatSettingsRights.WriteEnabled | ChatSettingsRights.WriteName | ChatSettingsRights.WriteProvider)] - public override async Task Update([FromBody] Api.Models.ChatSettings model, CancellationToken cancellationToken) + [TgsAuthorize(ChatBotRights.WriteChannels | ChatBotRights.WriteConnectionString | ChatBotRights.WriteEnabled | ChatBotRights.WriteName | ChatBotRights.WriteProvider)] + public override async Task Update([FromBody] Api.Models.ChatBot model, CancellationToken cancellationToken) { if (model == null) throw new ArgumentNullException(nameof(model)); - var query = DatabaseContext.ChatSettings.Where(x => x.InstanceId == Instance.Id && x.Id == model.Id).Include(x => x.Channels); + var query = DatabaseContext.ChatBots.Where(x => x.InstanceId == Instance.Id && x.Id == model.Id).Include(x => x.Channels); var current = await query.FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false); if (current == default) return StatusCode((int)HttpStatusCode.Gone); - var userRights = (ChatSettingsRights)AuthenticationContext.GetRight(RightsType.ChatSettings); + var userRights = (ChatBotRights)AuthenticationContext.GetRight(RightsType.ChatBots); bool anySettingsModified = false; - bool CheckModified(Expression> expression, ChatSettingsRights requiredRight) + bool CheckModified(Expression> expression, ChatBotRights requiredRight) { var memberSelectorExpression = (MemberExpression)expression.Body; var property = (PropertyInfo)memberSelectorExpression.Member; @@ -213,11 +213,11 @@ namespace Tgstation.Server.Host.Controllers return false; }; - if (CheckModified(x => x.ConnectionString, ChatSettingsRights.WriteConnectionString) - || CheckModified(x => x.Enabled, ChatSettingsRights.WriteEnabled) - || CheckModified(x => x.Name, ChatSettingsRights.WriteName) - || CheckModified(x => x.Provider, ChatSettingsRights.WriteProvider) - || (model.Channels != null && !userRights.HasFlag(ChatSettingsRights.WriteChannels))) + if (CheckModified(x => x.ConnectionString, ChatBotRights.WriteConnectionString) + || CheckModified(x => x.Enabled, ChatBotRights.WriteEnabled) + || CheckModified(x => x.Name, ChatBotRights.WriteName) + || CheckModified(x => x.Provider, ChatBotRights.WriteProvider) + || (model.Channels != null && !userRights.HasFlag(ChatBotRights.WriteChannels))) return Forbid(); if (model.Channels != null) @@ -239,9 +239,9 @@ namespace Tgstation.Server.Host.Controllers if (model.Channels != null || anySettingsModified) await chat.ChangeChannels(current.Id, current.Channels, cancellationToken).ConfigureAwait(false); - if (userRights.HasFlag(ChatSettingsRights.Read)) + if (userRights.HasFlag(ChatBotRights.Read)) { - if (!userRights.HasFlag(ChatSettingsRights.ReadConnectionString)) + if (!userRights.HasFlag(ChatBotRights.ReadConnectionString)) current.ConnectionString = null; return Json(current.ToApi()); } diff --git a/src/Tgstation.Server.Host/Controllers/InstanceController.cs b/src/Tgstation.Server.Host/Controllers/InstanceController.cs index 919cbe3319..c86029f9bc 100644 --- a/src/Tgstation.Server.Host/Controllers/InstanceController.cs +++ b/src/Tgstation.Server.Host/Controllers/InstanceController.cs @@ -81,7 +81,7 @@ namespace Tgstation.Server.Host.Controllers Models.InstanceUser InstanceAdminUser() => new Models.InstanceUser { ByondRights = (ByondRights)~0U, - ChatSettingsRights = (ChatSettingsRights)~0U, + ChatBotRights = (ChatBotRights)~0U, ConfigurationRights = (ConfigurationRights)~0U, DreamDaemonRights = (DreamDaemonRights)~0U, DreamMakerRights = (DreamMakerRights)~0U, diff --git a/src/Tgstation.Server.Host/Controllers/InstanceUserController.cs b/src/Tgstation.Server.Host/Controllers/InstanceUserController.cs index 0b4bbcc25a..6ce6ab0da3 100644 --- a/src/Tgstation.Server.Host/Controllers/InstanceUserController.cs +++ b/src/Tgstation.Server.Host/Controllers/InstanceUserController.cs @@ -57,7 +57,7 @@ namespace Tgstation.Server.Host.Controllers var dbUser = new Models.InstanceUser { ByondRights = model.ByondRights ?? ByondRights.None, - ChatSettingsRights = model.ChatSettingsRights ?? ChatSettingsRights.None, + ChatBotRights = model.ChatBotRights ?? ChatBotRights.None, ConfigurationRights = model.ConfigurationRights ?? ConfigurationRights.None, DreamDaemonRights = model.DreamDaemonRights ?? DreamDaemonRights.None, DreamMakerRights = model.DreamMakerRights ?? DreamMakerRights.None, @@ -93,7 +93,7 @@ namespace Tgstation.Server.Host.Controllers return StatusCode((int)HttpStatusCode.Gone); originalUser.ByondRights = model.ByondRights ?? originalUser.ByondRights; - originalUser.ChatSettingsRights = model.ChatSettingsRights ?? originalUser.ChatSettingsRights; + originalUser.ChatBotRights = model.ChatBotRights ?? originalUser.ChatBotRights; originalUser.ConfigurationRights = model.ConfigurationRights ?? originalUser.ConfigurationRights; originalUser.DreamDaemonRights = model.DreamDaemonRights ?? originalUser.DreamDaemonRights; originalUser.DreamMakerRights = model.DreamMakerRights ?? originalUser.DreamMakerRights; diff --git a/src/Tgstation.Server.Host/Controllers/TgsAuthorizeAttribute.cs b/src/Tgstation.Server.Host/Controllers/TgsAuthorizeAttribute.cs index fb2f5377f3..d6eb1b25b6 100644 --- a/src/Tgstation.Server.Host/Controllers/TgsAuthorizeAttribute.cs +++ b/src/Tgstation.Server.Host/Controllers/TgsAuthorizeAttribute.cs @@ -52,10 +52,10 @@ namespace Tgstation.Server.Host.Controllers public TgsAuthorizeAttribute(DreamDaemonRights requiredRights) => Roles = RightsHelper.RoleNames(requiredRights); /// - /// Construct a for + /// Construct a for /// /// The rights required - public TgsAuthorizeAttribute(ChatSettingsRights requiredRights) => Roles = RightsHelper.RoleNames(requiredRights); + public TgsAuthorizeAttribute(ChatBotRights requiredRights) => Roles = RightsHelper.RoleNames(requiredRights); /// /// Construct a for diff --git a/src/Tgstation.Server.Host/Models/ChatSettings.cs b/src/Tgstation.Server.Host/Models/ChatBot.cs similarity index 72% rename from src/Tgstation.Server.Host/Models/ChatSettings.cs rename to src/Tgstation.Server.Host/Models/ChatBot.cs index 816139e347..807a31f908 100644 --- a/src/Tgstation.Server.Host/Models/ChatSettings.cs +++ b/src/Tgstation.Server.Host/Models/ChatBot.cs @@ -1,12 +1,11 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; -using Tgstation.Server.Api.Models; namespace Tgstation.Server.Host.Models { /// - public sealed class ChatSettings : Api.Models.Internal.ChatSettings, IApiConvertable + public sealed class ChatBot : Api.Models.Internal.ChatBot, IApiConvertable { /// /// The @@ -20,12 +19,12 @@ namespace Tgstation.Server.Host.Models public Instance Instance { get; set; } /// - /// See + /// See /// public List Channels { get; set; } /// - public Api.Models.ChatSettings ToApi() => new Api.Models.ChatSettings + public Api.Models.ChatBot ToApi() => new Api.Models.ChatBot { Channels = Channels.Select(x => x.ToApi()).ToList(), ConnectionString = ConnectionString, diff --git a/src/Tgstation.Server.Host/Models/ChatChannel.cs b/src/Tgstation.Server.Host/Models/ChatChannel.cs index 09fcf41df6..c47d117d74 100644 --- a/src/Tgstation.Server.Host/Models/ChatChannel.cs +++ b/src/Tgstation.Server.Host/Models/ChatChannel.cs @@ -11,14 +11,14 @@ namespace Tgstation.Server.Host.Models public long Id { get; set; } /// - /// The + /// The /// public long ChatSettingsId { get; set; } /// - /// The + /// The /// - public ChatSettings ChatSettings { get; set; } + public ChatBot ChatSettings { get; set; } /// public Api.Models.ChatChannel ToApi() => new Api.Models.ChatChannel diff --git a/src/Tgstation.Server.Host/Models/DatabaseContext.cs b/src/Tgstation.Server.Host/Models/DatabaseContext.cs index 1b783e23a2..f4109b737a 100644 --- a/src/Tgstation.Server.Host/Models/DatabaseContext.cs +++ b/src/Tgstation.Server.Host/Models/DatabaseContext.cs @@ -28,7 +28,7 @@ namespace Tgstation.Server.Host.Models public DbSet DreamMakerSettings { get; set; } /// - public DbSet ChatSettings { get; set; } + public DbSet ChatBots { get; set; } /// public DbSet DreamDaemonSettings { get; set; } @@ -122,7 +122,7 @@ namespace Tgstation.Server.Host.Models chatChannel.HasIndex(x => new { x.ChatSettingsId, x.DiscordChannelId }).IsUnique(); chatChannel.HasOne(x => x.ChatSettings).WithMany(x => x.Channels).HasForeignKey(x => x.ChatSettingsId).OnDelete(DeleteBehavior.Cascade); - modelBuilder.Entity().HasIndex(x => x.Name).IsUnique(); + modelBuilder.Entity().HasIndex(x => x.Name).IsUnique(); var instanceModel = modelBuilder.Entity(); instanceModel.HasIndex(x => x.Path).IsUnique(); diff --git a/src/Tgstation.Server.Host/Models/IDatabaseContext.cs b/src/Tgstation.Server.Host/Models/IDatabaseContext.cs index ea02c85426..8fdb8aad74 100644 --- a/src/Tgstation.Server.Host/Models/IDatabaseContext.cs +++ b/src/Tgstation.Server.Host/Models/IDatabaseContext.cs @@ -50,9 +50,9 @@ namespace Tgstation.Server.Host.Models DbSet DreamDaemonSettings { get; set; } /// - /// The in the + /// The in the /// - DbSet ChatSettings { get; set; } + DbSet ChatBots { get; set; } /// /// The in the diff --git a/src/Tgstation.Server.Host/Models/Instance.cs b/src/Tgstation.Server.Host/Models/Instance.cs index 10b2eb9ece..4c22fd55b8 100644 --- a/src/Tgstation.Server.Host/Models/Instance.cs +++ b/src/Tgstation.Server.Host/Models/Instance.cs @@ -34,9 +34,9 @@ namespace Tgstation.Server.Host.Models public List InstanceUsers { get; set; } /// - /// The s for the + /// The s for the /// - public List ChatSettings { get; set; } + public List ChatSettings { get; set; } /// /// The s in the diff --git a/src/Tgstation.Server.Host/Models/InstanceUser.cs b/src/Tgstation.Server.Host/Models/InstanceUser.cs index 152738ef3a..925915f278 100644 --- a/src/Tgstation.Server.Host/Models/InstanceUser.cs +++ b/src/Tgstation.Server.Host/Models/InstanceUser.cs @@ -26,7 +26,7 @@ namespace Tgstation.Server.Host.Models /// If the has any instance rights /// public bool AnyRights => ByondRights != Api.Rights.ByondRights.None || - ChatSettingsRights != Api.Rights.ChatSettingsRights.None || + ChatBotRights != Api.Rights.ChatBotRights.None || ConfigurationRights != Api.Rights.ConfigurationRights.None || DreamDaemonRights != Api.Rights.DreamDaemonRights.None || DreamMakerRights != Api.Rights.DreamMakerRights.None || @@ -36,7 +36,7 @@ namespace Tgstation.Server.Host.Models public Api.Models.InstanceUser ToApi() => new Api.Models.InstanceUser { ByondRights = ByondRights, - ChatSettingsRights = ChatSettingsRights, + ChatBotRights = ChatBotRights, ConfigurationRights = ConfigurationRights, DreamDaemonRights = DreamDaemonRights, DreamMakerRights = DreamMakerRights,