diff --git a/build/Version.props b/build/Version.props index b9cd0eadbd..393bf27ba0 100644 --- a/build/Version.props +++ b/build/Version.props @@ -2,7 +2,7 @@ - 4.1.0 + 4.1.1 6.1.0 6.0.0 5.0.0 diff --git a/src/Tgstation.Server.Host/Controllers/ChatController.cs b/src/Tgstation.Server.Host/Controllers/ChatController.cs index 796fb8e94d..321a004b71 100644 --- a/src/Tgstation.Server.Host/Controllers/ChatController.cs +++ b/src/Tgstation.Server.Host/Controllers/ChatController.cs @@ -87,8 +87,8 @@ namespace Tgstation.Server.Host.Controllers if (countOfExistingBotsInInstance >= Instance.ChatBotLimit.Value) return Conflict(new ErrorMessage(ErrorCode.ChatBotMax)); - model.Enabled = model.Enabled ?? false; - model.ReconnectionInterval = model.ReconnectionInterval ?? 1; + model.Enabled ??= false; + model.ReconnectionInterval ??= 1; // try to update das db first var dbModel = new Models.ChatBot @@ -264,6 +264,7 @@ namespace Tgstation.Server.Host.Controllers || CheckModified(x => x.Name, ChatBotRights.WriteName) || CheckModified(x => x.Provider, ChatBotRights.WriteProvider) || CheckModified(x => x.ReconnectionInterval, ChatBotRights.WriteReconnectionInterval) + || CheckModified(x => x.ChannelLimit, ChatBotRights.WriteChannelLimit) || (model.Channels != null && !userRights.HasFlag(ChatBotRights.WriteChannels))) return Forbid(); @@ -329,7 +330,7 @@ namespace Tgstation.Server.Host.Controllers return BadRequest(new ErrorMessage(ErrorCode.ChatBotMaxChannels)); if (forCreation) - model.ChannelLimit = model.ChannelLimit ?? (ushort)defaultMaxChannels; + model.ChannelLimit ??= (ushort)defaultMaxChannels; return null; } diff --git a/src/Tgstation.Server.Host/Controllers/InstanceController.cs b/src/Tgstation.Server.Host/Controllers/InstanceController.cs index d207b07d5c..15f6eec39f 100644 --- a/src/Tgstation.Server.Host/Controllers/InstanceController.cs +++ b/src/Tgstation.Server.Host/Controllers/InstanceController.cs @@ -349,7 +349,7 @@ namespace Tgstation.Server.Host.Controllers /// Instance updated successfully. /// Instance updated successfully and relocation job created. [HttpPost] - [TgsAuthorize(InstanceManagerRights.Relocate | InstanceManagerRights.Rename | InstanceManagerRights.SetAutoUpdate | InstanceManagerRights.SetConfiguration | InstanceManagerRights.SetOnline)] + [TgsAuthorize(InstanceManagerRights.Relocate | InstanceManagerRights.Rename | InstanceManagerRights.SetAutoUpdate | InstanceManagerRights.SetConfiguration | InstanceManagerRights.SetOnline | InstanceManagerRights.SetChatBotLimit)] [ProducesResponseType(typeof(Api.Models.Instance), 200)] [ProducesResponseType(typeof(Api.Models.Instance), 202)] [ProducesResponseType(410)] diff --git a/tests/Tgstation.Server.Tests/Instance/ChatTest.cs b/tests/Tgstation.Server.Tests/Instance/ChatTest.cs index 89330c64a3..a31441d0b8 100644 --- a/tests/Tgstation.Server.Tests/Instance/ChatTest.cs +++ b/tests/Tgstation.Server.Tests/Instance/ChatTest.cs @@ -196,6 +196,10 @@ namespace Tgstation.Server.Tests.Instance var instance = metadata.CloneMetadata(); instance.ChatBotLimit = 0; await ApiAssert.ThrowsException(() => instanceClient.Update(instance, cancellationToken), ErrorCode.ChatBotMax); + + discordBot.ChannelLimit = 20; + discordBot.Channels = null; + await chatClient.Update(discordBot, cancellationToken); } } } diff --git a/tests/Tgstation.Server.Tests/InstanceManagerTest.cs b/tests/Tgstation.Server.Tests/InstanceManagerTest.cs index 59c6e4e09c..da75591d08 100644 --- a/tests/Tgstation.Server.Tests/InstanceManagerTest.cs +++ b/tests/Tgstation.Server.Tests/InstanceManagerTest.cs @@ -5,6 +5,7 @@ using System.Reflection; using System.Threading; using System.Threading.Tasks; using Tgstation.Server.Api.Models; +using Tgstation.Server.Api.Rights; using Tgstation.Server.Client; using Tgstation.Server.Host.Controllers; using Tgstation.Server.Tests.Instance; @@ -14,13 +15,15 @@ namespace Tgstation.Server.Tests sealed class InstanceManagerTest { readonly IInstanceManagerClient instanceManagerClient; + readonly IUsersClient usersClient; readonly string testRootPath; long counter; - public InstanceManagerTest(IInstanceManagerClient instanceManagerClient, string testRootPath) + public InstanceManagerTest(IInstanceManagerClient instanceManagerClient, IUsersClient usersClient, string testRootPath) { this.instanceManagerClient = instanceManagerClient ?? throw new ArgumentNullException(nameof(instanceManagerClient)); + this.usersClient = usersClient ?? throw new ArgumentNullException(nameof(usersClient)); this.testRootPath = testRootPath ?? throw new ArgumentNullException(nameof(testRootPath)); counter = 0; @@ -110,7 +113,7 @@ namespace Tgstation.Server.Tests await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false); } while (firstTest.MoveJob != null); - + //online it for real for component tests firstTest.Online = true; firstTest.ConfigurationType = ConfigurationType.HostWrite; @@ -152,10 +155,28 @@ namespace Tgstation.Server.Tests var instanceAttachFileName = (string)typeof(InstanceController).GetField("InstanceAttachFileName", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null); var attachPath = Path.Combine(firstTest.Path, instanceAttachFileName); Assert.IsTrue(File.Exists(attachPath)); - + //can recreate detached instance firstTest = await instanceManagerClient.CreateOrAttach(firstTest, cancellationToken).ConfigureAwait(false); + // Test updating only with SetChatBotLimit works + var current = await usersClient.Read(cancellationToken); + var update = new UserUpdate + { + Id = current.Id, + InstanceManagerRights = InstanceManagerRights.SetChatBotLimit + }; + await usersClient.Update(update, cancellationToken); + var update2 = new Api.Models.Instance + { + Id = firstTest.Id, + ChatBotLimit = 77 + }; + var newThing = await instanceManagerClient.Update(update2, cancellationToken); + + update.InstanceManagerRights |= InstanceManagerRights.Delete | InstanceManagerRights.Create; + await usersClient.Update(update, cancellationToken); + //but only if the attach file exists await instanceManagerClient.Detach(firstTest, cancellationToken).ConfigureAwait(false); File.Delete(attachPath); diff --git a/tests/Tgstation.Server.Tests/IntegrationTest.cs b/tests/Tgstation.Server.Tests/IntegrationTest.cs index 99f4b4318d..fe31c266d5 100644 --- a/tests/Tgstation.Server.Tests/IntegrationTest.cs +++ b/tests/Tgstation.Server.Tests/IntegrationTest.cs @@ -78,8 +78,6 @@ namespace Tgstation.Server.Tests Assert.IsTrue(discordProvider.Connected, "Discord provider not connected!"); } - // Disabled until 4.1.0 due to changes in version handling - [Ignore] [TestMethod] public async Task TestServerUpdate() { @@ -125,7 +123,7 @@ namespace Tgstation.Server.Tests } } while (true); - var testUpdateVersion = new Version(4, 0, 0, 6); + var testUpdateVersion = new Version(4, 1, 0); using (adminClient) //attempt to update to stable await adminClient.Administration.Update(new Administration @@ -144,7 +142,7 @@ namespace Tgstation.Server.Tests Assert.IsTrue(File.Exists(updatedAssemblyPath), "Updated assembly missing!"); var updatedAssemblyVersion = FileVersionInfo.GetVersionInfo(updatedAssemblyPath); - Assert.AreEqual(testUpdateVersion, Version.Parse(updatedAssemblyVersion.FileVersion)); + Assert.AreEqual(testUpdateVersion, Version.Parse(updatedAssemblyVersion.FileVersion).Semver()); } finally { @@ -222,7 +220,7 @@ namespace Tgstation.Server.Tests var adminTest = new AdministrationTest(adminClient.Administration).Run(cancellationToken); var usersTest = new UsersTest(adminClient.Users).Run(cancellationToken); - await new InstanceManagerTest(adminClient.Instances, server.Directory).Run(cancellationToken).ConfigureAwait(false); + await new InstanceManagerTest(adminClient.Instances, adminClient.Users, server.Directory).Run(cancellationToken).ConfigureAwait(false); await adminTest.ConfigureAwait(false); await usersTest.ConfigureAwait(false);