Feature #52: UserExt Auth methods for expressions
Extension methods can be used to test for user authorization (against claims) within Expressions
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Disco.BI.Extensions;
|
||||
using Disco.Models.Repository;
|
||||
using Disco.Services.Users;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
@@ -7,6 +8,7 @@ namespace Disco.BI.Expressions.Extensions
|
||||
{
|
||||
public static class UserExt
|
||||
{
|
||||
#region Active Directory Extensions
|
||||
public static object GetActiveDirectoryObjectValue(User User, string PropertyName, int Index = 0)
|
||||
{
|
||||
var adUserAccount = User.ActiveDirectoryAccount(PropertyName);
|
||||
@@ -44,5 +46,29 @@ namespace Disco.BI.Expressions.Extensions
|
||||
return intValue;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Authorization Testing Extensions
|
||||
public static bool HasAuthorization(User User, string Claim)
|
||||
{
|
||||
var authorization = UserService.GetAuthorization(User.UserId);
|
||||
|
||||
return authorization.Has(Claim);
|
||||
}
|
||||
|
||||
public static bool HasAuthorizationAll(User User, params string[] Claims)
|
||||
{
|
||||
var authorization = UserService.GetAuthorization(User.UserId);
|
||||
|
||||
return authorization.HasAll(Claims);
|
||||
}
|
||||
|
||||
public static bool HasAuthorizationAny(User User, params string[] Claims)
|
||||
{
|
||||
var authorization = UserService.GetAuthorization(User.UserId);
|
||||
|
||||
return authorization.HasAny(Claims);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user