From c2483804243ca9ce76ed6b0650891fb63a49ed32 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Mon, 20 Aug 2018 15:31:31 -0400 Subject: [PATCH] Remove IApiConvertable --- .../Controllers/UserController.cs | 10 ++++---- src/Tgstation.Server.Host/Models/ChatBot.cs | 7 ++++-- .../Models/ChatChannel.cs | 7 ++++-- .../Models/CompileJob.cs | 7 ++++-- .../Models/IApiConvertable.cs | 15 ------------ src/Tgstation.Server.Host/Models/Instance.cs | 9 +++++--- .../Models/InstanceUser.cs | 8 ++++--- src/Tgstation.Server.Host/Models/Job.cs | 11 +++++---- .../Models/RepositorySettings.cs | 9 +++++--- .../Models/RevisionInformation.cs | 7 ++++-- src/Tgstation.Server.Host/Models/TestMerge.cs | 9 +++++--- src/Tgstation.Server.Host/Models/User.cs | 23 +++++++++++-------- v4_prototype_TODO.txt | 3 --- 13 files changed, 69 insertions(+), 56 deletions(-) delete mode 100644 src/Tgstation.Server.Host/Models/IApiConvertable.cs diff --git a/src/Tgstation.Server.Host/Controllers/UserController.cs b/src/Tgstation.Server.Host/Controllers/UserController.cs index 8e0b574398..96ceaf0c2f 100644 --- a/src/Tgstation.Server.Host/Controllers/UserController.cs +++ b/src/Tgstation.Server.Host/Controllers/UserController.cs @@ -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)); } /// @@ -156,19 +156,19 @@ namespace Tgstation.Server.Host.Controllers await DatabaseContext.Save(cancellationToken).ConfigureAwait(false); - return Json(originalUser.ToApi()); + return Json(originalUser.ToApi(true)); } /// [TgsAuthorize] - public override Task Read(CancellationToken cancellationToken) => Task.FromResult(Json(AuthenticationContext.User.ToApi())); + public override Task Read(CancellationToken cancellationToken) => Task.FromResult(Json(AuthenticationContext.User.ToApi(true))); /// [TgsAuthorize(AdministrationRights.EditUsers)] public override async Task 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))); } /// @@ -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)); } } } diff --git a/src/Tgstation.Server.Host/Models/ChatBot.cs b/src/Tgstation.Server.Host/Models/ChatBot.cs index 807a31f908..d07a61b80e 100644 --- a/src/Tgstation.Server.Host/Models/ChatBot.cs +++ b/src/Tgstation.Server.Host/Models/ChatBot.cs @@ -5,7 +5,7 @@ using System.Linq; namespace Tgstation.Server.Host.Models { /// - public sealed class ChatBot : Api.Models.Internal.ChatBot, IApiConvertable + public sealed class ChatBot : Api.Models.Internal.ChatBot { /// /// The @@ -23,7 +23,10 @@ namespace Tgstation.Server.Host.Models /// public List Channels { get; set; } - /// + /// + /// Convert the to it's API form + /// + /// A new public Api.Models.ChatBot ToApi() => new Api.Models.ChatBot { Channels = Channels.Select(x => x.ToApi()).ToList(), diff --git a/src/Tgstation.Server.Host/Models/ChatChannel.cs b/src/Tgstation.Server.Host/Models/ChatChannel.cs index c47d117d74..2fe4de19cb 100644 --- a/src/Tgstation.Server.Host/Models/ChatChannel.cs +++ b/src/Tgstation.Server.Host/Models/ChatChannel.cs @@ -3,7 +3,7 @@ namespace Tgstation.Server.Host.Models { /// - public sealed class ChatChannel : Api.Models.ChatChannel, IApiConvertable + public sealed class ChatChannel : Api.Models.ChatChannel { /// /// The row Id @@ -20,7 +20,10 @@ namespace Tgstation.Server.Host.Models /// public ChatBot ChatSettings { get; set; } - /// + /// + /// Convert the to it's API form + /// + /// A new public Api.Models.ChatChannel ToApi() => new Api.Models.ChatChannel { DiscordChannelId = DiscordChannelId, diff --git a/src/Tgstation.Server.Host/Models/CompileJob.cs b/src/Tgstation.Server.Host/Models/CompileJob.cs index 15682ef9ad..22e97759dd 100644 --- a/src/Tgstation.Server.Host/Models/CompileJob.cs +++ b/src/Tgstation.Server.Host/Models/CompileJob.cs @@ -4,7 +4,7 @@ using System.ComponentModel.DataAnnotations; namespace Tgstation.Server.Host.Models { /// - public sealed class CompileJob : Api.Models.Internal.CompileJob, IApiConvertable + public sealed class CompileJob : Api.Models.Internal.CompileJob { /// /// See @@ -23,7 +23,10 @@ namespace Tgstation.Server.Host.Models [Required] public string ByondVersion { get; set; } - /// + /// + /// Convert the to it's API form + /// + /// A new public Api.Models.CompileJob ToApi() => new Api.Models.CompileJob { DirectoryName = DirectoryName, diff --git a/src/Tgstation.Server.Host/Models/IApiConvertable.cs b/src/Tgstation.Server.Host/Models/IApiConvertable.cs deleted file mode 100644 index 3a53bb26c7..0000000000 --- a/src/Tgstation.Server.Host/Models/IApiConvertable.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace Tgstation.Server.Host.Models -{ - /// - /// For converting models to their API form - /// - /// Which of the this model backs - public interface IApiConvertable where TModel : class - { - /// - /// Convert the model to it's API form - /// - /// A new - TModel ToApi(); - } -} \ No newline at end of file diff --git a/src/Tgstation.Server.Host/Models/Instance.cs b/src/Tgstation.Server.Host/Models/Instance.cs index 4c22fd55b8..89662f952b 100644 --- a/src/Tgstation.Server.Host/Models/Instance.cs +++ b/src/Tgstation.Server.Host/Models/Instance.cs @@ -5,7 +5,7 @@ namespace Tgstation.Server.Host.Models /// /// Represents an in the database /// - public sealed class Instance : Api.Models.Instance, IApiConvertable + public sealed class Instance : Api.Models.Instance { /// @@ -47,8 +47,11 @@ namespace Tgstation.Server.Host.Models /// The in the /// public List Jobs { get; set; } - - /// + + /// + /// Convert the to it's API form + /// + /// A new public Api.Models.Instance ToApi() => new Api.Models.Instance { AutoUpdateInterval = AutoUpdateInterval, diff --git a/src/Tgstation.Server.Host/Models/InstanceUser.cs b/src/Tgstation.Server.Host/Models/InstanceUser.cs index 925915f278..35508c4417 100644 --- a/src/Tgstation.Server.Host/Models/InstanceUser.cs +++ b/src/Tgstation.Server.Host/Models/InstanceUser.cs @@ -1,10 +1,9 @@ using System.ComponentModel.DataAnnotations; -using Tgstation.Server.Api.Models; namespace Tgstation.Server.Host.Models { /// - public sealed class InstanceUser : Api.Models.InstanceUser, IApiConvertable + public sealed class InstanceUser : Api.Models.InstanceUser { /// /// The row Id @@ -32,7 +31,10 @@ namespace Tgstation.Server.Host.Models DreamMakerRights != Api.Rights.DreamMakerRights.None || InstanceUserRights != Api.Rights.InstanceUserRights.None; - /// + /// + /// Convert the to it's API form + /// + /// A new public Api.Models.InstanceUser ToApi() => new Api.Models.InstanceUser { ByondRights = ByondRights, diff --git a/src/Tgstation.Server.Host/Models/Job.cs b/src/Tgstation.Server.Host/Models/Job.cs index 0b56cca428..aeb31c0d0e 100644 --- a/src/Tgstation.Server.Host/Models/Job.cs +++ b/src/Tgstation.Server.Host/Models/Job.cs @@ -3,7 +3,7 @@ namespace Tgstation.Server.Host.Models { /// - public sealed class Job : Api.Models.Internal.Job, IApiConvertable + public sealed class Job : Api.Models.Internal.Job { /// /// See @@ -22,19 +22,22 @@ namespace Tgstation.Server.Host.Models [Required] public Instance Instance { get; set; } - /// + /// + /// Convert the to it's API form + /// + /// A new 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) }; } } diff --git a/src/Tgstation.Server.Host/Models/RepositorySettings.cs b/src/Tgstation.Server.Host/Models/RepositorySettings.cs index f4fa66bbf6..969e1ebb69 100644 --- a/src/Tgstation.Server.Host/Models/RepositorySettings.cs +++ b/src/Tgstation.Server.Host/Models/RepositorySettings.cs @@ -5,7 +5,7 @@ using Tgstation.Server.Api.Models; namespace Tgstation.Server.Host.Models { /// - public sealed class RepositorySettings : Api.Models.Internal.RepositorySettings, IApiConvertable + public sealed class RepositorySettings : Api.Models.Internal.RepositorySettings { /// /// The row Id @@ -22,8 +22,11 @@ namespace Tgstation.Server.Host.Models /// [Required] public Instance Instance { get; set; } - - /// + + /// + /// Convert the to it's API form + /// + /// A new public Repository ToApi() => new Repository { //AccessToken = AccessToken, //never show this diff --git a/src/Tgstation.Server.Host/Models/RevisionInformation.cs b/src/Tgstation.Server.Host/Models/RevisionInformation.cs index 26ad23a215..3f2fda9492 100644 --- a/src/Tgstation.Server.Host/Models/RevisionInformation.cs +++ b/src/Tgstation.Server.Host/Models/RevisionInformation.cs @@ -5,7 +5,7 @@ using System.Linq; namespace Tgstation.Server.Host.Models { /// - public sealed class RevisionInformation : Api.Models.Internal.RevisionInformation, IApiConvertable + public sealed class RevisionInformation : Api.Models.Internal.RevisionInformation { /// /// The row Id @@ -33,7 +33,10 @@ namespace Tgstation.Server.Host.Models /// public List CompileJobs { get; set; } - /// + /// + /// Convert the to it's API form + /// + /// A new public Api.Models.RevisionInformation ToApi() => new Api.Models.RevisionInformation { CommitSha = CommitSha, diff --git a/src/Tgstation.Server.Host/Models/TestMerge.cs b/src/Tgstation.Server.Host/Models/TestMerge.cs index 2428a192a5..94a13aa767 100644 --- a/src/Tgstation.Server.Host/Models/TestMerge.cs +++ b/src/Tgstation.Server.Host/Models/TestMerge.cs @@ -4,7 +4,7 @@ using System.ComponentModel.DataAnnotations; namespace Tgstation.Server.Host.Models { /// - public sealed class TestMerge : Api.Models.Internal.TestMerge, IApiConvertable + public sealed class TestMerge : Api.Models.Internal.TestMerge { /// /// See @@ -27,7 +27,10 @@ namespace Tgstation.Server.Host.Models /// public List RevisonInformations { get; set; } - /// + /// + /// Convert the to it's API form + /// + /// A new 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 diff --git a/src/Tgstation.Server.Host/Models/User.cs b/src/Tgstation.Server.Host/Models/User.cs index 17432de245..b7032bd98b 100644 --- a/src/Tgstation.Server.Host/Models/User.cs +++ b/src/Tgstation.Server.Host/Models/User.cs @@ -5,7 +5,7 @@ using System.ComponentModel.DataAnnotations; namespace Tgstation.Server.Host.Models { /// - public sealed class User : Api.Models.Internal.User, IApiConvertable + public sealed class User : Api.Models.Internal.User { /// /// The hash of the user's password @@ -44,23 +44,28 @@ namespace Tgstation.Server.Host.Models public List TestMerges { get; set; } /// - /// See + /// See /// /// If we should recurse on + /// If rights and system identifier should be shown /// A new - 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 }; - /// - public Api.Models.User ToApi() => ToApi(true); + /// + /// Convert the to it's API form + /// + /// If rights and system identifier should be shown + /// A new + public Api.Models.User ToApi(bool showDetails) => ToApi(true, showDetails); } } diff --git a/v4_prototype_TODO.txt b/v4_prototype_TODO.txt index 3fe204864c..b8c6c5719b 100644 --- a/v4_prototype_TODO.txt +++ b/v4_prototype_TODO.txt @@ -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