OpenAuth.Net/OpenAuth.App/RoleManager/RoleApp.cs
yubaolee 38a62595ba fix issue #I3YVBH 兼容oracle 11g
add load all users/roles for flowinstance
fix issue #I3W5YR
2021-07-05 21:44:35 +08:00

107 lines
3.2 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 System.Collections.Generic;
using OpenAuth.App.Interface;
using OpenAuth.App.Response;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
using System.Linq;
using System.Threading.Tasks;
using Infrastructure;
using OpenAuth.App.Request;
using OpenAuth.Repository;
namespace OpenAuth.App
{
public class RoleApp : BaseStringApp<Role,OpenAuthDBContext>
{
private RevelanceManagerApp _revelanceApp;
/// <summary>
/// 加载当前登录用户可访问的全部角色
/// </summary>
public List<Role> Load(QueryRoleListReq request)
{
var loginUser = _auth.GetCurrentUser();
var roles = loginUser.Roles;
if (!string.IsNullOrEmpty(request.key))
{
roles = roles.Where(u => u.Name.Contains(request.key)).ToList();
}
return roles;
}
/// <summary>
/// 获取所有的角色
/// 为了控制权限通常只用于流程实例选择执行角色其他地方请使用Load
/// </summary>
public async Task<TableResp<Role>> LoadAll(QueryRoleListReq request)
{
var result = new TableResp<Role>();
var objs = UnitWork.Find<Role>(null);
if (!string.IsNullOrEmpty(request.key))
{
objs = objs.Where(u => u.Name.Contains(request.key));
}
result.data = objs.OrderBy(u => u.Name)
.Skip((request.page - 1) * request.limit)
.Take(request.limit).ToList();
result.count = objs.Count();
return result;
}
/// <summary>
/// 添加角色如果当前登录用户不是System则直接把新角色分配给当前登录用户
/// </summary>
public void Add(RoleView obj)
{
UnitWork.ExecuteWithTransaction(() =>
{
Role role = obj;
role.CreateTime = DateTime.Now;
UnitWork.Add(role);
UnitWork.Save();
obj.Id = role.Id; //要把保存后的ID存入view
//如果当前账号不是SYSTEM则直接分配
var loginUser = _auth.GetCurrentUser();
if (loginUser.User.Account != Define.SYSTEM_USERNAME)
{
_revelanceApp.Assign(new AssignReq
{
type = Define.USERROLE,
firstId = loginUser.User.Id,
secIds = new[] {role.Id}
});
}
});
}
/// <summary>
/// 更新角色属性
/// </summary>
/// <param name="obj"></param>
public void Update(RoleView obj)
{
Role role = obj;
UnitWork.Update<Role>(u => u.Id == obj.Id, u => new Role
{
Name = role.Name,
Status = role.Status
});
}
public RoleApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<Role,OpenAuthDBContext> repository,
RevelanceManagerApp app,IAuth auth) : base(unitWork, repository, auth)
{
_revelanceApp = app;
}
}
}