Browse Source

fixed unit roles not getting when all roles are requested from EfCoreIdentityUserRepository

pull/3732/head
Galip Tolga Erdem 7 years ago
parent
commit
29dbcb08ab
  1. 4
      modules/identity/src/Volo.Abp.Identity.Domain/Volo.Abp.Identity.Domain.csproj
  2. 26
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityUserRepository.cs

4
modules/identity/src/Volo.Abp.Identity.Domain/Volo.Abp.Identity.Domain.csproj

@ -33,8 +33,4 @@
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="3.1.2" /> <PackageReference Include="Microsoft.Extensions.Identity.Core" Version="3.1.2" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Volo\Abp\Identity\Organizations\" />
</ItemGroup>
</Project> </Project>

26
modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityUserRepository.cs

@ -6,6 +6,7 @@ using System.Security.Claims;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Internal;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
@ -139,17 +140,22 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
join role in DbContext.Roles.IncludeDetails(includeDetails) on userRole.RoleId equals role.Id join role in DbContext.Roles.IncludeDetails(includeDetails) on userRole.RoleId equals role.Id
where userRole.UserId == id where userRole.UserId == id
select role; select role;
//TODO
//var q2 = from userOrganization in DbContext.Set<IdentityUserOrganizationUnit>()
// join userOrg in DbContext.OrganizationUnits.IncludeDetails(includeDetails) on userOrganization.UserId equals id
// select userOrg.Roles;
//var q3 = from ouRole in DbContext.Set<OrganizationUnitRole>()
// join role in DbContext.Roles.IncludeDetails(includeDetails) on ouRole.RoleId equals role.Id
// where ouRole.RoleId == id
// select role;
//query = q2.Union(query);
return await query.ToListAsync(GetCancellationToken(cancellationToken)); //TODO: Needs improvement
var userOrganizationsQuery = from userOrg in DbContext.Set<IdentityUserOrganizationUnit>()
join ou in DbContext.OrganizationUnits.IncludeDetails(includeDetails) on userOrg.OrganizationUnitId equals ou.Id
where userOrg.UserId == id
select ou;
var orgUserRoleQuery = DbContext.Set<OrganizationUnitRole>().Where(q => userOrganizationsQuery.Select(t => t.Id).Contains(q.OrganizationUnitId))
.Select(t => t.RoleId);
var orgRoles = DbContext.Roles.Where(q => orgUserRoleQuery.Contains(q.Id));
var resultQuery = query.Union(orgRoles);
return await resultQuery.ToListAsync(GetCancellationToken(cancellationToken));
//return await query.ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<long> GetCountAsync( public virtual async Task<long> GetCountAsync(

Loading…
Cancel
Save