增加功能:MongoDB数据库支持角色对应用程序授权功能 #IRY3N

This commit is contained in:
Argo-Surface 2019-02-24 17:28:10 +08:00
parent 006c91c198
commit c262c09c5f
3 changed files with 50 additions and 3 deletions

View File

@ -0,0 +1,39 @@
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Bootstrap.DataAccess.MongoDB
{
public class App : DataAccess.App
{
/// <summary>
/// 根据角色ID指派部门
/// </summary>
/// <param name="roleId"></param>
/// <returns></returns>
public override IEnumerable<DataAccess.App> RetrievesByRoleId(string roleId)
{
var apps = DictHelper.RetrieveApps().Where(d => d.Key.CompareTo("0") > 0).Select(d => new DataAccess.App()
{
Id = d.Key,
AppName = d.Value
}).ToList();
var role = RoleHelper.Retrieves().Cast<Role>().FirstOrDefault(r => r.Id == roleId);
apps.ForEach(p => p.Checked = (role != null && role.Apps.Contains(p.Id)) ? "checked" : "");
return apps;
}
/// <summary>
/// 根据角色ID以及选定的App ID保到角色应用表
/// </summary>
/// <param name="roleId"></param>
/// <param name="appIds"></param>
/// <returns></returns>
public override bool SaveByRoleId(string roleId, IEnumerable<string> appIds)
{
var ret = DbManager.Roles.UpdateOne(md => md.Id == roleId, Builders<Role>.Update.Set(md => md.Apps, appIds));
return true;
}
}
}

View File

@ -14,6 +14,11 @@ namespace Bootstrap.DataAccess.MongoDB
/// </summary> /// </summary>
public IEnumerable<string> Menus { get; set; } public IEnumerable<string> Menus { get; set; }
/// <summary>
/// 此角色关联的所有应用程序
/// </summary>
public IEnumerable<string> Apps { get; set; }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
@ -38,7 +43,8 @@ namespace Bootstrap.DataAccess.MongoDB
{ {
RoleName = p.RoleName, RoleName = p.RoleName,
Description = p.Description, Description = p.Description,
Menus = new List<string>() Menus = new List<string>(),
Apps = new List<string>()
}); });
return true; return true;
} }

View File

@ -25,7 +25,8 @@
"5bd7b8445fa31256f77e4ba2", "5bd7b8445fa31256f77e4ba2",
"5bd9b3d868aa001661776f56", "5bd9b3d868aa001661776f56",
"5bd7b8445fa31256f77e4ba4" "5bd7b8445fa31256f77e4ba4"
] ],
"Apps": []
}, },
{ {
"_id": ObjectId("5bd7cc105fa31256f77e4eb8"), "_id": ObjectId("5bd7cc105fa31256f77e4eb8"),
@ -45,6 +46,7 @@
"5bd7b8445fa31256f77e4ba2", "5bd7b8445fa31256f77e4ba2",
"5bd9b3d868aa001661776f56", "5bd9b3d868aa001661776f56",
"5bd7b8445fa31256f77e4ba4" "5bd7b8445fa31256f77e4ba4"
] ],
"Apps": []
} }
] ]