mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-30 00:22:40 +01:00
Add ProducesResponseType for all controller actions
- Excluding common status codes which will be documented elsewhere
This commit is contained in:
@@ -154,6 +154,9 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize]
|
||||
[ProducesResponseType(typeof(Administration), 200)]
|
||||
[ProducesResponseType(424)]
|
||||
[ProducesResponseType(429)]
|
||||
public override async Task<IActionResult> Read(CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
@@ -198,6 +201,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(AdministrationRights.ChangeVersion)]
|
||||
[ProducesResponseType(typeof(ErrorMessage), 422)]
|
||||
public override async Task<IActionResult> Update([FromBody] Administration model, CancellationToken cancellationToken)
|
||||
{
|
||||
if (model == null)
|
||||
@@ -224,6 +228,8 @@ namespace Tgstation.Server.Host.Controllers
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="IActionResult"/> of the request</returns>
|
||||
[HttpDelete]
|
||||
[TgsAuthorize(AdministrationRights.RestartHost)]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(typeof(ErrorMessage), 422)]
|
||||
public async Task<IActionResult> Delete()
|
||||
{
|
||||
try
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
@@ -47,6 +48,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(ByondRights.ReadActive)]
|
||||
[ProducesResponseType(typeof(Api.Models.Byond), 200)]
|
||||
public override Task<IActionResult> Read(CancellationToken cancellationToken) => Task.FromResult<IActionResult>(
|
||||
Json(new Api.Models.Byond
|
||||
{
|
||||
@@ -55,6 +57,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(ByondRights.ListInstalled)]
|
||||
[ProducesResponseType(typeof(IEnumerable<Api.Models.Byond>), 200)]
|
||||
public override Task<IActionResult> List(CancellationToken cancellationToken) => Task.FromResult<IActionResult>(
|
||||
Json(instanceManager.GetInstance(Instance).ByondManager.InstalledVersions.Select(x => new Api.Models.Byond
|
||||
{
|
||||
@@ -63,6 +66,8 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(ByondRights.ChangeVersion)]
|
||||
[ProducesResponseType(typeof(Api.Models.Byond), 200)]
|
||||
[ProducesResponseType(typeof(Api.Models.Byond), 202)]
|
||||
public override async Task<IActionResult> Update([FromBody] Api.Models.Byond model, CancellationToken cancellationToken)
|
||||
{
|
||||
if (model == null)
|
||||
|
||||
@@ -59,6 +59,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(ChatBotRights.Create)]
|
||||
[ProducesResponseType(typeof(Api.Models.ChatBot), 201)]
|
||||
public override async Task<IActionResult> Create([FromBody] Api.Models.ChatBot model, CancellationToken cancellationToken)
|
||||
{
|
||||
if (model == null)
|
||||
@@ -131,6 +132,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(ChatBotRights.Delete)]
|
||||
[ProducesResponseType(200)]
|
||||
public override async Task<IActionResult> Delete(long id, CancellationToken cancellationToken)
|
||||
{
|
||||
var instance = instanceManager.GetInstance(Instance);
|
||||
@@ -141,6 +143,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(ChatBotRights.Read)]
|
||||
[ProducesResponseType(typeof(IEnumerable<Api.Models.ChatBot>), 200)]
|
||||
public override async Task<IActionResult> List(CancellationToken cancellationToken)
|
||||
{
|
||||
var query = DatabaseContext.ChatBots.Where(x => x.InstanceId == Instance.Id).Include(x => x.Channels);
|
||||
@@ -158,6 +161,8 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(ChatBotRights.Read)]
|
||||
[ProducesResponseType(typeof(Api.Models.ChatBot), 200)]
|
||||
[ProducesResponseType(410)]
|
||||
public override async Task<IActionResult> GetId(long id, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = DatabaseContext.ChatBots.Where(x => x.Id == id).Include(x => x.Channels);
|
||||
@@ -177,6 +182,8 @@ namespace Tgstation.Server.Host.Controllers
|
||||
/// <inheritdoc />
|
||||
#pragma warning disable CA1506 // TODO: Decomplexify
|
||||
[TgsAuthorize(ChatBotRights.WriteChannels | ChatBotRights.WriteConnectionString | ChatBotRights.WriteEnabled | ChatBotRights.WriteName | ChatBotRights.WriteProvider)]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(typeof(Api.Models.ChatBot), 200)]
|
||||
public override async Task<IActionResult> Update([FromBody] Api.Models.ChatBot model, CancellationToken cancellationToken)
|
||||
{
|
||||
if (model == null)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
@@ -65,6 +66,9 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(ConfigurationRights.Write)]
|
||||
[ProducesResponseType(typeof(ConfigurationFile), 200)]
|
||||
[ProducesResponseType(typeof(ConfigurationFile), 201)]
|
||||
[ProducesResponseType(501)]
|
||||
public override async Task<IActionResult> Update([FromBody] ConfigurationFile model, CancellationToken cancellationToken)
|
||||
{
|
||||
if (model == null)
|
||||
@@ -108,6 +112,9 @@ namespace Tgstation.Server.Host.Controllers
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="IActionResult"/> for the operation</returns>
|
||||
[HttpGet(Routes.File + "/{*filePath}")]
|
||||
[TgsAuthorize(ConfigurationRights.Read)]
|
||||
[ProducesResponseType(typeof(ConfigurationFile), 200)]
|
||||
[ProducesResponseType(410)]
|
||||
[ProducesResponseType(501)]
|
||||
public async Task<IActionResult> File(string filePath, CancellationToken cancellationToken)
|
||||
{
|
||||
if (ForbidDueToModeConflicts(filePath, out var systemIdentity))
|
||||
@@ -143,6 +150,9 @@ namespace Tgstation.Server.Host.Controllers
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="IActionResult"/> for the operation</returns>
|
||||
[HttpGet("List/{*directoryPath}")]
|
||||
[TgsAuthorize(ConfigurationRights.List)]
|
||||
[ProducesResponseType(typeof(IReadOnlyList<ConfigurationFile>), 200)]
|
||||
[ProducesResponseType(410)]
|
||||
[ProducesResponseType(501)]
|
||||
public async Task<IActionResult> Directory(string directoryPath, CancellationToken cancellationToken)
|
||||
{
|
||||
if (ForbidDueToModeConflicts(directoryPath, out var systemIdentity))
|
||||
@@ -168,10 +178,17 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(ConfigurationRights.List)]
|
||||
[ProducesResponseType(typeof(IReadOnlyList<ConfigurationFile>), 200)]
|
||||
[ProducesResponseType(410)]
|
||||
[ProducesResponseType(501)]
|
||||
public override Task<IActionResult> List(CancellationToken cancellationToken) => Directory(null, cancellationToken);
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(ConfigurationRights.Write)]
|
||||
[ProducesResponseType(typeof(ConfigurationFile), 200)]
|
||||
[ProducesResponseType(typeof(ConfigurationFile), 201)]
|
||||
[ProducesResponseType(410)]
|
||||
[ProducesResponseType(501)]
|
||||
public override async Task<IActionResult> Create([FromBody] ConfigurationFile model, CancellationToken cancellationToken)
|
||||
{
|
||||
if (model == null)
|
||||
@@ -185,6 +202,14 @@ namespace Tgstation.Server.Host.Controllers
|
||||
model.IsDirectory = true;
|
||||
return await instanceManager.GetInstance(Instance).Configuration.CreateDirectory(model.Path, systemIdentity, cancellationToken).ConfigureAwait(false) ? (IActionResult)Json(model) : StatusCode((int)HttpStatusCode.Created, model);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
Logger.LogInformation("IOException while creating directory {0}: {1}", model.Path, e);
|
||||
return Conflict(new ErrorMessage
|
||||
{
|
||||
Message = e.Message
|
||||
});
|
||||
}
|
||||
catch (NotImplementedException)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.NotImplemented);
|
||||
@@ -203,6 +228,8 @@ namespace Tgstation.Server.Host.Controllers
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="IActionResult"/> of the operation</returns>
|
||||
[HttpDelete]
|
||||
[TgsAuthorize(ConfigurationRights.Delete)]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(501)]
|
||||
public async Task<IActionResult> Delete([FromBody] ConfigurationFile directory, CancellationToken cancellationToken)
|
||||
{
|
||||
if (directory == null)
|
||||
|
||||
@@ -51,6 +51,8 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(DreamDaemonRights.Start)]
|
||||
[ProducesResponseType(typeof(Api.Models.Job), 202)]
|
||||
[ProducesResponseType(410)]
|
||||
public override async Task<IActionResult> Create([FromBody] DreamDaemon model, CancellationToken cancellationToken)
|
||||
{
|
||||
// alias for launching DD
|
||||
@@ -73,6 +75,8 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(DreamDaemonRights.ReadMetadata | DreamDaemonRights.ReadRevision)]
|
||||
[ProducesResponseType(typeof(DreamDaemon), 200)]
|
||||
[ProducesResponseType(410)]
|
||||
public override Task<IActionResult> Read(CancellationToken cancellationToken) => ReadImpl(null, cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
@@ -134,6 +138,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="IActionResult"/> of the operation</returns>
|
||||
[HttpDelete]
|
||||
[TgsAuthorize(DreamDaemonRights.Shutdown)]
|
||||
[ProducesResponseType(200)]
|
||||
public async Task<IActionResult> Delete(CancellationToken cancellationToken)
|
||||
{
|
||||
var instance = instanceManager.GetInstance(Instance);
|
||||
@@ -144,6 +149,8 @@ namespace Tgstation.Server.Host.Controllers
|
||||
/// <inheritdoc />
|
||||
#pragma warning disable CA1506 // TODO: Decomplexify
|
||||
[TgsAuthorize(DreamDaemonRights.SetAutoStart | DreamDaemonRights.SetPorts | DreamDaemonRights.SetSecurity | DreamDaemonRights.SetWebClient | DreamDaemonRights.SoftRestart | DreamDaemonRights.SoftShutdown | DreamDaemonRights.Start | DreamDaemonRights.SetStartupTimeout)]
|
||||
[ProducesResponseType(typeof(DreamDaemon), 200)]
|
||||
[ProducesResponseType(410)]
|
||||
public override async Task<IActionResult> Update([FromBody] DreamDaemon model, CancellationToken cancellationToken)
|
||||
{
|
||||
if (model == null)
|
||||
@@ -219,6 +226,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="IActionResult"/> of the request</returns>
|
||||
[HttpPatch]
|
||||
[TgsAuthorize(DreamDaemonRights.Restart)]
|
||||
[ProducesResponseType(typeof(Api.Models.Job), 202)]
|
||||
public async Task<IActionResult> Restart(CancellationToken cancellationToken)
|
||||
{
|
||||
var job = new Models.Job
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
@@ -49,6 +50,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(DreamMakerRights.Read)]
|
||||
[ProducesResponseType(typeof(DreamMaker), 200)]
|
||||
public override async Task<IActionResult> Read(CancellationToken cancellationToken)
|
||||
{
|
||||
var instance = instanceManager.GetInstance(Instance);
|
||||
@@ -58,6 +60,8 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(DreamMakerRights.CompileJobs)]
|
||||
[ProducesResponseType(typeof(Api.Models.CompileJob), 200)]
|
||||
[ProducesResponseType(404)]
|
||||
public override async Task<IActionResult> GetId(long id, CancellationToken cancellationToken)
|
||||
{
|
||||
var compileJob = await DatabaseContext.CompileJobs
|
||||
@@ -73,6 +77,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(DreamMakerRights.CompileJobs)]
|
||||
[ProducesResponseType(typeof(List<Api.Models.CompileJob>), 200)]
|
||||
public override async Task<IActionResult> List(CancellationToken cancellationToken)
|
||||
{
|
||||
var compileJobs = await DatabaseContext.CompileJobs.Where(x => x.Job.Instance.Id == Instance.Id).OrderByDescending(x => x.Job.StoppedAt).Select(x => new Api.Models.CompileJob
|
||||
@@ -84,6 +89,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(DreamMakerRights.Compile)]
|
||||
[ProducesResponseType(typeof(Api.Models.Job), 202)]
|
||||
public override async Task<IActionResult> Create([FromBody] DreamMaker model, CancellationToken cancellationToken)
|
||||
{
|
||||
var job = new Models.Job
|
||||
@@ -100,6 +106,9 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(DreamMakerRights.SetDme | DreamMakerRights.SetApiValidationPort | DreamMakerRights.SetApiValidationPort)]
|
||||
[ProducesResponseType(typeof(DreamMaker), 200)]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(410)]
|
||||
public override async Task<IActionResult> Update([FromBody] DreamMaker model, CancellationToken cancellationToken)
|
||||
{
|
||||
if (model.ApiValidationPort == 0)
|
||||
|
||||
@@ -92,6 +92,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
[TgsAuthorize]
|
||||
[AllowAnonymous]
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(Api.Models.ServerInformation), 200)]
|
||||
public IActionResult Home()
|
||||
{
|
||||
if (AuthenticationContext != null)
|
||||
@@ -117,6 +118,9 @@ namespace Tgstation.Server.Host.Controllers
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="IActionResult"/> of the operation</returns>
|
||||
[HttpPost]
|
||||
[ProducesResponseType(typeof(Api.Models.Token), 200)]
|
||||
[ProducesResponseType(401)]
|
||||
[ProducesResponseType(403)]
|
||||
#pragma warning disable CA1506 // TODO: Decomplexify
|
||||
public async Task<IActionResult> CreateToken(CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
@@ -110,6 +110,8 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(InstanceManagerRights.Create)]
|
||||
[ProducesResponseType(typeof(Api.Models.Instance), 200)]
|
||||
[ProducesResponseType(typeof(Api.Models.Instance), 201)]
|
||||
public override async Task<IActionResult> Create([FromBody] Api.Models.Instance model, CancellationToken cancellationToken)
|
||||
{
|
||||
if (model == null)
|
||||
@@ -130,7 +132,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
}, out var normalizedLocalPath);
|
||||
|
||||
if (rawPath.StartsWith(normalizedLocalPath, StringComparison.Ordinal))
|
||||
return Conflict("Instances cannot be created in the installation directory!");
|
||||
return Conflict(new ErrorMessage { Message = "Instances cannot be created in the installation directory!" });
|
||||
|
||||
var dirExistsTask = ioManager.DirectoryExists(model.Path, cancellationToken);
|
||||
bool attached = false;
|
||||
@@ -216,6 +218,8 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(InstanceManagerRights.Delete)]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(410)]
|
||||
public override async Task<IActionResult> Delete(long id, CancellationToken cancellationToken)
|
||||
{
|
||||
var originalModel = await DatabaseContext.Instances.Where(x => x.Id == id)
|
||||
@@ -250,7 +254,9 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(InstanceManagerRights.Relocate | InstanceManagerRights.Rename | InstanceManagerRights.SetAutoUpdate | InstanceManagerRights.SetConfiguration | InstanceManagerRights.SetOnline)]
|
||||
#pragma warning disable CA1502 // TODO: Decomplexify
|
||||
[ProducesResponseType(typeof(Api.Models.Instance), 200)]
|
||||
[ProducesResponseType(410)]
|
||||
#pragma warning disable CA1502 // TODO: Decomplexify
|
||||
public override async Task<IActionResult> Update([FromBody] Api.Models.Instance model, CancellationToken cancellationToken)
|
||||
{
|
||||
var instanceQuery = DatabaseContext.Instances.Where(x => x.Id == model.Id);
|
||||
@@ -396,6 +402,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(InstanceManagerRights.List | InstanceManagerRights.Read)]
|
||||
[ProducesResponseType(typeof(IEnumerable<Api.Models.Instance>), 200)]
|
||||
public override async Task<IActionResult> List(CancellationToken cancellationToken)
|
||||
{
|
||||
IQueryable<Models.Instance> query = DatabaseContext.Instances;
|
||||
@@ -420,6 +427,8 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(InstanceManagerRights.List | InstanceManagerRights.Read)]
|
||||
[ProducesResponseType(typeof(Api.Models.Instance), 200)]
|
||||
[ProducesResponseType(410)]
|
||||
public override async Task<IActionResult> GetId(long id, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = DatabaseContext.Instances.Where(x => x.Id == id);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
@@ -48,6 +49,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(InstanceUserRights.CreateUsers)]
|
||||
[ProducesResponseType(typeof(Api.Models.InstanceUser), 201)]
|
||||
public override async Task<IActionResult> Create([FromBody] Api.Models.InstanceUser model, CancellationToken cancellationToken)
|
||||
{
|
||||
var test = StandardModelChecks(model);
|
||||
@@ -75,6 +77,8 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(InstanceUserRights.WriteUsers)]
|
||||
[ProducesResponseType(typeof(Api.Models.InstanceUser), 200)]
|
||||
[ProducesResponseType(410)]
|
||||
#pragma warning disable CA1506 // TODO: Decomplexify
|
||||
public override async Task<IActionResult> Update([FromBody] Api.Models.InstanceUser model, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -104,10 +108,13 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize]
|
||||
[ProducesResponseType(typeof(Api.Models.InstanceUser), 200)]
|
||||
[ProducesResponseType(404)]
|
||||
public override Task<IActionResult> Read(CancellationToken cancellationToken) => Task.FromResult(AuthenticationContext.InstanceUser != null ? (IActionResult)Json(AuthenticationContext.InstanceUser.ToApi()) : NotFound());
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(InstanceUserRights.ReadUsers)]
|
||||
[ProducesResponseType(typeof(IEnumerable<Api.Models.InstanceUser>), 200)]
|
||||
public override async Task<IActionResult> List(CancellationToken cancellationToken)
|
||||
{
|
||||
var users = await DatabaseContext.Instances.Where(x => x.Id == Instance.Id).SelectMany(x => x.InstanceUsers).ToListAsync(cancellationToken).ConfigureAwait(false);
|
||||
@@ -116,6 +123,8 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(InstanceUserRights.ReadUsers)]
|
||||
[ProducesResponseType(typeof(Api.Models.InstanceUser), 200)]
|
||||
[ProducesResponseType(410)]
|
||||
public override async Task<IActionResult> GetId(long id, CancellationToken cancellationToken)
|
||||
{
|
||||
// this functions as userId
|
||||
@@ -127,6 +136,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(InstanceUserRights.WriteUsers)]
|
||||
[ProducesResponseType(200)]
|
||||
public override async Task<IActionResult> Delete(long id, CancellationToken cancellationToken)
|
||||
{
|
||||
await DatabaseContext.Instances.Where(x => x.Id == Instance.Id).SelectMany(x => x.InstanceUsers).Where(x => x.UserId == id).DeleteAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
@@ -38,6 +39,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize]
|
||||
[ProducesResponseType(typeof(IEnumerable<Api.Models.Job>), 200)]
|
||||
public override async Task<IActionResult> Read(CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await DatabaseContext.Jobs.Where(x => x.Instance.Id == Instance.Id && !x.StoppedAt.HasValue).OrderByDescending(x => x.StartedAt).ToListAsync(cancellationToken).ConfigureAwait(false);
|
||||
@@ -46,6 +48,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize]
|
||||
[ProducesResponseType(typeof(List<Api.Models.Job>), 200)]
|
||||
public override async Task<IActionResult> List(CancellationToken cancellationToken)
|
||||
{
|
||||
// you KNOW this will need pagination eventually right?
|
||||
@@ -58,6 +61,9 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize]
|
||||
[ProducesResponseType(202)]
|
||||
[ProducesResponseType(404)]
|
||||
[ProducesResponseType(410)]
|
||||
public override async Task<IActionResult> Delete(long id, CancellationToken cancellationToken)
|
||||
{
|
||||
// don't care if an instance post or not at this point
|
||||
@@ -77,6 +83,8 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize]
|
||||
[ProducesResponseType(404)]
|
||||
[ProducesResponseType(typeof(Api.Models.Job), 200)]
|
||||
public override async Task<IActionResult> GetId(long id, CancellationToken cancellationToken)
|
||||
{
|
||||
var job = await DatabaseContext.Jobs.Where(x => x.Id == id).Include(x => x.StartedBy).FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
@@ -128,6 +128,8 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(RepositoryRights.SetOrigin)]
|
||||
[ProducesResponseType(typeof(Repository), 201)]
|
||||
[ProducesResponseType(410)]
|
||||
public override async Task<IActionResult> Create([FromBody] Repository model, CancellationToken cancellationToken)
|
||||
{
|
||||
if (model == null)
|
||||
@@ -219,6 +221,8 @@ namespace Tgstation.Server.Host.Controllers
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="IActionResult"/> of the operation</returns>
|
||||
[TgsAuthorize(RepositoryRights.Delete)]
|
||||
[ProducesResponseType(typeof(Repository), 202)]
|
||||
[ProducesResponseType(410)]
|
||||
public async Task<IActionResult> Delete(CancellationToken cancellationToken)
|
||||
{
|
||||
var currentModel = await DatabaseContext.RepositorySettings.Where(x => x.InstanceId == Instance.Id).FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false);
|
||||
@@ -247,6 +251,9 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(RepositoryRights.Read)]
|
||||
[ProducesResponseType(typeof(Repository), 200)]
|
||||
[ProducesResponseType(typeof(Repository), 201)]
|
||||
[ProducesResponseType(410)]
|
||||
public override async Task<IActionResult> Read(CancellationToken cancellationToken)
|
||||
{
|
||||
var currentModel = await DatabaseContext.RepositorySettings.Where(x => x.InstanceId == Instance.Id).FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false);
|
||||
@@ -273,7 +280,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
{
|
||||
if (repo != null && await PopulateApi(api, repo, DatabaseContext, Instance, cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
// user may have fucked with the repo without telling us, do what we can
|
||||
// user may have fucked with the repo manually, do what we can
|
||||
await DatabaseContext.Save(cancellationToken).ConfigureAwait(false);
|
||||
return StatusCode((int)HttpStatusCode.Created, api);
|
||||
}
|
||||
|
||||
@@ -75,6 +75,9 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(AdministrationRights.WriteUsers)]
|
||||
[ProducesResponseType(typeof(Api.Models.User), 201)]
|
||||
[ProducesResponseType(410)]
|
||||
[ProducesResponseType(501)]
|
||||
public override async Task<IActionResult> Create([FromBody] UserUpdate model, CancellationToken cancellationToken)
|
||||
{
|
||||
if (model == null)
|
||||
@@ -139,6 +142,8 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(AdministrationRights.WriteUsers | AdministrationRights.EditOwnPassword)]
|
||||
[ProducesResponseType(typeof(Api.Models.User), 200)]
|
||||
[ProducesResponseType(404)]
|
||||
public override async Task<IActionResult> Update([FromBody] UserUpdate model, CancellationToken cancellationToken)
|
||||
{
|
||||
if (model == null)
|
||||
@@ -187,10 +192,12 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize]
|
||||
[ProducesResponseType(typeof(Api.Models.User), 200)]
|
||||
public override Task<IActionResult> Read(CancellationToken cancellationToken) => Task.FromResult<IActionResult>(Json(AuthenticationContext.User.ToApi(true)));
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(AdministrationRights.ReadUsers)]
|
||||
[ProducesResponseType(typeof(IEnumerable<Api.Models.User>), 200)]
|
||||
public override async Task<IActionResult> List(CancellationToken cancellationToken)
|
||||
{
|
||||
var users = await DatabaseContext.Users
|
||||
@@ -201,6 +208,8 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize]
|
||||
[ProducesResponseType(typeof(Api.Models.User), 200)]
|
||||
[ProducesResponseType(404)]
|
||||
public override async Task<IActionResult> GetId(long id, CancellationToken cancellationToken)
|
||||
{
|
||||
if (id == AuthenticationContext.User.Id)
|
||||
|
||||
Reference in New Issue
Block a user