49 lines
992 B
C#
49 lines
992 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using BS.Shared;
|
|
|
|
namespace BeWo.Service.Attributes
|
|
{
|
|
[AttributeUsage(AttributeTargets.Method, Inherited = true)]
|
|
public class RequirePermissionAttribute : Attribute
|
|
{
|
|
public UserRightType[] Permissions { get; }
|
|
|
|
public RequirePermissionAttribute(params UserRightType[] permissions)
|
|
{
|
|
Permissions = permissions;
|
|
}
|
|
|
|
public bool HasPermission(IEnumerable<UserRightType> rights)
|
|
{
|
|
if (Permissions is null || Permissions.Length == 0)
|
|
return true;
|
|
|
|
foreach (var right in rights)
|
|
{
|
|
if (HasPermission(right))
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public bool HasPermission(UserRightType right)
|
|
{
|
|
if (Permissions is null || Permissions.Length == 0)
|
|
return true;
|
|
|
|
for (var i = 0; i < Permissions.Length; i++)
|
|
{
|
|
var permission = Permissions[i];
|
|
if (right == permission) return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|