Skip to content

Commit 70f17b3

Browse files
authored
Merge pull request #334 from aspnetboilerplate/role-app-service
Fixed #322 - RoleAppService.Get returns Prohibited permissions which …
2 parents 0048e70 + 3cacdbe commit 70f17b3

File tree

6 files changed

+46
-3
lines changed

6 files changed

+46
-3
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace AbpCompanyName.AbpProjectName.Roles.Dto
2+
{
3+
public class GetRolesInput
4+
{
5+
public string Permission { get; set; }
6+
}
7+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using Abp.Application.Services.Dto;
3+
using Abp.Domain.Entities.Auditing;
4+
5+
namespace AbpCompanyName.AbpProjectName.Roles.Dto
6+
{
7+
public class RoleListDto : EntityDto, IHasCreationTime
8+
{
9+
public string Name { get; set; }
10+
11+
public string DisplayName { get; set; }
12+
13+
public bool IsStatic { get; set; }
14+
15+
public bool IsDefault { get; set; }
16+
17+
public DateTime CreationTime { get; set; }
18+
}
19+
}

aspnet-core/src/AbpCompanyName.AbpProjectName.Application/Roles/IRoleAppService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ public interface IRoleAppService : IAsyncCrudAppService<RoleDto, int, PagedResul
1010
Task<ListResultDto<PermissionDto>> GetAllPermissions();
1111

1212
Task<GetRoleForEditOutput> GetRoleForEdit(EntityDto input);
13+
14+
Task<ListResultDto<RoleListDto>> GetRolesAsync(GetRolesInput input);
1315
}
1416
}

aspnet-core/src/AbpCompanyName.AbpProjectName.Application/Roles/RoleAppService.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
using Abp.Authorization;
99
using Abp.Domain.Repositories;
1010
using Abp.IdentityFramework;
11-
using Abp.UI;
11+
using Abp.Linq.Extensions;
12+
using Abp.Extensions;
1213
using AbpCompanyName.AbpProjectName.Authorization;
1314
using AbpCompanyName.AbpProjectName.Authorization.Roles;
1415
using AbpCompanyName.AbpProjectName.Authorization.Users;
@@ -48,6 +49,19 @@ public override async Task<RoleDto> Create(CreateRoleDto input)
4849
return MapToEntityDto(role);
4950
}
5051

52+
public async Task<ListResultDto<RoleListDto>> GetRolesAsync(GetRolesInput input)
53+
{
54+
var roles = await _roleManager
55+
.Roles
56+
.WhereIf(
57+
!input.Permission.IsNullOrWhiteSpace(),
58+
r => r.Permissions.Any(rp => rp.Name == input.Permission && rp.IsGranted)
59+
)
60+
.ToListAsync();
61+
62+
return new ListResultDto<RoleListDto>(ObjectMapper.Map<List<RoleListDto>>(roles));
63+
}
64+
5165
public override async Task<RoleDto> Update(RoleDto input)
5266
{
5367
CheckUpdatePermission();

aspnet-core/src/AbpCompanyName.AbpProjectName.Web.Mvc/Controllers/RolesController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using AbpCompanyName.AbpProjectName.Authorization;
66
using AbpCompanyName.AbpProjectName.Controllers;
77
using AbpCompanyName.AbpProjectName.Roles;
8+
using AbpCompanyName.AbpProjectName.Roles.Dto;
89
using AbpCompanyName.AbpProjectName.Web.Models.Roles;
910

1011
namespace AbpCompanyName.AbpProjectName.Web.Controllers
@@ -21,7 +22,7 @@ public RolesController(IRoleAppService roleAppService)
2122

2223
public async Task<IActionResult> Index()
2324
{
24-
var roles = (await _roleAppService.GetAll(new PagedAndSortedResultRequestDto())).Items;
25+
var roles = (await _roleAppService.GetRolesAsync(new GetRolesInput())).Items;
2526
var permissions = (await _roleAppService.GetAllPermissions()).Items;
2627
var model = new RoleListViewModel
2728
{

aspnet-core/src/AbpCompanyName.AbpProjectName.Web.Mvc/Models/Roles/RoleListViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace AbpCompanyName.AbpProjectName.Web.Models.Roles
55
{
66
public class RoleListViewModel
77
{
8-
public IReadOnlyList<RoleDto> Roles { get; set; }
8+
public IReadOnlyList<RoleListDto> Roles { get; set; }
99

1010
public IReadOnlyList<PermissionDto> Permissions { get; set; }
1111
}

0 commit comments

Comments
 (0)