Browse Source

Create an endpoint to query all roles.

Resolve #2983
pull/2985/head
maliming 7 years ago
parent
commit
ed5ebe3203
  1. 2
      modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityRoleAppService.cs
  2. 6
      modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs
  3. 8
      modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityRoleController.cs
  4. 4
      modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/CreateModal.cshtml.cs
  5. 4
      modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml.cs
  6. 12
      modules/identity/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityRoleAppService_Tests.cs

2
modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityRoleAppService.cs

@ -8,6 +8,8 @@ namespace Volo.Abp.Identity
{ {
public interface IIdentityRoleAppService : IApplicationService public interface IIdentityRoleAppService : IApplicationService
{ {
Task<List<IdentityRoleDto>> GetAllListAsync();
Task<PagedResultDto<IdentityRoleDto>> GetListAsync(PagedAndSortedResultRequestDto input); Task<PagedResultDto<IdentityRoleDto>> GetListAsync(PagedAndSortedResultRequestDto input);
Task<IdentityRoleDto> CreateAsync(IdentityRoleCreateDto input); Task<IdentityRoleDto> CreateAsync(IdentityRoleCreateDto input);

6
modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs

@ -27,6 +27,12 @@ namespace Volo.Abp.Identity
await _roleManager.GetByIdAsync(id)); await _roleManager.GetByIdAsync(id));
} }
public virtual async Task<List<IdentityRoleDto>> GetAllListAsync()
{
var list = await _roleRepository.GetListAsync();
return ObjectMapper.Map<List<IdentityRole>, List<IdentityRoleDto>>(list);
}
public virtual async Task<PagedResultDto<IdentityRoleDto>> GetListAsync(PagedAndSortedResultRequestDto input) public virtual async Task<PagedResultDto<IdentityRoleDto>> GetListAsync(PagedAndSortedResultRequestDto input)
{ {
var list = await _roleRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount); var list = await _roleRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount);

8
modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityRoleController.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
@ -19,6 +20,13 @@ namespace Volo.Abp.Identity
_roleAppService = roleAppService; _roleAppService = roleAppService;
} }
[HttpGet]
[Route("all")]
public virtual Task<List<IdentityRoleDto>> GetAllListAsync()
{
return _roleAppService.GetAllListAsync();
}
[HttpGet] [HttpGet]
public virtual Task<PagedResultDto<IdentityRoleDto>> GetListAsync(PagedAndSortedResultRequestDto input) public virtual Task<PagedResultDto<IdentityRoleDto>> GetListAsync(PagedAndSortedResultRequestDto input)
{ {

4
modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/CreateModal.cshtml.cs

@ -29,9 +29,9 @@ namespace Volo.Abp.Identity.Web.Pages.Identity.Users
{ {
UserInfo = new UserInfoViewModel(); UserInfo = new UserInfoViewModel();
var roleDtoList = await _identityRoleAppService.GetListAsync(new PagedAndSortedResultRequestDto()); var roleDtoList = await _identityRoleAppService.GetAllListAsync();
Roles = ObjectMapper.Map<IReadOnlyList<IdentityRoleDto>, AssignedRoleViewModel[]>(roleDtoList.Items); Roles = ObjectMapper.Map<IReadOnlyList<IdentityRoleDto>, AssignedRoleViewModel[]>(roleDtoList);
foreach (var role in Roles) foreach (var role in Roles)
{ {

4
modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml.cs

@ -31,9 +31,7 @@ namespace Volo.Abp.Identity.Web.Pages.Identity.Users
{ {
UserInfo = ObjectMapper.Map<IdentityUserDto, UserInfoViewModel>(await _identityUserAppService.GetAsync(id)); UserInfo = ObjectMapper.Map<IdentityUserDto, UserInfoViewModel>(await _identityUserAppService.GetAsync(id));
Roles = ObjectMapper.Map<IReadOnlyList<IdentityRoleDto>, AssignedRoleViewModel[]>( Roles = ObjectMapper.Map<IReadOnlyList<IdentityRoleDto>, AssignedRoleViewModel[]>((await _identityRoleAppService.GetAllListAsync()));
(await _identityRoleAppService.GetListAsync(new PagedAndSortedResultRequestDto())).Items
);
var userRoleNames = (await _identityUserAppService.GetRolesAsync(UserInfo.Id)).Items.Select(r => r.Name).ToList(); var userRoleNames = (await _identityUserAppService.GetRolesAsync(UserInfo.Id)).Items.Select(r => r.Name).ToList();
foreach (var role in Roles) foreach (var role in Roles)

12
modules/identity/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityRoleAppService_Tests.cs

@ -34,6 +34,18 @@ namespace Volo.Abp.Identity
result.Id.ShouldBe(moderator.Id); result.Id.ShouldBe(moderator.Id);
} }
[Fact]
public async Task GetAllListAsync()
{
//Act
var result = await _roleAppService.GetAllListAsync();
//Assert
result.Count.ShouldBeGreaterThan(0);
}
[Fact] [Fact]
public async Task GetListAsync() public async Task GetListAsync()
{ {

Loading…
Cancel
Save