diff options
| author | Jake Mannens <jake@asger.xyz> | 2023-10-03 16:41:58 +1100 |
|---|---|---|
| committer | Jake Mannens <jake@asger.xyz> | 2023-10-03 16:41:58 +1100 |
| commit | 33438ac951430fa370965b42a3d98a54e704ab01 (patch) | |
| tree | fbd835c25ac7566e8437cd0ef988fce0596a15e7 /Acl.cs | |
| parent | 7170867a9a2650fa5a98b9e2664fb2114a0bf114 (diff) | |
AclDialog
Diffstat (limited to 'Acl.cs')
| -rw-r--r-- | Acl.cs | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -12,6 +12,24 @@ public class Acl { public int AclId { get; set; } public HBObject Subject { get; set; } public List<AclRule> Rules { get; set; } + + public static Type GetAclType(HBObject obj) { + var attrib = Attribute.GetCustomAttribute(obj.GetType(), typeof(AclTypeAttribute), true); + + return (attrib as AclTypeAttribute)?.Type ?? typeof(ObjectPermissions); + } + + public static IEnumerable<KeyValuePair<string, ulong>> GetPermissionDescriptions(HBObject obj) { + var aclType = GetAclType(obj); + + foreach(var val in Enum.GetValues(aclType)) { + var attrib = (AclPermissionAttribute?) Attribute.GetCustomAttribute( + aclType.GetMember(val.ToString()!).First(), + typeof(AclPermissionAttribute)); + + yield return new(attrib?.Name ?? val.ToString()!, (ulong) val); + } + } } public class Acl<T> : Acl where T : Enum { @@ -40,3 +58,22 @@ public class AclRule<T> : AclRule where T : Enum { set => base.Permissions = (ulong) (object) value; } } + +public class AclTypeAttribute : Attribute { + public Type Type { get; private init; } + + public AclTypeAttribute(Type aclType) { + if(!aclType.IsEnum) + throw new ArgumentException(); + Type = aclType; + } +} + +public class AclPermissionAttribute : Attribute { + public string? Name { get; set; } + + public AclPermissionAttribute() {} + + public AclPermissionAttribute(string name) => + Name = name; +} |
