|
@@ -1,7 +1,12 @@
|
|
|
-using Hotline.Share.Dtos.CallCenter;
|
|
|
+using Hotline.Permissions;
|
|
|
+using Hotline.Repository.SqlSugar;
|
|
|
+using Hotline.Settings;
|
|
|
+using Hotline.Share.Dtos.CallCenter;
|
|
|
+using Hotline.Share.Dtos.Role;
|
|
|
using Identity.Admin.HttpClient;
|
|
|
using Identity.Shared.Dtos.Identity;
|
|
|
using Identity.Shared.Dtos.Role;
|
|
|
+using MapsterMapper;
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using XF.Domain.Exceptions;
|
|
@@ -12,10 +17,19 @@ namespace Hotline.Api.Controllers;
|
|
|
public class RoleController : BaseController
|
|
|
{
|
|
|
private readonly IIdentityClient _identityClient;
|
|
|
+ private readonly ISystemAuthorityRepository _systemAuthorityRepository;
|
|
|
+ private readonly ISystemDataAuthorityRepository _systemDataAuthorityRepository;
|
|
|
+ private readonly IMapper _mapper;
|
|
|
|
|
|
- public RoleController(IIdentityClient identityClient)
|
|
|
+ public RoleController(IIdentityClient identityClient,
|
|
|
+ ISystemAuthorityRepository systemAuthorityRepository,
|
|
|
+ ISystemDataAuthorityRepository systemDataAuthorityRepository,
|
|
|
+ IMapper mapper)
|
|
|
{
|
|
|
_identityClient = identityClient;
|
|
|
+ _systemAuthorityRepository = systemAuthorityRepository;
|
|
|
+ _systemDataAuthorityRepository = systemDataAuthorityRepository;
|
|
|
+ _mapper = mapper;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -24,7 +38,7 @@ public class RoleController : BaseController
|
|
|
/// <param name="dto"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("paged")]
|
|
|
- [Authorize("d")]
|
|
|
+ [Permission(EPermission.QueryPagedRole)]
|
|
|
public async Task<PagedDto<IdentityRoleDto>> QueryPaged([FromQuery] QueryRolesPagedDto dto)
|
|
|
{
|
|
|
|
|
@@ -39,6 +53,7 @@ public class RoleController : BaseController
|
|
|
/// </summary>
|
|
|
/// <param name="dto"></param>
|
|
|
/// <returns></returns>
|
|
|
+ [Permission(EPermission.AddRole)]
|
|
|
[HttpPost]
|
|
|
public async Task<string> Add([FromBody] IdentityRoleDto dto)
|
|
|
{
|
|
@@ -52,6 +67,7 @@ public class RoleController : BaseController
|
|
|
/// </summary>
|
|
|
/// <param name="roleId"></param>
|
|
|
/// <returns></returns>
|
|
|
+ [Permission(EPermission.RemoveRole)]
|
|
|
[HttpDelete("{roleId}")]
|
|
|
public async Task Remove(string roleId)
|
|
|
{
|
|
@@ -64,6 +80,7 @@ public class RoleController : BaseController
|
|
|
/// </summary>
|
|
|
/// <param name="dto"></param>
|
|
|
/// <returns></returns>
|
|
|
+ [Permission(EPermission.UpdateRole)]
|
|
|
[HttpPut]
|
|
|
public async Task Update([FromBody] IdentityRoleDto dto)
|
|
|
{
|
|
@@ -71,6 +88,97 @@ public class RoleController : BaseController
|
|
|
CheckHttpRequestSuccess(updateRoleRsp, "UpdateRoleAsync");
|
|
|
}
|
|
|
|
|
|
+ #region 应用权限管理
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 分配权限
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [Permission(EPermission.AllocationAuthority)]
|
|
|
+ [HttpPost("allocationauthority")]
|
|
|
+ public async Task AllocationAuthority(List<RoleAuthorityDto> dto)
|
|
|
+ {
|
|
|
+ var list = _mapper.Map<List<SystemAuthority>>(dto);
|
|
|
+ await _systemAuthorityRepository.AddRangeAsync(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取角色权限
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="roleid"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [Permission(EPermission.GetAuthority)]
|
|
|
+ [HttpGet("getauthority")]
|
|
|
+ public async Task<IReadOnlyList<SystemAuthority>> GetAuthority(string roleid)
|
|
|
+ {
|
|
|
+ return await _systemAuthorityRepository.QueryAsync(x => x.RoleId == roleid);
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 数据权限管理
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 新增数据权限
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [Permission(EPermission.AddDataAuthority)]
|
|
|
+ [HttpPost("add-data-authority")]
|
|
|
+ public async Task AddDataAuthority([FromBody] AddDataAuthorityDto dto)
|
|
|
+ {
|
|
|
+ var dataAuthority = _mapper.Map<SystemDataAuthority>(dto);
|
|
|
+ await _systemDataAuthorityRepository.AddAsync(dataAuthority);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 修改数据权限
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [Permission(EPermission.UpdateDataAuthority)]
|
|
|
+ [HttpPost("update-data-authority")]
|
|
|
+ public async Task UpdateDataAuthority([FromBody] UpdateDataAuthorityDto dto)
|
|
|
+ {
|
|
|
+ var entity = await _systemDataAuthorityRepository.GetAsync(x => x.Id == dto.Id, HttpContext.RequestAborted);
|
|
|
+ if (entity is null)
|
|
|
+ throw UserFriendlyException.SameMessage("无效数据");
|
|
|
+
|
|
|
+ _mapper.Map(dto, entity);
|
|
|
+ await _systemDataAuthorityRepository.UpdateAsync(entity, HttpContext.RequestAborted);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 删除数据权限
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [Permission(EPermission.RemoveDataAuthority)]
|
|
|
+ [HttpDelete("remove-data-authority/{id}")]
|
|
|
+ public async Task RemoveDataAuthority(string id)
|
|
|
+ {
|
|
|
+ var entity = await _systemDataAuthorityRepository.GetAsync(id, HttpContext.RequestAborted);
|
|
|
+ if (entity is null)
|
|
|
+ throw UserFriendlyException.SameMessage("无效数据");
|
|
|
+
|
|
|
+ await _systemDataAuthorityRepository.RemoveAsync(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取角色所有数据权限设置
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="roleid"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [Permission(EPermission.GetDataAuthorityByRole)]
|
|
|
+ [HttpGet("getdataauthoritybyrole")]
|
|
|
+ public async Task<IReadOnlyList<SystemDataAuthority>> GetDataAuthorityByRole(string roleid)
|
|
|
+ {
|
|
|
+ return await _systemDataAuthorityRepository.QueryAsync(x => x.RoleId == roleid);
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
#region private
|
|
|
|
|
|
private void CheckHttpRequestSuccess(ApiResponse response, string msg)
|