OpenAuth.Net/OpenAuth.WebApi/Controllers/AccessObjsController.cs
2020-12-27 00:00:28 +08:00

156 lines
4.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using Infrastructure;
using Microsoft.AspNetCore.Mvc;
using OpenAuth.App;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;
namespace OpenAuth.WebApi.Controllers
{
/// <summary>
/// 分配资源/分配字段等
/// </summary>
[Route("api/[controller]/[action]")]
[ApiController]
public class AccessObjsController : ControllerBase
{
private readonly RevelanceManagerApp _app;
private readonly IAuth _authUtil;
public AccessObjsController(IAuth authUtil, RevelanceManagerApp app)
{
_app = app;
_authUtil = authUtil;
}
/// <summary>
/// 添加关联
/// <para>比如给用户分配资源那么firstId就是用户IDsecIds就是资源ID列表</para>
/// </summary>
/// <returns></returns>
[HttpPost]
public Response Assign(AssignReq request)
{
var result = new Response();
try
{
_app.Assign(request);
}
catch (Exception ex)
{
result.Code = 500;
result.Message = ex.InnerException?.Message ?? ex.Message;
}
return result;
}
/// <summary>
/// 取消关联
/// </summary>
[HttpPost]
public Response UnAssign(AssignReq request)
{
var result = new Response();
try
{
_app.UnAssign(request);
}
catch (Exception ex)
{
result.Code = 500;
result.Message = ex.InnerException?.Message ?? ex.Message;
}
return result;
}
/// <summary>
/// 角色分配数据字段权限
/// </summary>
/// <returns></returns>
[HttpPost]
public Response AssignDataProperty(AssignDataReq request)
{
var result = new Response();
try
{
_app.AssignData(request);
}
catch (Exception ex)
{
result.Code = 500;
result.Message = ex.InnerException?.Message ?? ex.Message;
}
return result;
}
/// <summary>
/// 取消角色的数据字段权限
/// <para>如果Properties为空则把角色的某一个模块权限全部删除</para>
/// <para>如果moduleId为空直接把角色的所有授权删除</para>
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
private static string lockobj = "lock";
[HttpPost]
public Response UnAssignDataProperty(AssignDataReq request)
{
var result = new Response();
try
{
lock (lockobj)
{
_app.UnAssignData(request);
}
}
catch (Exception ex)
{
result.Code = 500;
result.Message = ex.InnerException?.Message ?? ex.Message;
}
return result;
}
/// <summary>
/// 角色分配用户,整体提交,会覆盖之前的配置
/// </summary>
[HttpPost]
public Response AssignRoleUsers(AssignRoleUsers request)
{
var result = new Response();
try
{
_app.AssignRoleUsers(request);
}
catch (Exception ex)
{
result.Code = 500;
result.Message = ex.InnerException?.Message ?? ex.Message;
}
return result;
}
/// <summary>
/// 部门分配用户,整体提交,会覆盖之前的配置
/// </summary>
[HttpPost]
public Response AssignOrgUsers(AssignOrgUsers request)
{
var result = new Response();
try
{
_app.AssignOrgUsers(request);
}
catch (Exception ex)
{
result.Code = 500;
result.Message = ex.InnerException?.Message ?? ex.Message;
}
return result;
}
}
}