Browse Source

Added GetRoles to IIdentityUserAppService

pull/113/head
Halil İbrahim Kalkan 9 years ago
parent
commit
ecd03af4c7
  1. 2
      src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserAppService.cs
  2. 2
      src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityRoleDto.cs
  3. 1
      src/Volo.Abp.Identity.Application/Volo/Abp/Identity/AbpDeskApplicationModuleAutoMapperProfile.cs
  4. 8
      src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs
  5. 9
      src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs
  6. 2
      src/Volo.Abp.Identity/Properties/AssemblyInfo.cs
  7. 2
      src/Volo.Abp.Identity/Volo/Abp/Identity/IIdentityUserRepository.cs
  8. 18
      test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/AbpIdentityTestDataBuilder.cs
  9. 17
      test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityUserAppService_Tests.cs

2
src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserAppService.cs

@ -7,6 +7,6 @@ namespace Volo.Abp.Identity
{
public interface IIdentityUserAppService : IAsyncCrudAppService<IdentityUserDto, Guid, PagedAndSortedResultRequestDto, IdentityUserCreateDto, IdentityUserUpdateDto>
{
Task<ListResultDto<IdentityRoleDto>> GetRolesAsync(Guid id);
}
}

2
src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserRoleInfoDto.cs → src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityRoleDto.cs

@ -2,7 +2,7 @@
namespace Volo.Abp.Identity
{
public class IdentityUserRoleInfoDto : EntityDto
public class IdentityRoleDto : EntityDto
{
public string Name { get; set; }
}

1
src/Volo.Abp.Identity.Application/Volo/Abp/Identity/AbpDeskApplicationModuleAutoMapperProfile.cs

@ -7,6 +7,7 @@ namespace Volo.Abp.Identity
public AbpIdentityApplicationModuleAutoMapperProfile()
{
CreateMap<IdentityUser, IdentityUserDto>();
CreateMap<IdentityRole, IdentityRoleDto>();
}
}
}

8
src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs

@ -67,6 +67,14 @@ namespace Volo.Abp.Identity
await _userManager.DeleteAsync(user);
}
public async Task<ListResultDto<IdentityRoleDto>> GetRolesAsync(Guid id)
{
var roles = await _userRepository.GetRolesAsync(id);
return new ListResultDto<IdentityRoleDto>(
ObjectMapper.Map<List<IdentityRole>, List<IdentityRoleDto>>(roles)
);
}
private async Task UpdateUserByInput(IdentityUser user, IdentityUserCreateOrUpdateDtoBase input)
{
await _userManager.SetEmailAsync(user, input.Email);

9
src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs

@ -82,5 +82,14 @@ namespace Volo.Abp.Identity
{
return await this.OrderBy(sorting ?? nameof(IdentityUser.UserName)).PageBy(skipCount, maxResultCount).ToListAsync();
}
public async Task<List<IdentityRole>> GetRolesAsync(Guid userId)
{
var query = from userRole in DbContext.UserRoles
join role in DbContext.Roles on userRole.RoleId equals role.Id
select role;
return await query.ToListAsync();
}
}
}

2
src/Volo.Abp.Identity/Properties/AssemblyInfo.cs

@ -1,4 +1,5 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
@ -8,6 +9,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Volo.Abp.Identity")]
[assembly: AssemblyTrademark("")]
[assembly: InternalsVisibleTo("Volo.Abp.Identity.Application.Tests")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from

2
src/Volo.Abp.Identity/Volo/Abp/Identity/IIdentityUserRepository.cs

@ -25,5 +25,7 @@ namespace Volo.Abp.Identity
Task<IList<IdentityUser>> GetListByNormalizedRoleNameAsync(string normalizedRoleName, CancellationToken cancellationToken);
Task<List<IdentityUser>> GetListAsync(string sorting, int maxResultCount, int skipCount);
Task<List<IdentityRole>> GetRolesAsync(Guid userId);
}
}

18
test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/AbpIdentityTestDataBuilder.cs

@ -9,6 +9,10 @@ namespace Volo.Abp.Identity
private readonly IIdentityUserRepository _userRepository;
private readonly IIdentityRoleRepository _roleRepository;
private IdentityRole _adminRole;
private IdentityRole _moderator;
private IdentityRole _supporterRole;
public AbpIdentityTestDataBuilder(
IGuidGenerator guidGenerator,
IIdentityUserRepository userRepository,
@ -27,14 +31,20 @@ namespace Volo.Abp.Identity
private void AddRoles()
{
_roleRepository.Insert(new IdentityRole(_guidGenerator.Create(), "admin"));
_roleRepository.Insert(new IdentityRole(_guidGenerator.Create(), "moderator"));
_roleRepository.Insert(new IdentityRole(_guidGenerator.Create(), "supporter"));
_adminRole = new IdentityRole(_guidGenerator.Create(), "admin");
_moderator = new IdentityRole(_guidGenerator.Create(), "moderator");
_supporterRole = new IdentityRole(_guidGenerator.Create(), "supporter");
_roleRepository.Insert(_adminRole);
_roleRepository.Insert(_moderator);
_roleRepository.Insert(_supporterRole);
}
private void AddUsers()
{
_userRepository.Insert(new IdentityUser(_guidGenerator.Create(), "john.nash"));
var john = new IdentityUser(_guidGenerator.Create(), "john.nash");
john.Roles.Add(new IdentityUserRole(_guidGenerator.Create(), john.Id, _moderator.Id));
_userRepository.Insert(john);
}
}
}

17
test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityUserAppService_Tests.cs

@ -140,6 +140,23 @@ namespace Volo.Abp.Identity
(await FindUserAsync("john.nash")).ShouldBeNull();
}
[Fact]
public async Task GetRolesAsync()
{
//Arrange
var johnNash = await GetUserAsync("john.nash");
//Act
var result = await _identityUserAppService.GetRolesAsync(johnNash.Id);
//Assert
result.Items.Count.ShouldBe(1);
result.Items[0].Name.ShouldBe("moderator");
}
private async Task<IdentityUser> GetUserAsync(string userName)
{
return (await _userRepository.GetListAsync()).First(u => u.UserName == userName);

Loading…
Cancel
Save