parent
045ffc8ce2
commit
81b3390363
|
@ -1,5 +1,6 @@
|
|||
using Bootstrap.Security;
|
||||
using MongoDB.Driver;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
|
@ -17,14 +18,30 @@ namespace Bootstrap.DataAccess.MongoDB
|
|||
/// <returns></returns>
|
||||
public override IEnumerable<BootstrapMenu> RetrieveAllMenus(string userName)
|
||||
{
|
||||
var user = UserHelper.Retrieves().Cast<User>().FirstOrDefault(u => u.UserName.ToLowerInvariant() == userName.ToLowerInvariant());
|
||||
if (user == null) return Enumerable.Empty<BootstrapMenu>();
|
||||
|
||||
var dicts = DictHelper.RetrieveDicts().Where(m => m.Category == "菜单");
|
||||
|
||||
var menus = DbManager.Menus.Find(FilterDefinition<BootstrapMenu>.Empty).ToList();
|
||||
// 通过用户获取 角色列表
|
||||
var roles = RoleHelper.Retrieves().Cast<Role>().Where(r => user.Roles.Any(rl => rl == r.Id)).ToList();
|
||||
|
||||
// 通过用户获取 组列表相关联的角色列表
|
||||
roles = GroupHelper.RetrievesByUserName(userName).Aggregate(roles, (r, g) =>
|
||||
{
|
||||
r.AddRange(RoleHelper.RetrievesByGroupId(g.Id).Cast<Role>());
|
||||
return r;
|
||||
}).Distinct().ToList();
|
||||
|
||||
var menus = DbManager.Menus.Find(FilterDefinition<BootstrapMenu>.Empty).ToList()
|
||||
.Where(m => roles.Any(r => r.RoleName.Equals("Administrators", StringComparison.OrdinalIgnoreCase) || r.Menus.Any(rm => rm.Equals(m.Url, StringComparison.OrdinalIgnoreCase))))
|
||||
.ToList();
|
||||
menus.ForEach(m =>
|
||||
{
|
||||
m.CategoryName = dicts.FirstOrDefault(d => d.Code == m.Category)?.Name;
|
||||
if (m.ParentId != "0") m.ParentName = menus.FirstOrDefault(p => p.Id == m.ParentId)?.Name;
|
||||
});
|
||||
|
||||
return menus;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue