using System;
using System.Linq;
namespace InABox.Core
{
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class SecurityAttribute : Attribute
{
public Type SecurityDescriptor { get; set; }
///
/// If the user does not have the security token, this property will be if
/// or if . The default is .
///
public bool Visible { get; set; } = false;
///
/// If the user does not have the security token, this property will be if
/// or if . The default is .
///
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)))
{
}
}
}