From 2afa64df98ccb6df8c1690cbd42d5c3f6e6d6b89 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Wed, 4 Apr 2018 16:02:53 -0400 Subject: [PATCH] Finish up the configuration stuff --- .../Models/Configuration.cs | 40 +++++++++++++++++++ src/Tgstation.Server.Api/Models/DreamMaker.cs | 6 +++ .../Rights/ConfigurationRights.cs | 28 +++++++++++++ .../Rights/DreamMakerRights.cs | 4 ++ src/Tgstation.Server.Api/RouteHelper.cs | 36 ++++++++++++++++- 5 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 src/Tgstation.Server.Api/Models/Configuration.cs create mode 100644 src/Tgstation.Server.Api/Rights/ConfigurationRights.cs diff --git a/src/Tgstation.Server.Api/Models/Configuration.cs b/src/Tgstation.Server.Api/Models/Configuration.cs new file mode 100644 index 0000000000..198956a00d --- /dev/null +++ b/src/Tgstation.Server.Api/Models/Configuration.cs @@ -0,0 +1,40 @@ +using Tgstation.Server.Api.Rights; + +namespace Tgstation.Server.Api.Models +{ + /// + /// Represents a static game file. Create and delete actions uncerimonuously overwrite/delete files + /// + [Model(RightsType.Configuration, CanCrud = true, CanList = true, RequiresInstance = true, ReadRight = ConfigurationRights.Read, WriteRight = ConfigurationRights.Write)] + public sealed class Configuration + { + /// + /// The path to the file + /// + public string Path { get; set; } + + /// + /// If read access to the file was denied + /// + [Permissions(DenyWrite = true)] + public bool ReadDenied { get; set; } + + /// + /// If represents a directory. Will only be if is + /// + [Permissions(DenyWrite = true)] + public bool IsDirectory { get; set; } + + /// + /// The content of the file. Will be if is or during listing operations + /// +#pragma warning disable CA1819 // Properties should not return arrays + public byte[] Content { get; set; } +#pragma warning restore CA1819 // Properties should not return arrays + + /// + /// The MD5 hash of the file when last read by the user. Will be if is . If this doesn't match during update actions, the write will be denied + /// + public string LastReadHash { get; set; } + } +} diff --git a/src/Tgstation.Server.Api/Models/DreamMaker.cs b/src/Tgstation.Server.Api/Models/DreamMaker.cs index ca1baaea6d..e8a093f5a6 100644 --- a/src/Tgstation.Server.Api/Models/DreamMaker.cs +++ b/src/Tgstation.Server.Api/Models/DreamMaker.cs @@ -55,5 +55,11 @@ namespace Tgstation.Server.Api.Models /// [Permissions(WriteRight = DreamMakerRights.SetAutoCompile)] public int? AutoCompileInterval { get; set; } + + /// + /// The .dme file tries to compile with + /// + [Permissions(WriteRight = DreamMakerRights.SetDme)] + public string TargetDme { get; set; } } } diff --git a/src/Tgstation.Server.Api/Rights/ConfigurationRights.cs b/src/Tgstation.Server.Api/Rights/ConfigurationRights.cs new file mode 100644 index 0000000000..1246644afe --- /dev/null +++ b/src/Tgstation.Server.Api/Rights/ConfigurationRights.cs @@ -0,0 +1,28 @@ +using System; + +namespace Tgstation.Server.Api.Rights +{ + /// + /// Rights for + /// + [Flags] + public enum ConfigurationRights + { + /// + /// User has no rights + /// + None = 0, + /// + /// User may read files + /// + Read = 1, + /// + /// User may write files + /// + Write = 2, + /// + /// User may list files + /// + List = 3 + } +} diff --git a/src/Tgstation.Server.Api/Rights/DreamMakerRights.cs b/src/Tgstation.Server.Api/Rights/DreamMakerRights.cs index 77dd9b3bae..f770f8c01e 100644 --- a/src/Tgstation.Server.Api/Rights/DreamMakerRights.cs +++ b/src/Tgstation.Server.Api/Rights/DreamMakerRights.cs @@ -28,5 +28,9 @@ namespace Tgstation.Server.Api.Rights /// User may modify /// SetAutoCompile = 8, + /// + /// User may modify + /// + SetDme = 16 } } diff --git a/src/Tgstation.Server.Api/RouteHelper.cs b/src/Tgstation.Server.Api/RouteHelper.cs index 1d78cf485c..b833a3f630 100644 --- a/src/Tgstation.Server.Api/RouteHelper.cs +++ b/src/Tgstation.Server.Api/RouteHelper.cs @@ -99,7 +99,7 @@ namespace Tgstation.Server.Api /// Get the to a given 's token list /// /// The to list tokens for - /// A to the get action + /// A to the list action public static Route ListUserTokens(User user) { var result = List(null); @@ -112,5 +112,39 @@ namespace Tgstation.Server.Api /// /// public static Route ServerVersion() => new Route { Path = "/", Method = HttpMethod.Get }; + + /// + /// Get the to read a file + /// + /// The the file resides in + /// The path to the file in the directory + /// A to the read action + public static Route ReadFile(Instance instance, string path) => new Route { Path = String.Concat("/Configuration/", instance?.Id ?? throw new ArgumentNullException(nameof(instance)), '/', path?.TrimStart('/') ?? throw new ArgumentNullException(nameof(path))), Method = HttpMethod.Get }; + + /// + /// Get the to create a file + /// + /// The the file resides in + /// The path to the file in the directory + /// A to the create action + public static Route CreateFile(Instance instance, string path) + { + var result = ReadFile(instance, path); + result.Method = HttpMethod.Put; + return result; + } + + /// + /// Get the to delete a file + /// + /// The the file resides in + /// The path to the file in the directory + /// A to the delete action + public static Route DeleteFile(Instance instance, string path) + { + var result = ReadFile(instance, path); + result.Method = HttpMethod.Delete; + return result; + } } }