diff --git a/Bootstrap.DataAccess.MongoDB/Menu.cs b/Bootstrap.DataAccess.MongoDB/Menu.cs
index af546032..d48d9986 100644
--- a/Bootstrap.DataAccess.MongoDB/Menu.cs
+++ b/Bootstrap.DataAccess.MongoDB/Menu.cs
@@ -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
///
public override IEnumerable RetrieveAllMenus(string userName)
{
+ var user = UserHelper.Retrieves().Cast().FirstOrDefault(u => u.UserName.ToLowerInvariant() == userName.ToLowerInvariant());
+ if (user == null) return Enumerable.Empty();
+
var dicts = DictHelper.RetrieveDicts().Where(m => m.Category == "菜单");
- var menus = DbManager.Menus.Find(FilterDefinition.Empty).ToList();
+ // 通过用户获取 角色列表
+ var roles = RoleHelper.Retrieves().Cast().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());
+ return r;
+ }).Distinct().ToList();
+
+ var menus = DbManager.Menus.Find(FilterDefinition.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;
}