NormalAuthStrategy.cs
3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// ***********************************************************************
// <summary>
// 普通用户授权策略
// </summary>
// ***********************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using WebRepository;
namespace WebApp
{
/// <summary>
/// 普通用户授权策略
/// </summary>
public class NormalAuthStrategy : WebApp<SysUser>, IAuthStrategy
{
protected SysUser _user;
private List<int> _userRoleIds; //用户角色
public List<SysModuleView> Modules
{
get
{
var moduleIds = UnitWork.Find<SysRelevance>(
u =>
(u.FirstId == _user.Id && u.RelKey == Define.USERMODULE) ||
(u.RelKey == Define.ROLEMODULE && _userRoleIds.Contains(u.FirstId.Value))).Select(u => u.SecondId);
var modules = (from module in UnitWork.Find<SysModule>(u => moduleIds.Contains(u.Id))
select new SysModuleView
{
Name = module.Name,
Code = module.Code,
CascadeId = module.CascadeId,
Id = module.Id.Value,
IconName = module.IconName,
Url = module.Url,
ParentId = module.ParentId,
ParentName = module.ParentName,
SortNo = module.SortNo.Value,
IsShow = module.IsShow.Value,
}).OrderBy(u => u.SortNo).ToList();
var elementIds = UnitWork.Find<SysRelevance>(
u =>
(u.FirstId == _user.Id && u.RelKey == Define.USERELEMENT) ||
(u.RelKey == Define.ROLEELEMENT && _userRoleIds.Contains(u.FirstId.Value))).Select(u => u.SecondId);
var usermoduleelements = UnitWork.Find<SysModuleElement>(u => elementIds.Contains(u.Id));
foreach (var module in modules)
{
module.Elements = usermoduleelements.Where(u => u.ModuleId == module.Id).OrderBy(u => u.Sort).ToList();
}
return modules;
}
}
public List<SysRole> Roles
{
get { return UnitWork.Find<SysRole>(u => _userRoleIds.Contains(u.Id.Value)).ToList(); }
}
public List<SysDept> Orgs
{
get
{
var orgids = UnitWork.Find<SysRelevance>(
u =>
(u.FirstId == _user.Id && u.RelKey == Define.USERORG) ||
(u.RelKey == Define.ROLEORG && _userRoleIds.Contains(u.FirstId.Value))).Select(u => u.SecondId);
return UnitWork.Find<SysDept>(u => orgids.Contains(u.Id)).ToList();
}
}
public SysUser User
{
get { return _user; }
set
{
_user = value;
_userRoleIds = UnitWork.Find<SysRelevance>(u => u.FirstId == _user.Id && u.RelKey == Define.USERROLE).Select(u => u.SecondId.Value).ToList();
}
}
public NormalAuthStrategy(IUnitWork unitWork, IRepository<SysUser> repository) : base(unitWork, repository)
{
}
}
}