diff --git a/src/Tgstation.Server.Api/Models/Internal/ChatBot.cs b/src/Tgstation.Server.Api/Models/Internal/ChatBot.cs index cf6ba561aa..9dd6b9e873 100644 --- a/src/Tgstation.Server.Api/Models/Internal/ChatBot.cs +++ b/src/Tgstation.Server.Api/Models/Internal/ChatBot.cs @@ -1,6 +1,5 @@ using System; using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; namespace Tgstation.Server.Api.Models.Internal { @@ -26,10 +25,9 @@ namespace Tgstation.Server.Api.Models.Internal public bool? Enabled { get; set; } /// - /// The time interval in minutes the chat bot attempts to reconnect if and disconnected. + /// The time interval in minutes the chat bot attempts to reconnect if and disconnected. Must not be zero. /// [Required] - [NotMapped] public uint? ReconnectionInterval { get; set; } /// diff --git a/src/Tgstation.Server.Api/Rights/ChatBotRights.cs b/src/Tgstation.Server.Api/Rights/ChatBotRights.cs index 11572bb0b1..7dcc43270e 100644 --- a/src/Tgstation.Server.Api/Rights/ChatBotRights.cs +++ b/src/Tgstation.Server.Api/Rights/ChatBotRights.cs @@ -57,5 +57,10 @@ namespace Tgstation.Server.Api.Rights /// User can change /// WriteName = 256, + + /// + /// User can change + /// + WriteReconnectionInterval = 512, } } diff --git a/src/Tgstation.Server.Host/Controllers/ChatController.cs b/src/Tgstation.Server.Host/Controllers/ChatController.cs index 7346a52af3..b141f12161 100644 --- a/src/Tgstation.Server.Host/Controllers/ChatController.cs +++ b/src/Tgstation.Server.Host/Controllers/ChatController.cs @@ -91,6 +91,9 @@ namespace Tgstation.Server.Host.Controllers return BadRequest(new ErrorMessage { Message = "Invalid provider!" }); } + if (model.ReconnectionInterval == 0) + return BadRequest(new ErrorMessage { Message = "ReconnectionInterval must not be zero!" }); + if (!model.ValidateProviderChannelTypes()) return BadRequest(new ErrorMessage { Message = "One or more of channels aren't formatted correctly for the given provider!" }); @@ -105,6 +108,7 @@ namespace Tgstation.Server.Host.Controllers Channels = model.Channels?.Select(x => ConvertApiChatChannel(x)).ToList() ?? new List(), // important that this isn't null InstanceId = Instance.Id, Provider = model.Provider, + ReconnectionInterval = model.ReconnectionInterval }; DatabaseContext.ChatBots.Add(dbModel); @@ -219,12 +223,18 @@ namespace Tgstation.Server.Host.Controllers [TgsAuthorize(ChatBotRights.WriteChannels | ChatBotRights.WriteConnectionString | ChatBotRights.WriteEnabled | ChatBotRights.WriteName | ChatBotRights.WriteProvider)] [ProducesResponseType(200)] [ProducesResponseType(typeof(Api.Models.ChatBot), 200)] - #pragma warning disable CA1506 // TODO: Decomplexify + #pragma warning disable CA1502 // TODO: Decomplexify + #pragma warning disable CA1506 public async Task Update([FromBody] Api.Models.ChatBot model, CancellationToken cancellationToken) + #pragma warning restore CA1502 + #pragma warning restore CA1506 { if (model == null) throw new ArgumentNullException(nameof(model)); + if (model.ReconnectionInterval == 0) + return BadRequest(new ErrorMessage { Message = "ReconnectionInterval must not be zero!" }); + if (model.Provider.HasValue && !model.ValidateProviderChannelTypes()) return BadRequest(new ErrorMessage { Message = "One or more of channels aren't formatted correctly for the given provider!" }); @@ -261,6 +271,7 @@ namespace Tgstation.Server.Host.Controllers || CheckModified(x => x.Enabled, ChatBotRights.WriteEnabled) || CheckModified(x => x.Name, ChatBotRights.WriteName) || CheckModified(x => x.Provider, ChatBotRights.WriteProvider) + || CheckModified(x => x.ReconnectionInterval, ChatBotRights.WriteReconnectionInterval) || (model.Channels != null && !userRights.HasFlag(ChatBotRights.WriteChannels))) return Forbid(); @@ -297,6 +308,5 @@ namespace Tgstation.Server.Host.Controllers return Ok(); } - #pragma warning restore CA1506 } }