2017-03-08 23:58:58 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
2016-10-07 13:00:42 +00:00
|
|
|
|
using System.Diagnostics;
|
2016-09-20 01:08:28 +00:00
|
|
|
|
|
|
|
|
|
namespace NadekoBot.Services.Database.Models
|
|
|
|
|
{
|
2016-10-07 13:00:42 +00:00
|
|
|
|
[DebuggerDisplay("{global::NadekoBot.Modules.Permissions.PermissionExtensions.GetCommand(this)}", Target = typeof(Permission))]
|
2016-09-20 01:08:28 +00:00
|
|
|
|
public class Permission : DbEntity
|
|
|
|
|
{
|
2016-09-27 13:26:37 +00:00
|
|
|
|
public Permission Previous { get; set; } = null;
|
|
|
|
|
public Permission Next { get; set; } = null;
|
|
|
|
|
|
2016-09-22 18:53:49 +00:00
|
|
|
|
public PrimaryPermissionType PrimaryTarget { get; set; }
|
|
|
|
|
public ulong PrimaryTargetId { get; set; }
|
|
|
|
|
|
|
|
|
|
public SecondaryPermissionType SecondaryTarget { get; set; }
|
|
|
|
|
public string SecondaryTargetName { get; set; }
|
|
|
|
|
|
2016-09-20 01:08:28 +00:00
|
|
|
|
public bool State { get; set; }
|
2016-09-30 00:40:33 +00:00
|
|
|
|
|
2017-03-08 23:58:58 +00:00
|
|
|
|
public Permissionv2 Tov2() =>
|
|
|
|
|
new Permissionv2()
|
|
|
|
|
{
|
|
|
|
|
PrimaryTarget = PrimaryTarget,
|
|
|
|
|
PrimaryTargetId = PrimaryTargetId,
|
|
|
|
|
SecondaryTarget = SecondaryTarget,
|
|
|
|
|
SecondaryTargetName = SecondaryTargetName,
|
|
|
|
|
State = State,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//[NotMapped]
|
|
|
|
|
//private static Permission AllowAllPerm => new Permission()
|
|
|
|
|
//{
|
|
|
|
|
// PrimaryTarget = PrimaryPermissionType.Server,
|
|
|
|
|
// PrimaryTargetId = 0,
|
|
|
|
|
// SecondaryTarget = SecondaryPermissionType.AllModules,
|
|
|
|
|
// SecondaryTargetName = "*",
|
|
|
|
|
// State = true,
|
|
|
|
|
//};
|
|
|
|
|
//[NotMapped]
|
|
|
|
|
//private static Permission BlockNsfwPerm => new Permission()
|
|
|
|
|
//{
|
|
|
|
|
// PrimaryTarget = PrimaryPermissionType.Server,
|
|
|
|
|
// PrimaryTargetId = 0,
|
|
|
|
|
// SecondaryTarget = SecondaryPermissionType.Module,
|
|
|
|
|
// SecondaryTargetName = "nsfw",
|
|
|
|
|
// State = false,
|
|
|
|
|
//};
|
|
|
|
|
|
|
|
|
|
//public Permission Clone() => new Permission()
|
|
|
|
|
//{
|
|
|
|
|
// PrimaryTarget = PrimaryTarget,
|
|
|
|
|
// SecondaryTarget = SecondaryTarget,
|
|
|
|
|
// PrimaryTargetId = PrimaryTargetId,
|
|
|
|
|
// SecondaryTargetName = SecondaryTargetName,
|
|
|
|
|
// State = State,
|
|
|
|
|
//};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public interface IIndexed
|
|
|
|
|
{
|
|
|
|
|
int Index { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-16 08:47:38 +00:00
|
|
|
|
[DebuggerDisplay("{PrimaryTarget}{SecondaryTarget} {SecondaryTargetName} {State} {PrimaryTargetId}")]
|
2017-03-08 23:58:58 +00:00
|
|
|
|
public class Permissionv2 : DbEntity, IIndexed
|
|
|
|
|
{
|
2017-03-10 22:06:22 +00:00
|
|
|
|
public int? GuildConfigId { get; set; }
|
2017-03-08 23:58:58 +00:00
|
|
|
|
public int Index { get; set; }
|
|
|
|
|
|
|
|
|
|
public PrimaryPermissionType PrimaryTarget { get; set; }
|
|
|
|
|
public ulong PrimaryTargetId { get; set; }
|
|
|
|
|
|
|
|
|
|
public SecondaryPermissionType SecondaryTarget { get; set; }
|
|
|
|
|
public string SecondaryTargetName { get; set; }
|
|
|
|
|
|
|
|
|
|
public bool State { get; set; }
|
|
|
|
|
|
2016-09-30 00:40:33 +00:00
|
|
|
|
[NotMapped]
|
2017-03-08 23:58:58 +00:00
|
|
|
|
public static Permissionv2 AllowAllPerm => new Permissionv2()
|
2016-09-30 00:40:33 +00:00
|
|
|
|
{
|
|
|
|
|
PrimaryTarget = PrimaryPermissionType.Server,
|
|
|
|
|
PrimaryTargetId = 0,
|
|
|
|
|
SecondaryTarget = SecondaryPermissionType.AllModules,
|
|
|
|
|
SecondaryTargetName = "*",
|
|
|
|
|
State = true,
|
2017-03-08 23:58:58 +00:00
|
|
|
|
Index = 0,
|
2016-09-30 00:40:33 +00:00
|
|
|
|
};
|
|
|
|
|
[NotMapped]
|
2017-03-08 23:58:58 +00:00
|
|
|
|
private static Permissionv2 BlockNsfwPerm => new Permissionv2()
|
2016-09-30 00:40:33 +00:00
|
|
|
|
{
|
|
|
|
|
PrimaryTarget = PrimaryPermissionType.Server,
|
|
|
|
|
PrimaryTargetId = 0,
|
|
|
|
|
SecondaryTarget = SecondaryPermissionType.Module,
|
|
|
|
|
SecondaryTargetName = "nsfw",
|
|
|
|
|
State = false,
|
2017-03-08 23:58:58 +00:00
|
|
|
|
Index = 1
|
2016-09-30 00:40:33 +00:00
|
|
|
|
};
|
|
|
|
|
|
2017-03-08 23:58:58 +00:00
|
|
|
|
public static List<Permissionv2> GetDefaultPermlist =>
|
|
|
|
|
new List<Permissionv2>
|
|
|
|
|
{
|
|
|
|
|
BlockNsfwPerm,
|
|
|
|
|
AllowAllPerm
|
|
|
|
|
};
|
2016-09-30 00:40:33 +00:00
|
|
|
|
|
2017-03-08 23:58:58 +00:00
|
|
|
|
//public Permission Clone() => new Permission()
|
|
|
|
|
//{
|
|
|
|
|
// PrimaryTarget = PrimaryTarget,
|
|
|
|
|
// SecondaryTarget = SecondaryTarget,
|
|
|
|
|
// PrimaryTargetId = PrimaryTargetId,
|
|
|
|
|
// SecondaryTargetName = SecondaryTargetName,
|
|
|
|
|
// State = State,
|
|
|
|
|
//};
|
2016-09-20 01:08:28 +00:00
|
|
|
|
}
|
2016-09-22 18:53:49 +00:00
|
|
|
|
public enum PrimaryPermissionType
|
2016-09-20 01:08:28 +00:00
|
|
|
|
{
|
|
|
|
|
User,
|
|
|
|
|
Channel,
|
2016-09-30 00:40:33 +00:00
|
|
|
|
Role,
|
|
|
|
|
Server
|
2016-09-20 01:08:28 +00:00
|
|
|
|
}
|
2016-09-22 18:53:49 +00:00
|
|
|
|
|
|
|
|
|
public enum SecondaryPermissionType
|
|
|
|
|
{
|
|
|
|
|
Module,
|
2016-09-23 08:23:54 +00:00
|
|
|
|
Command,
|
|
|
|
|
AllModules
|
2016-09-22 18:53:49 +00:00
|
|
|
|
}
|
2016-09-20 01:08:28 +00:00
|
|
|
|
}
|