1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using System;
- using System.Linq;
- namespace InABox.Core
- {
- [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
- public class SecurityAttribute : Attribute
- {
- public Type SecurityDescriptor { get; set; }
- /// <summary>
- /// If the user does not have the security token, this property will be <see cref="Visible.Visible"/> if <see langword="true"/>
- /// or <see cref="Visible.Hidden"/> if <see langword="false"/>. The default is <see langword="false"/>.
- /// </summary>
- public bool Visible { get; set; } = false;
- /// <summary>
- /// If the user does not have the security token, this property will be <see cref="Editable.Editable"/> if <see langword="true"/>
- /// or <see cref="Editable.Hidden"/> if <see langword="false"/>. The default is <see langword="false"/>.
- /// </summary>
- public bool Editable { get; set; } = false;
- private SecurityAttribute() { }
- public SecurityAttribute(Type securityDescriptor)
- {
- if (!securityDescriptor.GetInterfaces().Contains(typeof(ISecurityDescriptor)))
- throw new Exception(securityDescriptor.EntityName() + " is not a valid security descriptor!");
- SecurityDescriptor = securityDescriptor;
- }
- public virtual SecurityAttribute Clone()
- {
- var result = new SecurityAttribute(SecurityDescriptor);
- result.SecurityDescriptor = SecurityDescriptor;
- return result;
- }
- }
- public class CanViewAttribute : SecurityAttribute
- {
- public CanViewAttribute(Type TEntity): base(
- typeof(AutoSecurityDescriptor<,>).MakeGenericType(TEntity, typeof(CanView<>).MakeGenericType(TEntity)))
- {
- }
- }
- public class CanEditAttribute : SecurityAttribute
- {
- public CanEditAttribute(Type TEntity) : base(
- typeof(AutoSecurityDescriptor<,>).MakeGenericType(TEntity, typeof(CanEdit<>).MakeGenericType(TEntity)))
- {
- }
- }
- public class CanDeleteAttribute : SecurityAttribute
- {
- public CanDeleteAttribute(Type TEntity) : base(
- typeof(AutoSecurityDescriptor<,>).MakeGenericType(TEntity, typeof(CanDelete<>).MakeGenericType(TEntity)))
- {
- }
- }
- }
|