mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-04-05 17:38:01 +08:00
ru
This commit is contained in:
parent
8dcbae1517
commit
4aaeb28912
@ -80,8 +80,8 @@ namespace OpenAuth.App
|
||||
{
|
||||
var orgids = UnitWork.Find<Relevance>(
|
||||
u =>
|
||||
(u.FirstId == _user.Id && u.Key == "UserOrg") ||
|
||||
(u.Key == "RoleOrg" && _userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
||||
(u.FirstId == _user.Id && u.Key == Define.USERORG) ||
|
||||
(u.Key == Define.ROLEORG && _userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
||||
return UnitWork.Find<Org>(u => orgids.Contains(u.Id));
|
||||
}
|
||||
|
||||
@ -93,8 +93,8 @@ namespace OpenAuth.App
|
||||
{
|
||||
var resourceIds = UnitWork.Find<Relevance>(
|
||||
u =>
|
||||
(u.FirstId == _user.Id && u.Key == "UserResource") ||
|
||||
(u.Key == "RoleResource" && _userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
||||
(u.FirstId == _user.Id && u.Key == Define.USERRESOURCE) ||
|
||||
(u.Key == Define.ROLERESOURCE && _userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
||||
return UnitWork.Find<Resource>(u => resourceIds.Contains(u.Id));
|
||||
}
|
||||
|
||||
@ -105,8 +105,8 @@ namespace OpenAuth.App
|
||||
{
|
||||
var elementIds = UnitWork.Find<Relevance>(
|
||||
u =>
|
||||
(u.FirstId == _user.Id && u.Key == "UserElement") ||
|
||||
(u.Key == "RoleElement" && _userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
||||
(u.FirstId == _user.Id && u.Key == Define.ROLERESOURCE) ||
|
||||
(u.Key == Define.ROLEELEMENT && _userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
||||
return UnitWork.Find<ModuleElement>(u => elementIds.Contains(u.Id));
|
||||
}
|
||||
|
||||
@ -117,8 +117,8 @@ namespace OpenAuth.App
|
||||
{
|
||||
var moduleIds = UnitWork.Find<Relevance>(
|
||||
u =>
|
||||
(u.FirstId == _user.Id && u.Key == "UserModule") ||
|
||||
(u.Key == "RoleModule" && _userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
||||
(u.FirstId == _user.Id && u.Key == Define.USERMODULE) ||
|
||||
(u.Key == Define.ROLEMODULE && _userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
||||
return UnitWork.Find<Module>(u => moduleIds.Contains(u.Id)).OrderBy(u => u.SortNo);
|
||||
}
|
||||
|
||||
|
14
OpenAuth.App/Define.cs
Normal file
14
OpenAuth.App/Define.cs
Normal file
@ -0,0 +1,14 @@
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public static class Define
|
||||
{
|
||||
public const string ROLERESOURCE= "RoleResource"; //角色资源关联KEY
|
||||
public const string USERRESOURCE = "UserResource"; //用户资源关联KEY
|
||||
public const string USERORG = "UserOrg"; //用户机构关联KEY
|
||||
public const string ROLEORG = "RoleOrg"; //角色机构关联KEY
|
||||
public const string USERELEMENT = "UserElement"; //用户菜单关联KEY
|
||||
public const string ROLEELEMENT = "RoleElement"; //角色菜单关联KEY
|
||||
public const string USERMODULE = "UserModule"; //用户模块关联KEY
|
||||
public const string ROLEMODULE = "RoleModule"; //角色模块关联KEY
|
||||
}
|
||||
}
|
@ -106,6 +106,7 @@
|
||||
<Compile Include="BaseApp.cs" />
|
||||
<Compile Include="AuthorizeApp.cs" />
|
||||
<Compile Include="CategoryApp.cs" />
|
||||
<Compile Include="Define.cs" />
|
||||
<Compile Include="Extention\IWF_Runtime.cs" />
|
||||
<Compile Include="Extention\WF_Runtime.cs" />
|
||||
<Compile Include="Extention\WF_RuntimeInitModel.cs" />
|
||||
|
@ -74,8 +74,8 @@ namespace OpenAuth.App
|
||||
var moduleIds =
|
||||
UnitWork.Find<Relevance>(
|
||||
u =>
|
||||
(u.FirstId == userId && u.Key == "UserOrg") ||
|
||||
(u.Key == "RoleOrg" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId).ToList();
|
||||
(u.FirstId == userId && u.Key == Define.USERORG) ||
|
||||
(u.Key == Define.ROLEORG && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId).ToList();
|
||||
|
||||
if (!moduleIds.Any()) return new List<Org>();
|
||||
return UnitWork.Find<Org>(u => moduleIds.Contains(u.Id)).ToList();
|
||||
@ -88,7 +88,7 @@ namespace OpenAuth.App
|
||||
public List<Org> LoadForRole(string roleId)
|
||||
{
|
||||
var moduleIds =
|
||||
UnitWork.Find<Relevance>(u => u.FirstId == roleId && u.Key == "RoleOrg")
|
||||
UnitWork.Find<Relevance>(u => u.FirstId == roleId && u.Key == Define.ROLEORG)
|
||||
.Select(u => u.SecondId)
|
||||
.ToList();
|
||||
if (!moduleIds.Any()) return new List<Org>();
|
||||
|
@ -12,7 +12,7 @@ namespace OpenAuth.App
|
||||
/// 添加关联
|
||||
/// <para>比如给用户分配资源,那么firstId就是用户ID,secIds就是资源ID列表</para>
|
||||
/// </summary>
|
||||
/// <param name="type">关联的类型,如"UserResource"</param>
|
||||
/// <param name="type">关联的类型,如Define.USERRESOURCE</param>
|
||||
public void Assign(string type, string firstId, string[] secIds)
|
||||
{
|
||||
Assign(type, secIds.ToLookup(u => firstId));
|
||||
@ -54,7 +54,7 @@ namespace OpenAuth.App
|
||||
/// <summary>
|
||||
/// 取消关联
|
||||
/// </summary>
|
||||
/// <param name="type">关联的类型,如"UserResource"</param>
|
||||
/// <param name="type">关联的类型,如Define.USERRESOURCE</param>
|
||||
/// <param name="firstId">The first identifier.</param>
|
||||
/// <param name="secIds">The sec ids.</param>
|
||||
public void UnAssign(string type, string firstId, string[] secIds)
|
||||
|
@ -3,47 +3,50 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.App.Response;
|
||||
using OpenAuth.App.SSO;
|
||||
using OpenAuth.Repository.Domain;
|
||||
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class UserManagerApp :BaseApp<User>
|
||||
public class UserManagerApp : BaseApp<User>
|
||||
{
|
||||
public RevelanceManagerApp ReleManagerApp { get; set; }
|
||||
|
||||
public User Get(string account)
|
||||
public User Get(string account)
|
||||
{
|
||||
return Repository.FindSingle(u => u.Account == account);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载一个部门及子部门全部用户
|
||||
/// 加载当前登录用户可访问的一个部门及子部门全部用户
|
||||
/// </summary>
|
||||
public TableData Load(QueryUserListReq request)
|
||||
{
|
||||
IEnumerable<User> users;
|
||||
int records = 0;
|
||||
if (string.IsNullOrEmpty(request.orgId))
|
||||
var loginUser = AuthUtil.GetCurrentUser();
|
||||
|
||||
string cascadeId = ".0.";
|
||||
if (!string.IsNullOrEmpty(request.orgId))
|
||||
{
|
||||
users = Repository.Find(null).OrderBy(u => u.Id).Skip((request.page - 1) * request.limit).Take(request.limit);
|
||||
records = Repository.GetCount();
|
||||
}
|
||||
else
|
||||
{
|
||||
var ids = GetSubOrgIds(request.orgId);
|
||||
List<string> userIds = ReleManagerApp.Get("UserOrg", false, ids);
|
||||
users = UnitWork.Find<User>(u =>userIds.Contains(u.Id))
|
||||
.OrderBy(u => u.Name)
|
||||
.Skip((request.page - 1) * request.limit)
|
||||
.Take(request.limit);
|
||||
records = Repository.GetCount(u => userIds.Contains(u.Id));
|
||||
var org = loginUser.Orgs.SingleOrDefault(u => u.Id == request.orgId);
|
||||
cascadeId = org.CascadeId;
|
||||
}
|
||||
|
||||
var ids = loginUser.Orgs.Where(u => u.CascadeId.Contains(cascadeId)).Select(u => u.Id).ToArray();
|
||||
var userIds = ReleManagerApp.Get(Define.USERORG, false, ids);
|
||||
|
||||
var users = UnitWork.Find<User>(u => userIds.Contains(u.Id))
|
||||
.OrderBy(u => u.Name)
|
||||
.Skip((request.page - 1) * request.limit)
|
||||
.Take(request.limit);
|
||||
|
||||
var records = Repository.GetCount(u => userIds.Contains(u.Id));
|
||||
|
||||
|
||||
var userviews = new List<UserView>();
|
||||
foreach (var user in users)
|
||||
{
|
||||
UserView uv = user;
|
||||
UserView uv = user;
|
||||
var orgs = LoadByUser(user.Id);
|
||||
uv.Organizations = string.Join(",", orgs.Select(u => u.Name).ToList());
|
||||
uv.OrganizationIds = string.Join(",", orgs.Select(u => u.Id).ToList());
|
||||
@ -57,33 +60,6 @@ namespace OpenAuth.App
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前组织的所有下级组织
|
||||
/// </summary>
|
||||
private string[] GetSubOrgIds(string orgId)
|
||||
{
|
||||
var org = UnitWork.FindSingle<Org>(u => u.Id == orgId);
|
||||
var orgs = UnitWork.Find<Org>(u => u.CascadeId.Contains(org.CascadeId))
|
||||
.Select(u => u.Id).ToArray();
|
||||
return orgs;
|
||||
}
|
||||
|
||||
public UserView Find(string id)
|
||||
{
|
||||
var user = Repository.FindSingle(u => u.Id == id);
|
||||
if (user == null) return new UserView();
|
||||
|
||||
UserView view = user;
|
||||
foreach (var org in LoadByUser(id))
|
||||
{
|
||||
view.Organizations += "," + org.Name;
|
||||
view.OrganizationIds += "," + org.Id;
|
||||
}
|
||||
view.OrganizationIds = view.OrganizationIds.TrimStart(',');
|
||||
view.Organizations = view.Organizations.TrimStart(',');
|
||||
return view;
|
||||
}
|
||||
|
||||
public void AddOrUpdate(UserView view)
|
||||
{
|
||||
if (string.IsNullOrEmpty(view.OrganizationIds))
|
||||
@ -113,8 +89,8 @@ namespace OpenAuth.App
|
||||
}
|
||||
string[] orgIds = view.OrganizationIds.Split(',').ToArray();
|
||||
|
||||
ReleManagerApp.DeleteBy("UserOrg", user.Id);
|
||||
ReleManagerApp.AddRelevance("UserOrg", orgIds.ToLookup(u => user.Id));
|
||||
ReleManagerApp.DeleteBy(Define.USERORG, user.Id);
|
||||
ReleManagerApp.AddRelevance(Define.USERORG, orgIds.ToLookup(u => user.Id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -123,9 +99,9 @@ namespace OpenAuth.App
|
||||
public IEnumerable<Org> LoadByUser(string userId)
|
||||
{
|
||||
var result = from userorg in UnitWork.Find<Relevance>(null)
|
||||
join org in UnitWork.Find<Org>(null) on userorg.SecondId equals org.Id
|
||||
where userorg.FirstId == userId && userorg.Key == "UserOrg"
|
||||
select org;
|
||||
join org in UnitWork.Find<Org>(null) on userorg.SecondId equals org.Id
|
||||
where userorg.FirstId == userId && userorg.Key == Define.USERORG
|
||||
select org;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
|
||||
var moduleWithChildren = AuthUtil.GetCurrentUser().Modules
|
||||
.GenerateTree(u =>u.Id, u =>u.ParentId);
|
||||
var modules = key == "UserModule" ? App.LoadForUser(firstId) : App.LoadForRole(firstId);
|
||||
var modules = key == Define.USERMODULE ? App.LoadForUser(firstId) : App.LoadForRole(firstId);
|
||||
|
||||
CheckModule(moduleWithChildren, modules);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user