mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-12-26 22:25:39 +08:00
增加撤销与启动,详见:#I3ILBG
调整工程结构,采用模块化机制
This commit is contained in:
64
OpenAuth.App/Resources/Request/AddOrUpdateResReq.cs
Normal file
64
OpenAuth.App/Resources/Request/AddOrUpdateResReq.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <autogenerated>
|
||||
// This code was generated by a CodeSmith Template.
|
||||
//
|
||||
// DO NOT MODIFY contents of this file. Changes to this
|
||||
// file will be lost if the code is regenerated.
|
||||
// Author:Yubao Li
|
||||
// </autogenerated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace OpenAuth.Repository.Domain
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源表
|
||||
/// </summary>
|
||||
public class AddOrUpdateResReq
|
||||
{
|
||||
public string Id { get; set; }
|
||||
/// <summary>
|
||||
/// 节点语义ID
|
||||
/// </summary>
|
||||
public string CascadeId { get; set; }
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
/// <summary>
|
||||
/// 排序号
|
||||
/// </summary>
|
||||
public int SortNo { get; set; }
|
||||
/// <summary>
|
||||
/// 描述
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
/// <summary>
|
||||
/// 父节点名称
|
||||
/// </summary>
|
||||
public string ParentName { get; set; }
|
||||
/// <summary>
|
||||
/// 父节点流ID
|
||||
/// </summary>
|
||||
public string ParentId { get; set; }
|
||||
/// <summary>
|
||||
/// 资源所属应用ID
|
||||
/// </summary>
|
||||
public string AppId { get; set; }
|
||||
/// <summary>
|
||||
/// 所属应用名称
|
||||
/// </summary>
|
||||
public string AppName { get; set; }
|
||||
/// <summary>
|
||||
/// 分类名称
|
||||
/// </summary>
|
||||
public string TypeName { get; set; }
|
||||
/// <summary>
|
||||
/// 分类ID
|
||||
/// </summary>
|
||||
public string TypeId { get; set; }
|
||||
/// <summary>
|
||||
/// 是否可用
|
||||
/// </summary>
|
||||
public bool Disable { get; set; }
|
||||
}
|
||||
}
|
||||
11
OpenAuth.App/Resources/Request/QueryResourcesReq.cs
Normal file
11
OpenAuth.App/Resources/Request/QueryResourcesReq.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace OpenAuth.App.Request
|
||||
{
|
||||
public class QueryResourcesReq : PageReq
|
||||
{
|
||||
/// <summary>
|
||||
/// TypeID
|
||||
/// </summary>
|
||||
public string appId { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
95
OpenAuth.App/Resources/ResourceApp.cs
Normal file
95
OpenAuth.App/Resources/ResourceApp.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Infrastructure;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.App.Response;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
/// <summary>
|
||||
/// 分类管理
|
||||
/// </summary>
|
||||
public class ResourceApp:BaseStringApp<Resource,OpenAuthDBContext>
|
||||
{
|
||||
private RevelanceManagerApp _revelanceApp;
|
||||
|
||||
public void Add(AddOrUpdateResReq resource)
|
||||
{
|
||||
var obj = resource.MapTo<Resource>();
|
||||
CaculateCascade(obj);
|
||||
obj.CreateTime = DateTime.Now;
|
||||
var user = _auth.GetCurrentUser().User;
|
||||
obj.CreateUserId = user.Id;
|
||||
obj.CreateUserName = user.Name;
|
||||
Repository.Add(obj);
|
||||
}
|
||||
|
||||
public void Update(AddOrUpdateResReq obj)
|
||||
{
|
||||
var user = _auth.GetCurrentUser().User;
|
||||
UnitWork.Update<Category>(u => u.Id == obj.Id, u => new Category
|
||||
{
|
||||
TypeId = obj.TypeId,
|
||||
UpdateTime = DateTime.Now,
|
||||
UpdateUserId = user.Id,
|
||||
UpdateUserName = user.Name
|
||||
//todo:要修改的字段赋值
|
||||
});
|
||||
}
|
||||
|
||||
public IEnumerable<Resource> LoadForRole(string appId, string roleId)
|
||||
{
|
||||
var elementIds = _revelanceApp.Get(Define.ROLERESOURCE, true, roleId);
|
||||
return UnitWork.Find<Resource>(u => elementIds.Contains(u.Id) && (appId == null || appId =="" || u.AppId == appId));
|
||||
}
|
||||
|
||||
public async Task<TableData> Load(QueryResourcesReq request)
|
||||
{
|
||||
var loginContext = _auth.GetCurrentUser();
|
||||
if (loginContext == null)
|
||||
{
|
||||
throw new CommonException("登录已过期", Define.INVALID_TOKEN);
|
||||
}
|
||||
|
||||
var properties = loginContext.GetProperties("Resource");
|
||||
|
||||
if (properties == null || properties.Count == 0)
|
||||
{
|
||||
throw new Exception("当前登录用户没有访问该模块字段的权限,请联系管理员配置");
|
||||
}
|
||||
|
||||
|
||||
var result = new TableData();
|
||||
var resources = GetDataPrivilege("u");
|
||||
if (!string.IsNullOrEmpty(request.key))
|
||||
{
|
||||
resources = resources.Where(u => u.Name.Contains(request.key) || u.Id.Contains(request.key));
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(request.appId))
|
||||
{
|
||||
resources = resources.Where(u => u.AppId == request.appId);
|
||||
}
|
||||
|
||||
var propertyStr = string.Join(',', properties.Select(u => u.Key));
|
||||
result.columnHeaders = properties;
|
||||
result.data = resources.OrderBy(u => u.TypeId)
|
||||
.Skip((request.page - 1) * request.limit)
|
||||
.Take(request.limit).Select($"new ({propertyStr})");
|
||||
result.count = resources.Count();
|
||||
return result;
|
||||
}
|
||||
|
||||
public ResourceApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<Resource,OpenAuthDBContext> repository
|
||||
,RevelanceManagerApp app,IAuth auth) : base(unitWork, repository, auth)
|
||||
{
|
||||
_revelanceApp = app;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user