summaryrefslogtreecommitdiff
path: root/Acl.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Acl.cs')
-rw-r--r--Acl.cs37
1 files changed, 37 insertions, 0 deletions
diff --git a/Acl.cs b/Acl.cs
index 7bffc50..a16d08a 100644
--- a/Acl.cs
+++ b/Acl.cs
@@ -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;
+}