/// <summary> /// Checks if given user is granted for given permission. /// </summary> /// <param name="powerChecker">Permission checker</param> /// <param name="userId">User</param> /// <param name="requiresAll">True, to require all given permissions are granted. False, to require one or more.</param> /// <param name="permissionCodes">Name of the permissions</param> public static async Task <bool> IsGrantedAsync(this IPowerChecker powerChecker, string userId, bool requiresAll, params string[] permissionCodes) { if (permissionCodes.IsNullOrEmpty()) { return(true); } if (requiresAll) { foreach (var permissionCode in permissionCodes) { if (!(await powerChecker.IsGrantedAsync(userId, permissionCode))) { return(false); } } return(true); } else { foreach (var permissionCode in permissionCodes) { if (await powerChecker.IsGrantedAsync(userId, permissionCode)) { return(true); } } return(false); } }
/// <summary> /// Checks if a user is granted for a permission. /// </summary> /// <param name="powerChecker">Permission checker</param> /// <param name="userId">User to check</param> /// <param name="permissionCode">Name of the permission</param> public static bool IsGranted(this IPowerChecker powerChecker, string userId, string permissionCode) { return(AsyncHelper.RunSync(() => powerChecker.IsGrantedAsync(userId, permissionCode))); }
public static async Task AuthorizeAsync(this IPowerChecker powerChecker, string absolutePath, HttpMethod method) { await powerChecker.IsGrantedAsync(absolutePath, method); }