2019-02-24 17:28:10 +08:00
|
|
|
|
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);
|
2019-02-24 20:01:10 +08:00
|
|
|
|
apps.ForEach(p => p.Checked = (role != null && (role.Apps.Contains(p.Id)) || role.RoleName.Equals("Administrators", StringComparison.OrdinalIgnoreCase)) ? "checked" : "");
|
2019-02-24 17:28:10 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
2019-02-25 14:41:04 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据指定用户名获得授权应用程序集合
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="userName"></param>
|
|
|
|
|
/// <returns></returns>
|
2019-02-25 15:14:09 +08:00
|
|
|
|
public override IEnumerable<string> RetrievesByUserName(string userName)
|
2019-02-25 14:41:04 +08:00
|
|
|
|
{
|
|
|
|
|
var ret = new List<string>();
|
|
|
|
|
var roles = RoleHelper.RetrieveRolesByUserName(userName);
|
|
|
|
|
if (roles.Contains("Administrators", StringComparer.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
ret.AddRange(DictHelper.RetrieveApps().Select(kv => kv.Key));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
RoleHelper.Retrieves().Cast<Role>().Where(r => roles.Any(rn => rn == r.RoleName)).ToList().ForEach(r => ret.AddRange(r.Apps));
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2019-02-24 17:28:10 +08:00
|
|
|
|
}
|
|
|
|
|
}
|