diff --git a/build/Version.props b/build/Version.props index 222901410b..d4a35b4ba5 100644 --- a/build/Version.props +++ b/build/Version.props @@ -5,7 +5,7 @@ 4.7.0 2.2.0 - 8.1.1 + 8.1.2 9.1.1 5.2.10 1.1.0 diff --git a/src/Tgstation.Server.Host/Controllers/InstancePermissionSetController.cs b/src/Tgstation.Server.Host/Controllers/InstancePermissionSetController.cs index 5a154b339a..58b95e35a4 100644 --- a/src/Tgstation.Server.Host/Controllers/InstancePermissionSetController.cs +++ b/src/Tgstation.Server.Host/Controllers/InstancePermissionSetController.cs @@ -48,27 +48,44 @@ namespace Tgstation.Server.Host.Controllers /// The for the operation. /// A resulting in the of the request. /// created successfully. + /// The does not exist. [HttpPut] [TgsAuthorize(InstancePermissionSetRights.Create)] [ProducesResponseType(typeof(Api.Models.InstancePermissionSet), 201)] + [ProducesResponseType(typeof(ErrorMessage), 410)] +#pragma warning disable CA1506 public async Task Create([FromBody] Api.Models.InstancePermissionSet model, CancellationToken cancellationToken) { if (model == null) throw new ArgumentNullException(nameof(model)); - var userCanonicalName = await DatabaseContext - .Users + var existingPermissionSet = await DatabaseContext + .PermissionSets .AsQueryable() .Where(x => x.Id == model.PermissionSetId) - .Select(x => x.CanonicalName) + .Select(x => new Models.PermissionSet + { + UserId = x.UserId + }) .FirstOrDefaultAsync(cancellationToken) .ConfigureAwait(false); - if (userCanonicalName == default) - return BadRequest(new ErrorMessage(ErrorCode.ModelValidationFailure)); + if (existingPermissionSet == default) + return Gone(); - if (userCanonicalName == Models.User.CanonicalizeName(Models.User.TgsSystemUserName)) - return Forbid(); + if (existingPermissionSet.UserId.HasValue) + { + var userCanonicalName = await DatabaseContext + .Users + .AsQueryable() + .Where(x => x.Id == existingPermissionSet.UserId.Value) + .Select(x => x.CanonicalName) + .FirstAsync(cancellationToken) + .ConfigureAwait(false); + + if (userCanonicalName == Models.User.CanonicalizeName(Models.User.TgsSystemUserName)) + return Forbid(); + } var dbUser = new Models.InstancePermissionSet { @@ -88,6 +105,7 @@ namespace Tgstation.Server.Host.Controllers await DatabaseContext.Save(cancellationToken).ConfigureAwait(false); return Created(dbUser.ToApi()); } + #pragma warning restore CA1506 /// /// Update the permissions for an .