mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-30 08:33:19 +01:00
Remove IApiConvertable
This commit is contained in:
@@ -118,7 +118,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
await DatabaseContext.Save(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return StatusCode((int)HttpStatusCode.Created, dbUser.ToApi());
|
||||
return StatusCode((int)HttpStatusCode.Created, dbUser.ToApi(true));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -156,19 +156,19 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
await DatabaseContext.Save(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return Json(originalUser.ToApi());
|
||||
return Json(originalUser.ToApi(true));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize]
|
||||
public override Task<IActionResult> Read(CancellationToken cancellationToken) => Task.FromResult<IActionResult>(Json(AuthenticationContext.User.ToApi()));
|
||||
public override Task<IActionResult> Read(CancellationToken cancellationToken) => Task.FromResult<IActionResult>(Json(AuthenticationContext.User.ToApi(true)));
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(AdministrationRights.EditUsers)]
|
||||
public override async Task<IActionResult> List(CancellationToken cancellationToken)
|
||||
{
|
||||
var users = await DatabaseContext.Users.ToListAsync(cancellationToken).ConfigureAwait(false);
|
||||
return Json(users.Select(x => x.ToApi()));
|
||||
return Json(users.Select(x => x.ToApi(true)));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -178,7 +178,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
var user = await DatabaseContext.Users.Where(x => x.Id == id).FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (user == default)
|
||||
return NotFound();
|
||||
return Json(user.ToApi());
|
||||
return Json(user.ToApi(true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Linq;
|
||||
namespace Tgstation.Server.Host.Models
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public sealed class ChatBot : Api.Models.Internal.ChatBot, IApiConvertable<Api.Models.ChatBot>
|
||||
public sealed class ChatBot : Api.Models.Internal.ChatBot
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="Api.Models.Instance.Id"/>
|
||||
@@ -23,7 +23,10 @@ namespace Tgstation.Server.Host.Models
|
||||
/// </summary>
|
||||
public List<ChatChannel> Channels { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Convert the <see cref="ChatBot"/> to it's API form
|
||||
/// </summary>
|
||||
/// <returns>A new <see cref="Api.Models.ChatBot"/></returns>
|
||||
public Api.Models.ChatBot ToApi() => new Api.Models.ChatBot
|
||||
{
|
||||
Channels = Channels.Select(x => x.ToApi()).ToList(),
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace Tgstation.Server.Host.Models
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public sealed class ChatChannel : Api.Models.ChatChannel, IApiConvertable<Api.Models.ChatChannel>
|
||||
public sealed class ChatChannel : Api.Models.ChatChannel
|
||||
{
|
||||
/// <summary>
|
||||
/// The row Id
|
||||
@@ -20,7 +20,10 @@ namespace Tgstation.Server.Host.Models
|
||||
/// </summary>
|
||||
public ChatBot ChatSettings { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Convert the <see cref="ChatChannel"/> to it's API form
|
||||
/// </summary>
|
||||
/// <returns>A new <see cref="Api.Models.ChatChannel"/></returns>
|
||||
public Api.Models.ChatChannel ToApi() => new Api.Models.ChatChannel
|
||||
{
|
||||
DiscordChannelId = DiscordChannelId,
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.ComponentModel.DataAnnotations;
|
||||
namespace Tgstation.Server.Host.Models
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public sealed class CompileJob : Api.Models.Internal.CompileJob, IApiConvertable<Api.Models.CompileJob>
|
||||
public sealed class CompileJob : Api.Models.Internal.CompileJob
|
||||
{
|
||||
/// <summary>
|
||||
/// See <see cref="Api.Models.CompileJob.Job"/>
|
||||
@@ -23,7 +23,10 @@ namespace Tgstation.Server.Host.Models
|
||||
[Required]
|
||||
public string ByondVersion { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Convert the <see cref="CompileJob"/> to it's API form
|
||||
/// </summary>
|
||||
/// <returns>A new <see cref="Api.Models.CompileJob"/></returns>
|
||||
public Api.Models.CompileJob ToApi() => new Api.Models.CompileJob
|
||||
{
|
||||
DirectoryName = DirectoryName,
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
namespace Tgstation.Server.Host.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// For converting models to their API form
|
||||
/// </summary>
|
||||
/// <typeparam name="TModel">Which of the <see cref="Api.Models"/> this model backs</typeparam>
|
||||
public interface IApiConvertable<TModel> where TModel : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Convert the model to it's API form
|
||||
/// </summary>
|
||||
/// <returns>A new <typeparamref name="TModel"/></returns>
|
||||
TModel ToApi();
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace Tgstation.Server.Host.Models
|
||||
/// <summary>
|
||||
/// Represents an <see cref="Api.Models.Instance"/> in the database
|
||||
/// </summary>
|
||||
public sealed class Instance : Api.Models.Instance, IApiConvertable<Api.Models.Instance>
|
||||
public sealed class Instance : Api.Models.Instance
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
@@ -47,8 +47,11 @@ namespace Tgstation.Server.Host.Models
|
||||
/// The <see cref="Jobs"/> in the <see cref="Instance"/>
|
||||
/// </summary>
|
||||
public List<Job> Jobs { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
/// <summary>
|
||||
/// Convert the <see cref="Instance"/> to it's API form
|
||||
/// </summary>
|
||||
/// <returns>A new <see cref="Api.Models.Instance"/></returns>
|
||||
public Api.Models.Instance ToApi() => new Api.Models.Instance
|
||||
{
|
||||
AutoUpdateInterval = AutoUpdateInterval,
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Tgstation.Server.Api.Models;
|
||||
|
||||
namespace Tgstation.Server.Host.Models
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public sealed class InstanceUser : Api.Models.InstanceUser, IApiConvertable<Api.Models.InstanceUser>
|
||||
public sealed class InstanceUser : Api.Models.InstanceUser
|
||||
{
|
||||
/// <summary>
|
||||
/// The row Id
|
||||
@@ -32,7 +31,10 @@ namespace Tgstation.Server.Host.Models
|
||||
DreamMakerRights != Api.Rights.DreamMakerRights.None ||
|
||||
InstanceUserRights != Api.Rights.InstanceUserRights.None;
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Convert the <see cref="InstanceUser"/> to it's API form
|
||||
/// </summary>
|
||||
/// <returns>A new <see cref="Api.Models.InstanceUser"/></returns>
|
||||
public Api.Models.InstanceUser ToApi() => new Api.Models.InstanceUser
|
||||
{
|
||||
ByondRights = ByondRights,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace Tgstation.Server.Host.Models
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public sealed class Job : Api.Models.Internal.Job, IApiConvertable<Api.Models.Job>
|
||||
public sealed class Job : Api.Models.Internal.Job
|
||||
{
|
||||
/// <summary>
|
||||
/// See <see cref="Api.Models.Job.StartedBy"/>
|
||||
@@ -22,19 +22,22 @@ namespace Tgstation.Server.Host.Models
|
||||
[Required]
|
||||
public Instance Instance { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Convert the <see cref="Job"/> to it's API form
|
||||
/// </summary>
|
||||
/// <returns>A new <see cref="Api.Models.Job"/></returns>
|
||||
public Api.Models.Job ToApi() => new Api.Models.Job
|
||||
{
|
||||
Id = Id,
|
||||
StartedAt = StartedAt,
|
||||
StoppedAt = StoppedAt,
|
||||
Cancelled = Cancelled,
|
||||
CancelledBy = CancelledBy?.ToApi(),
|
||||
CancelledBy = CancelledBy?.ToApi(false),
|
||||
CancelRight = CancelRight,
|
||||
CancelRightsType = CancelRightsType,
|
||||
Description = Description,
|
||||
ExceptionDetails = ExceptionDetails,
|
||||
StartedBy = StartedBy.ToApi()
|
||||
StartedBy = StartedBy.ToApi(false)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ using Tgstation.Server.Api.Models;
|
||||
namespace Tgstation.Server.Host.Models
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public sealed class RepositorySettings : Api.Models.Internal.RepositorySettings, IApiConvertable<Repository>
|
||||
public sealed class RepositorySettings : Api.Models.Internal.RepositorySettings
|
||||
{
|
||||
/// <summary>
|
||||
/// The row Id
|
||||
@@ -22,8 +22,11 @@ namespace Tgstation.Server.Host.Models
|
||||
/// </summary>
|
||||
[Required]
|
||||
public Instance Instance { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
/// <summary>
|
||||
/// Convert the <see cref="Repository"/> to it's API form
|
||||
/// </summary>
|
||||
/// <returns>A new <see cref="Api.Models.Repository"/></returns>
|
||||
public Repository ToApi() => new Repository
|
||||
{
|
||||
//AccessToken = AccessToken, //never show this
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Linq;
|
||||
namespace Tgstation.Server.Host.Models
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public sealed class RevisionInformation : Api.Models.Internal.RevisionInformation, IApiConvertable<Api.Models.RevisionInformation>
|
||||
public sealed class RevisionInformation : Api.Models.Internal.RevisionInformation
|
||||
{
|
||||
/// <summary>
|
||||
/// The row Id
|
||||
@@ -33,7 +33,10 @@ namespace Tgstation.Server.Host.Models
|
||||
/// </summary>
|
||||
public List<CompileJob> CompileJobs { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Convert the <see cref="RevisionInformation"/> to it's API form
|
||||
/// </summary>
|
||||
/// <returns>A new <see cref="Api.Models.RevisionInformation"/></returns>
|
||||
public Api.Models.RevisionInformation ToApi() => new Api.Models.RevisionInformation
|
||||
{
|
||||
CommitSha = CommitSha,
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.ComponentModel.DataAnnotations;
|
||||
namespace Tgstation.Server.Host.Models
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public sealed class TestMerge : Api.Models.Internal.TestMerge, IApiConvertable<Api.Models.TestMerge>
|
||||
public sealed class TestMerge : Api.Models.Internal.TestMerge
|
||||
{
|
||||
/// <summary>
|
||||
/// See <see cref="Api.Models.TestMerge.MergedBy"/>
|
||||
@@ -27,7 +27,10 @@ namespace Tgstation.Server.Host.Models
|
||||
/// </summary>
|
||||
public List<RevInfoTestMerge> RevisonInformations { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Convert the <see cref="TestMerge"/> to it's API form
|
||||
/// </summary>
|
||||
/// <returns>A new <see cref="Api.Models.TestMerge"/></returns>
|
||||
public Api.Models.TestMerge ToApi() => new Api.Models.TestMerge
|
||||
{
|
||||
Author = Author,
|
||||
@@ -36,7 +39,7 @@ namespace Tgstation.Server.Host.Models
|
||||
TitleAtMerge = TitleAtMerge,
|
||||
Comment = Comment,
|
||||
Id = Id,
|
||||
MergedBy = MergedBy.ToApi(),
|
||||
MergedBy = MergedBy.ToApi(false),
|
||||
Number =Number,
|
||||
PullRequestRevision = PullRequestRevision,
|
||||
Url = Url
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.ComponentModel.DataAnnotations;
|
||||
namespace Tgstation.Server.Host.Models
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public sealed class User : Api.Models.Internal.User, IApiConvertable<Api.Models.User>
|
||||
public sealed class User : Api.Models.Internal.User
|
||||
{
|
||||
/// <summary>
|
||||
/// The hash of the user's password
|
||||
@@ -44,23 +44,28 @@ namespace Tgstation.Server.Host.Models
|
||||
public List<TestMerge> TestMerges { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// See <see cref="ToApi()"/>
|
||||
/// See <see cref="ToApi(bool)"/>
|
||||
/// </summary>
|
||||
/// <param name="recursive">If we should recurse on <see cref="CreatedBy"/></param>
|
||||
/// <param name="showDetails">If rights and system identifier should be shown</param>
|
||||
/// <returns>A new <see cref="Api.Models.User"/></returns>
|
||||
Api.Models.User ToApi(bool recursive) => new Api.Models.User
|
||||
Api.Models.User ToApi(bool recursive, bool showDetails) => new Api.Models.User
|
||||
{
|
||||
AdministrationRights = AdministrationRights,
|
||||
AdministrationRights = showDetails ? AdministrationRights : null,
|
||||
CreatedAt = CreatedAt,
|
||||
CreatedBy = recursive ? CreatedBy?.ToApi(false) : null,
|
||||
CreatedBy = recursive ? CreatedBy?.ToApi(false, showDetails) : null,
|
||||
Enabled = Enabled,
|
||||
Id = Id,
|
||||
InstanceManagerRights = InstanceManagerRights,
|
||||
InstanceManagerRights = showDetails ? InstanceManagerRights : null,
|
||||
Name = Name,
|
||||
SystemIdentifier = SystemIdentifier
|
||||
SystemIdentifier = showDetails ? SystemIdentifier : null
|
||||
};
|
||||
|
||||
/// <inheritdoc />
|
||||
public Api.Models.User ToApi() => ToApi(true);
|
||||
/// <summary>
|
||||
/// Convert the <see cref="User"/> to it's API form
|
||||
/// </summary>
|
||||
/// <param name="showDetails">If rights and system identifier should be shown</param>
|
||||
/// <returns>A new <see cref="Api.Models.User"/></returns>
|
||||
public Api.Models.User ToApi(bool showDetails) => ToApi(true, showDetails);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,4 @@ Verify the byond cache folder location on linux
|
||||
|
||||
Test watchdog
|
||||
|
||||
Only show user name and ID when serializing to API
|
||||
In fact remove IApiConvertable<> altogether, it's not required by anything
|
||||
|
||||
Test chat channel tagging
|
||||
|
||||
Reference in New Issue
Block a user