/// <summary> /// 是否拥有父级API权限 /// </summary> /// <param name="userOwnedAPIAuthorities"></param> /// <param name="parentID"></param> /// <returns></returns> private bool HasParentAPIAuthority(List <UserOwnedAPIAuthority> userOwnedAPIAuthorities, Guid parentID) { UserOwnedAPIAuthority userOwnedAPIAuthority = userOwnedAPIAuthorities.FirstOrDefault(m => m.ID == parentID); if (userOwnedAPIAuthority == null) { return(false); } return(!userOwnedAPIAuthority.ParentID.HasValue || HasParentAPIAuthority(userOwnedAPIAuthorities, userOwnedAPIAuthority.ParentID.Value)); }
public async Task <bool> HasAPIAuthorityAsync(Guid userID, params string[] codes) { List <UserOwnedAPIAuthority> userOwnedAPIAuthorities = await _userOwnedAPIAuthorityRepository.WhereAsync(m => m.UserID == userID).ToList(); foreach (string code in codes) { UserOwnedAPIAuthority userOwnedAPIAuthority = userOwnedAPIAuthorities.FirstOrDefault(m => m.Code == code); if (userOwnedAPIAuthority?.ParentID == null) { return(true); } if (!HasParentAPIAuthority(userOwnedAPIAuthorities, userOwnedAPIAuthority.ParentID.Value)) { return(false); } } return(true); }