Removes ModelAttribute and Permissions Attribute

Ancient prototypes gone astray
This commit is contained in:
Cyberboss
2018-08-20 15:38:34 -04:00
parent 513ad1127d
commit eaf079f467
23 changed files with 1 additions and 205 deletions
@@ -1,53 +0,0 @@
using System;
using Tgstation.Server.Api.Rights;
namespace Tgstation.Server.Api
{
/// <summary>
/// Indicates the rights <see cref="Enum"/> for a model
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public sealed class ModelAttribute : Attribute
{
/// <summary>
/// Right required to read the model
/// </summary>
public object ReadRight { get; set; }
/// <summary>
/// Right required to update the model
/// </summary>
public object WriteRight { get; set; }
/// <summary>
/// If the Create and Delete actions are available for this model
/// </summary>
public bool CanCrud { get; set; }
/// <summary>
/// If the List action is available for this model
/// </summary>
public bool CanList { get; set; }
/// <summary>
/// If the actions require an <see cref="Models.Instance.Id"/>
/// </summary>
public bool RequiresInstance { get; set; }
/// <summary>
/// The <see cref="Rights.RightsType"/> the model uses
/// </summary>
public RightsType RightsType { get; }
/// <summary>
/// Construct a <see cref="ModelAttribute"/>
/// </summary>
public ModelAttribute() => CanList = true;
/// <summary>
/// Construct a <see cref="ModelAttribute"/> with a given <paramref name="rightsType"/>
/// </summary>
/// <param name="rightsType">The value of <see cref="RightsType"/></param>
public ModelAttribute(RightsType rightsType) => RightsType = rightsType;
}
}
@@ -9,25 +9,21 @@ namespace Tgstation.Server.Api.Models
/// <summary>
/// If the server is running on a windows operating system
/// </summary>
[Permissions(DenyWrite = true)]
public bool WindowsHost { get; set; }
/// <summary>
/// The GitHub repository the server is built to recieve updates from
/// </summary>
[Permissions(DenyWrite = true)]
public Uri TrackedRepositoryUrl { get; set; }
/// <summary>
/// The latest available version of the Tgstation.Server.Host assembly from the upstream repository. If <see cref="Version.Minor"/> is higher than <see cref="NewVersion"/>'s the update cannot be applied due to API changes
/// </summary>
[Permissions(DenyWrite = true)]
public Version LatestVersion { get; set; }
/// <summary>
/// Changes the version of Tgstation.Server.Host to the given version from the upstream repository
/// </summary>
[Permissions(WriteRight = AdministrationRights.ChangeVersion)]
public Version NewVersion { get; set; }
}
}
-3
View File
@@ -6,19 +6,16 @@ namespace Tgstation.Server.Api.Models
/// <summary>
/// Represents a BYOND installation
/// </summary>
[Model(RightsType.Byond, RequiresInstance = true)]
public sealed class Byond
{
/// <summary>
/// The <see cref="System.Version"/> of the <see cref="Byond"/> installation used for new compiles. Will be <see langword="null"/> if the user does not have permission to view it or there is no BYOND version installed. Only considers the <see cref="Version.Major"/> and <see cref="Version.Minor"/> numbers
/// </summary>
[Permissions(ReadRight = ByondRights.ReadActive, WriteRight = ByondRights.ChangeVersion)]
public Version Version { get; set; }
/// <summary>
/// The <see cref="Job"/> being used to install a new <see cref="Version"/>
/// </summary>
[Permissions(DenyWrite = true)]
public Job InstallJob { get; set; }
}
}
@@ -11,7 +11,6 @@ namespace Tgstation.Server.Api.Models
/// <summary>
/// Channels the Discord bot should listen/announce in
/// </summary>
[Permissions(WriteRight = ChatBotRights.WriteChannels)]
public List<ChatChannel> Channels { get; set; }
/// <summary>
@@ -6,31 +6,26 @@ namespace Tgstation.Server.Api.Models
/// <summary>
/// Represents a game configuration file. Create and delete actions uncerimonuously overwrite/delete files
/// </summary>
[Model(RightsType.Configuration, CanCrud = true, CanList = true, RequiresInstance = true, ReadRight = ConfigurationRights.Read, WriteRight = ConfigurationRights.Write)]
public sealed class ConfigurationFile
{
/// <summary>
/// The path to the <see cref="ConfigurationFile"/> file
/// </summary>
[Permissions(DenyWrite = true)]
public string Path { get; set; }
/// <summary>
/// If access to the <see cref="ConfigurationFile"/> file was denied for the operation
/// </summary>
[Permissions(DenyWrite = true)]
public bool? AccessDenied { get; set; }
/// <summary>
/// If <see cref="Path"/> represents a directory
/// </summary>
[Permissions(DenyWrite = true)]
public bool? IsDirectory { get; set; }
/// <summary>
/// The MD5 hash of the file when last read by the user. If this doesn't match during update actions, the write will be denied with <see cref="System.Net.HttpStatusCode.Conflict"/>
/// </summary>
[Permissions(DenyWrite = true)]
public string LastReadHash { get; set; }
/// <summary>
@@ -11,37 +11,31 @@ namespace Tgstation.Server.Api.Models
/// <summary>
/// The live revision
/// </summary>
[Permissions(DenyWrite = true, ReadRight = DreamDaemonRights.ReadRevision)]
public CompileJob ActiveCompileJob { get; set; }
/// <summary>
/// The next revision to go live
/// </summary>
[Permissions(DenyWrite = true, ReadRight = DreamDaemonRights.ReadRevision)]
public CompileJob StagedCompileJob { get; set; }
/// <summary>
/// The current status of <see cref="DreamDaemon"/>
/// </summary>
[Permissions(DenyWrite = true, ReadRight = DreamDaemonRights.ReadMetadata)]
public bool? Running { get; set; }
/// <summary>
/// The current <see cref="DreamDaemonSecurity"/> of <see cref="DreamDaemon"/>
/// </summary>
[Permissions(DenyWrite = true, ReadRight = DreamDaemonRights.ReadMetadata)]
public DreamDaemonSecurity? CurrentSecurity { get; set; }
/// <summary>
/// The port the running <see cref="DreamDaemon"/> instance is set to
/// </summary>
[Permissions(DenyWrite = true, ReadRight = DreamDaemonRights.ReadMetadata)]
public ushort? CurrentPort { get; set; }
/// <summary>
/// The webclient status the running <see cref="DreamDaemon"/> instance is set to
/// </summary>
[Permissions(DenyWrite = true, ReadRight = DreamDaemonRights.ReadMetadata)]
public bool? CurrentAllowWebclient { get; set; }
}
}
@@ -10,7 +10,6 @@ namespace Tgstation.Server.Api.Models
/// <summary>
/// The <see cref="CompilerStatus"/> of the compiler
/// </summary>
[Permissions(DenyWrite = true)]
public CompilerStatus Status { get; set; }
}
}
@@ -7,52 +7,44 @@ namespace Tgstation.Server.Api.Models
/// <summary>
/// Metadata about a server instance
/// </summary>
[Model(RightsType.InstanceManager, CanCrud = true, CanList = true)]
public class Instance
{
/// <summary>
/// The id of the <see cref="Instance"/>. Not modifiable
/// </summary>
[Permissions(DenyWrite = true)]
public long Id { get; set; }
/// <summary>
/// The name of the <see cref="Instance"/>
/// </summary>
[Permissions(WriteRight = InstanceManagerRights.Rename)]
[Required]
public string Name { get; set; }
/// <summary>
/// The path to where the <see cref="Instance"/> is located. Can only be changed while the <see cref="Instance"/> is offline. Must not exist when the instance is created
/// </summary>
[Permissions(WriteRight = InstanceManagerRights.Relocate)]
[Required]
public string Path { get; set; }
/// <summary>
/// If the <see cref="Instance"/> is online
/// </summary>
[Permissions(WriteRight = InstanceManagerRights.SetOnline)]
public bool? Online { get; set; }
/// <summary>
/// If <see cref="ConfigurationFile"/> can be used on the <see cref="Instance"/>
/// </summary>
[Permissions(WriteRight = InstanceManagerRights.SetConfiguration)]
[Required]
public ConfigurationType? ConfigurationType { get; set; }
/// <summary>
/// The time interval in minutes the repository is automatically pulled and compiles
/// </summary>
[Permissions(WriteRight = InstanceManagerRights.SetAutoUpdate)]
public int? AutoUpdateInterval { get; set; }
/// <summary>
/// The <see cref="Job"/> representing a change of <see cref="Path"/>
/// </summary>
[Permissions(DenyWrite = true)]
[NotMapped]
public Job MoveJob { get; set; }
@@ -6,13 +6,11 @@ namespace Tgstation.Server.Api.Models
/// <summary>
/// Represents a <see cref="User"/>s permissions in an <see cref="Instance"/>
/// </summary>
[Model(RightsType.InstanceUser, WriteRight = Rights.InstanceUserRights.WriteUsers, CanList = true, RequiresInstance = true)]
public class InstanceUser
{
/// <summary>
/// The <see cref="Internal.User.Id"/> of the <see cref="User"/> the <see cref="InstanceUser"/> belongs to
/// </summary>
[Permissions(DenyWrite = true)]
[Required]
public long? UserId { get; set; }
@@ -6,38 +6,32 @@ namespace Tgstation.Server.Api.Models.Internal
/// <summary>
/// Manage the server chat bots
/// </summary>
[Model(RightsType.ChatBots, RequiresInstance = true, CanList = true, CanCrud = true, ReadRight = ChatBotRights.Read)]
public class ChatBot
{
/// <summary>
/// The settings id
/// </summary>
[Permissions(DenyWrite = true)]
public long Id { get; set; }
/// <summary>
/// The name of the connection
/// </summary>
[Permissions(WriteRight = ChatBotRights.WriteName)]
[Required]
public string Name { get; set; }
/// <summary>
/// If the connection is enabled
/// </summary>
[Permissions(WriteRight = ChatBotRights.WriteEnabled)]
public bool? Enabled { get; set; }
/// <summary>
/// The <see cref="ChatProvider"/> used for the connection
/// </summary>
[Permissions(WriteRight = ChatBotRights.WriteProvider)]
public ChatProvider? Provider { get; set; }
/// <summary>
/// The information used to connect to the <see cref="Provider"/>
/// </summary>
[Permissions(ReadRight = ChatBotRights.ReadConnectionString, WriteRight = ChatBotRights.ReadConnectionString)]
[Required]
public string ConnectionString { get; set; }
}
@@ -6,41 +6,35 @@ namespace Tgstation.Server.Api.Models.Internal
/// <summary>
/// Launch settings for DreamDaemon
/// </summary>
[Model(RightsType.DreamDaemon, CanCrud = true, RequiresInstance = true)]
public class DreamDaemonLaunchParameters
{
/// <summary>
/// If the BYOND web client can be used to connect to the game server
/// </summary>
[Permissions(ReadRight = DreamDaemonRights.ReadMetadata, WriteRight = DreamDaemonRights.SetWebClient)]
[Required]
public bool? AllowWebClient { get; set; }
/// <summary>
/// The <see cref="DreamDaemonSecurity"/> level of <see cref="DreamDaemon"/>
/// </summary>
[Permissions(ReadRight = DreamDaemonRights.ReadMetadata, WriteRight = DreamDaemonRights.SetSecurity)]
[Required]
public DreamDaemonSecurity? SecurityLevel { get; set; }
/// <summary>
/// The first port <see cref="DreamDaemon"/> uses. This should be the publically advertised port
/// </summary>
[Permissions(ReadRight = DreamDaemonRights.ReadMetadata, WriteRight = DreamDaemonRights.SetPorts)]
[Required]
public ushort? PrimaryPort { get; set; }
/// <summary>
/// The second port <see cref="DreamDaemon"/> uses
/// </summary>
[Permissions(ReadRight = DreamDaemonRights.ReadMetadata, WriteRight = DreamDaemonRights.SetPorts)]
[Required]
public ushort? SecondaryPort { get; set; }
/// <summary>
/// The DreamDaemon startup timeout in seconds
/// </summary>
[Permissions(ReadRight = DreamDaemonRights.ReadMetadata, WriteRight = DreamDaemonRights.SetStartupTimeout)]
[Required]
public uint? StartupTimeout { get; set; }
}
@@ -11,21 +11,18 @@ namespace Tgstation.Server.Api.Models.Internal
/// <summary>
/// If <see cref="DreamDaemon"/> starts when it's <see cref="Instance"/> starts
/// </summary>
[Permissions(ReadRight = DreamDaemonRights.ReadMetadata, WriteRight = DreamDaemonRights.SetAutoStart)]
[Required]
public bool? AutoStart { get; set; }
/// <summary>
/// If the server is undergoing a soft reset. This may be automatically set by changes to other fields
/// </summary>
[Permissions(ReadRight = DreamDaemonRights.ReadMetadata, WriteRight = DreamDaemonRights.SoftRestart)]
[Required]
public bool? SoftRestart { get; set; }
/// <summary>
/// If the server is undergoing a soft shutdown
/// </summary>
[Permissions(ReadRight = DreamDaemonRights.ReadMetadata, WriteRight = DreamDaemonRights.SoftShutdown)]
[Required]
public bool? SoftShutdown { get; set; }
}
@@ -6,19 +6,16 @@ namespace Tgstation.Server.Api.Models.Internal
/// <summary>
/// Configurable settings for <see cref="DreamMaker"/>
/// </summary>
[Model(RightsType.DreamMaker, ReadRight = DreamMakerRights.Read, CanCrud = true, RequiresInstance = true)]
public class DreamMakerSettings
{
/// <summary>
/// The .dme file <see cref="DreamMakerSettings"/> tries to compile with without the extension
/// </summary>
[Permissions(WriteRight = DreamMakerRights.SetDme)]
public string ProjectName { get; set; }
/// <summary>
/// The port used during compilation to validate the TGS API
/// The port used during compilation to validate the DMAPI
/// </summary>
[Permissions(WriteRight = DreamMakerRights.SetApiValidationPort)]
[Required]
public ushort? ApiValidationPort { get; set; }
}
@@ -7,58 +7,49 @@ namespace Tgstation.Server.Api.Models.Internal
/// <summary>
/// Represents a long running job
/// </summary>
[Model(RequiresInstance = true)]
public class Job
{
/// <summary>
/// The <see cref="Job"/> ID
/// </summary>
[Permissions(DenyWrite = true)]
public long Id { get; set; }
/// <summary>
/// English description of the <see cref="Job"/>
/// </summary>
[Permissions(DenyWrite = true)]
[Required]
public string Description { get; set; }
/// <summary>
/// Details of any exceptions caught during the <see cref="Job"/>
/// </summary>
[Permissions(DenyWrite = true)]
public string ExceptionDetails { get; set; }
/// <summary>
/// When the <see cref="Job"/> was started
/// </summary>
[Permissions(DenyWrite = true)]
[Required]
public DateTimeOffset? StartedAt { get; set; }
/// <summary>
/// When the <see cref="Job"/> stopped
/// </summary>
[Permissions(DenyWrite = true)]
public DateTimeOffset? StoppedAt { get; set; }
/// <summary>
/// If the <see cref="Job"/> was cancelled
/// </summary>
[Permissions(DenyWrite = true)]
[Required]
public bool? Cancelled { get; set; }
/// <summary>
/// The <see cref="RightsType"/> of <see cref="CancelRight"/> if it can be cancelled
/// </summary>
[Permissions(DenyWrite = true)]
public RightsType? CancelRightsType { get; set; }
/// <summary>
/// The <see cref="Rights"/> required to cancel the <see cref="Job"/>
/// </summary>
[Permissions(DenyWrite = true)]
public ulong? CancelRight { get; set; }
}
}
@@ -6,60 +6,51 @@ namespace Tgstation.Server.Api.Models.Internal
/// <summary>
/// Represents configurable settings for a <see cref="Repository"/>
/// </summary>
[Model(RightsType.Repository, ReadRight = RepositoryRights.Read, RequiresInstance = true)]
public class RepositorySettings
{
/// <summary>
/// The name of the committer
/// </summary>
[Permissions(WriteRight = RepositoryRights.ChangeCommitter)]
[Required]
public string CommitterName { get; set; }
/// <summary>
/// The e-mail of the committer
/// </summary>
[Permissions(WriteRight = RepositoryRights.ChangeCommitter)]
[Required]
public string CommitterEmail { get; set; }
/// <summary>
/// The username to access the git repository with
/// </summary>
[Permissions(ReadRight = RepositoryRights.ChangeCredentials, WriteRight = RepositoryRights.ChangeCredentials)]
public string AccessUser { get; set; }
/// <summary>
/// The token/password to access the git repository with
/// </summary>
[Permissions(ReadRight = RepositoryRights.ChangeCredentials, WriteRight = RepositoryRights.ChangeCredentials)]
public string AccessToken { get; set; }
/// <summary>
/// If commits created from testmerges are pushed to the remote
/// </summary>
[Permissions(WriteRight = RepositoryRights.ChangeTestMergeCommits)]
[Required]
public bool? PushTestMergeCommits { get; set; }
/// <summary>
/// If test merge commits are signed with the username of the person who merged it. Note this only affects future commits
/// </summary>
[Permissions(WriteRight = RepositoryRights.ChangeTestMergeCommits)]
[Required]
public bool? ShowTestMergeCommitters { get; set; }
/// <summary>
/// If test merge commits should be kept when auto updating. May cause merge conflicts which will block the update
/// </summary>
[Permissions(WriteRight = RepositoryRights.ChangeTestMergeCommits)]
[Required]
public bool? AutoUpdatesKeepTestMerges { get; set; }
/// <summary>
/// If synchronization should occur when auto updating
/// </summary>
[Permissions(WriteRight = RepositoryRights.ChangeTestMergeCommits)]
[Required]
public bool? AutoUpdatesSynchronize { get; set; }
}
@@ -10,14 +10,12 @@ namespace Tgstation.Server.Api.Models.Internal
/// <summary>
/// The revision sha
/// </summary>
[Permissions(DenyWrite = true)]
[Required, StringLength(40)]
public string CommitSha { get; set; }
/// <summary>
/// The sha of the most recent remote commit
/// </summary>
[Permissions(DenyWrite = true)]
[Required, StringLength(40)]
public string OriginCommitSha { get; set; }
}
@@ -7,13 +7,11 @@ namespace Tgstation.Server.Api.Models.Internal
/// <summary>
/// Represents a server <see cref="User"/>
/// </summary>
[Model(RightsType.Administration, WriteRight = Rights.AdministrationRights.EditUsers, CanCrud = true)]
public class User
{
/// <summary>
/// The ID of the <see cref="User"/>
/// </summary>
[Permissions(DenyWrite = true)]
public long Id { get; set; }
/// <summary>
@@ -25,14 +23,12 @@ namespace Tgstation.Server.Api.Models.Internal
/// <summary>
/// When the <see cref="User"/> was created
/// </summary>
[Permissions(DenyWrite = true)]
[Required]
public DateTimeOffset? CreatedAt { get; set; }
/// <summary>
/// The SID/UID of the <see cref="User"/> on Windows/POSIX respectively
/// </summary>
[Permissions(DenyWrite = true)]
public string SystemIdentifier { get; set; }
/// <summary>
-2
View File
@@ -8,13 +8,11 @@
/// <summary>
/// The <see cref="User"/> that started the job
/// </summary>
[Permissions(DenyWrite = true)]
public User StartedBy { get; set; }
/// <summary>
/// The <see cref="User"/> that cancelled the job
/// </summary>
[Permissions(DenyWrite = true)]
public User CancelledBy { get; set; }
/// <summary>
@@ -11,49 +11,41 @@ namespace Tgstation.Server.Api.Models
/// <summary>
/// The origin URL. If <see langword="null"/>, the <see cref="Repository"/> does not exist
/// </summary>
[Permissions(WriteRight = RepositoryRights.SetOrigin)]
public string Origin { get; set; }
/// <summary>
/// The commit HEAD should point to. Not populated in responses, use <see cref="RevisionInformation"/> instead for retrieval
/// </summary>
[Permissions(WriteRight = RepositoryRights.SetSha)]
public string CheckoutSha { get; set; }
/// <summary>
/// The current <see cref="Models.RevisionInformation"/> for the <see cref="Repository"/>
/// </summary>
[Permissions(DenyWrite = true)]
public RevisionInformation RevisionInformation { get; set; }
/// <summary>
/// If the repository was cloned from GitHub.com. If <see langword="true"/> this enables test merge functionality
/// </summary>
[Permissions(DenyWrite = true)]
public bool? IsGitHub { get; set; }
/// <summary>
/// The <see cref="Job"/> started by the <see cref="Repository"/> if any
/// </summary>
[Permissions(DenyWrite = true)]
public Job ActiveJob { get; set; }
/// <summary>
/// Do the equivalent of a git pull. Will attempt to merge unless <see cref="Reference"/> is also specified in which case a hard reset will be performed after checking out
/// </summary>
[Permissions(WriteRight = RepositoryRights.UpdateBranch)]
public bool? UpdateFromOrigin { get; set; }
/// <summary>
/// The branch or tag HEAD points to
/// </summary>
[Permissions(WriteRight = RepositoryRights.SetReference)]
public string Reference { get; set; }
/// <summary>
/// <see cref="TestMergeParameters"/> for new <see cref="TestMerge"/>s. Note that merges that conflict will not be performed
/// </summary>
[Permissions(WriteRight = RepositoryRights.MergePullRequest)]
public List<TestMergeParameters> NewTestMerges { get; set; }
}
}
-1
View File
@@ -16,7 +16,6 @@
/// <summary>
/// The <see cref="User"/> who created this <see cref="User"/>
/// </summary>
[Permissions(DenyWrite = true)]
public User CreatedBy { get; set; }
}
}
@@ -1,26 +0,0 @@
using System;
namespace Tgstation.Server.Api
{
/// <summary>
/// Indicates permissions for model fields
/// </summary>
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public sealed class PermissionsAttribute : Attribute
{
/// <summary>
/// Right required to read the field
/// </summary>
public object ReadRight { get; set; }
/// <summary>
/// Right required to update the field
/// </summary>
public object WriteRight { get; set; }
/// <summary>
/// If the field cannot be written to
/// </summary>
public bool DenyWrite { get; set; }
}
}
@@ -15,11 +15,6 @@ namespace Tgstation.Server.Host.Controllers
/// <typeparam name="TModel">The model being represented</typeparam>
public abstract class ModelController<TModel> : ApiController where TModel : class
{
/// <summary>
/// The <see cref="ModelAttribute"/> of the <typeparamref name="TModel"/>
/// </summary>
protected static readonly ModelAttribute ModelAttribute = (ModelAttribute)typeof(TModel).GetCustomAttributes(typeof(ModelAttribute), true).First();
/// <summary>
/// Construct a <see cref="ModelController{TModel}"/>
/// </summary>
@@ -1,37 +0,0 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Tgstation.Server.Api.Tests
{
[TestClass]
public sealed class TestModels
{
static IEnumerable<Tuple<Type, ModelAttribute>> Models()
{
var modelAttributeType = typeof(ModelAttribute);
var targetAssembly = modelAttributeType.Assembly;
foreach(var I in targetAssembly.GetTypes())
{
var attr = (ModelAttribute)I.GetCustomAttributes(modelAttributeType, false).FirstOrDefault();
if (attr != default(ModelAttribute))
yield return new Tuple<Type, ModelAttribute>(I, attr);
}
}
[TestMethod]
public void TestModelsPropertiesPermissions()
{
var permissionsAttributeType = typeof(PermissionsAttribute);
foreach (var I in Models())
{
foreach (var J in I.Item1.GetProperties())
{
var perm = (PermissionsAttribute)J.GetCustomAttributes(permissionsAttributeType, false).FirstOrDefault();
}
}
}
}
}