Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

list of users have permission #6333


User avatar
0
samara081 created

i need to get a list of users , who's have specific permission ,


4 Answer(s)
  • User Avatar
    1
    ismcagdas created
    Support Team
  • User Avatar
    0
    samara081 created

    url give 404

  • User Avatar
    1
    alper created
    Support Team

    https://github.com/aspnetzero/aspnet-zero-core repository is a private repository. You need to login first!

  • User Avatar
    1
    alper created
    Support Team
    public async Task<PagedResultDto<UserListDto>> GetUsers(GetUsersInput input)
    {
        var query = UserManager.Users
            .WhereIf(input.Role.HasValue, u => u.Roles.Any(r => r.RoleId == input.Role.Value))
            .WhereIf(input.OnlyLockedUsers, u => u.LockoutEndDateUtc.HasValue && u.LockoutEndDateUtc.Value > DateTime.UtcNow)
            .WhereIf(
                !input.Filter.IsNullOrWhiteSpace(),
                u =>
                    u.Name.Contains(input.Filter) ||
                    u.Surname.Contains(input.Filter) ||
                    u.UserName.Contains(input.Filter) ||
                    u.EmailAddress.Contains(input.Filter)
            );
    
        // HERE IT CHECKS A SPECIFIC PERMISSION
    
        if (!input.Permission.IsNullOrWhiteSpace())
        {
            query = from user in query
                    join ur in _userRoleRepository.GetAll() on user.Id equals ur.UserId into urJoined
                    from ur in urJoined.DefaultIfEmpty()
                    join up in _userPermissionRepository.GetAll() on new { UserId = user.Id, Name = input.Permission } equals new { up.UserId, up.Name } into upJoined
                    from up in upJoined.DefaultIfEmpty()
                    join rp in _rolePermissionRepository.GetAll() on new { RoleId = ur == null ? 0 : ur.RoleId, Name = input.Permission } equals new { rp.RoleId, rp.Name } into rpJoined
                    from rp in rpJoined.DefaultIfEmpty()
                    where up != null && up.IsGranted || up == null && rp != null
                    group user by user
                    into userGrouped
                    select userGrouped.Key;
        }
    
        // ...
    }