拦截 处理签名系统文档 添加更新项目

Uat_Study
{872297557@qq.com} 2023-01-06 16:00:52 +08:00
parent 8838871c0d
commit 27f40962f7
6 changed files with 36 additions and 17 deletions

View File

@ -52,7 +52,7 @@ namespace IRaCIS.Core.API.Controllers.Special
[HttpPost, Route("trial/addOrUpdateTrial")] [HttpPost, Route("trial/addOrUpdateTrial")]
[Authorize(Policy = IRaCISPolicy.PM_APM)] [Authorize(Policy = IRaCISPolicy.PM_APM)]
[TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "AfterStopCannNotOpt" })] [TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "AddOrUpdateTrial", "BeforeOngoingCantOpt", "AfterStopCannNotOpt" })]
public async Task<IResponseOutput<Trial>> AddOrUpdateTrial(TrialCommand param) public async Task<IResponseOutput<Trial>> AddOrUpdateTrial(TrialCommand param)
{ {
var userId = Guid.Parse(User.FindFirst("id").Value); var userId = Guid.Parse(User.FindFirst("id").Value);

View File

@ -428,7 +428,7 @@ namespace IRaCIS.Core.API.Controllers
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[HttpPost, Route("Inspection/TrialDocument/userConfirm")] [HttpPost, Route("Inspection/TrialDocument/userConfirm")]
[TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "AfterStopCannNotOpt" })] [TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "SignSystemDocNoTrialId", "AfterStopCannNotOpt" })]
[UnitOfWork] [UnitOfWork]
public async Task<IResponseOutput> UserConfirm(DataInspectionDto<UserConfirmCommand> opt) public async Task<IResponseOutput> UserConfirm(DataInspectionDto<UserConfirmCommand> opt)
{ {

View File

@ -11,35 +11,46 @@ namespace IRaCIS.Core.Application.Filter
/// <summary> /// <summary>
/// 主要为了 处理项目结束 锁库,不允许操作 /// 主要为了 处理项目结束 锁库,不允许操作
/// </summary> /// </summary>
public class TrialResourceFilter : Attribute, IAsyncResourceFilter public class TrialResourceFilter : Attribute, IAsyncResourceFilter
{ {
private readonly IEasyCachingProvider _provider; private readonly IEasyCachingProvider _provider;
private readonly IUserInfo _userInfo; private readonly IUserInfo _userInfo;
private readonly string _trialOpt;
//private readonly List<string> _trialOptList; private readonly List<string> _trialOptList=new List<string>();
public TrialResourceFilter(IEasyCachingProvider provider, IUserInfo userInfo, string trialOpt) public TrialResourceFilter(IEasyCachingProvider provider, IUserInfo userInfo, string trialOpt = null, string trialOpt2 = null, string trialOpt3 = null)
{ {
_provider = provider; _provider = provider;
_userInfo = userInfo; _userInfo = userInfo;
_trialOpt = trialOpt; //_trialOpt = trialOpt;
if (!string.IsNullOrWhiteSpace(trialOpt)) _trialOptList.Add(trialOpt);
if (!string.IsNullOrWhiteSpace(trialOpt2)) _trialOptList.Add(trialOpt2);
if (!string.IsNullOrWhiteSpace(trialOpt3)) _trialOptList.Add(trialOpt3);
} }
//public TrialResourceFilter(IEasyCachingProvider provider, IUserInfo userInfo, List<string> trialOptList=new list)
//public TrialResourceFilter(IEasyCachingProvider provider, IUserInfo userInfo)
//{ //{
// _provider = provider; // _provider = provider;
// _userInfo = userInfo; // _userInfo = userInfo;
// _trialOptList = trialOptList;
//} //}
//优先选择异步的方法 //优先选择异步的方法
public async Task OnResourceExecutionAsync(ResourceExecutingContext context, ResourceExecutionDelegate next) public async Task OnResourceExecutionAsync(ResourceExecutingContext context, ResourceExecutionDelegate next)
{ {
// var typeFilter = context.ActionDescriptor.EndpointMetadata.Where(t => t.GetType() == typeof(TypeFilterAttribute)).Select(t => (TypeFilterAttribute)t).ToList().FirstOrDefault();
//var _trialOptList= typeFilter.Arguments.Select(t => t.ToString()).ToList();
#region 处理新的用户类型,不能操作项目相关接口 #region 处理新的用户类型,不能操作项目相关接口
// 后期列举出具体的类型,其他任何用户类型,都不允许操作 // 后期列举出具体的类型,其他任何用户类型,都不允许操作
@ -118,7 +129,7 @@ namespace IRaCIS.Core.Application.Filter
} }
//使用字符串取 如果是swagger 可能有时取的不对 因为空格的原因 //使用字符串取 如果是swagger 可能有时取的不对 因为空格的原因
//trialIdStr = contentFromBody.Substring(trialIdIndex + "TrialId".Length + 4, 36); //trialIdStr = contentFromBody.Substring(trialIdIndex + "TrialId".Length + 4, 3
} }
#endregion #endregion
@ -145,7 +156,7 @@ namespace IRaCIS.Core.Application.Filter
var trialStatusStr = cacheResultDic[trialIdStr]; var trialStatusStr = cacheResultDic[trialIdStr];
// 这里是统一拦截 项目有关的操作允许情况(特殊的地方比如项目配置有的在多种状态初始化ongoing都可以操作有的仅仅在Initializing还有 项目添加和更新,不走这里,特殊处理,不然在这里显得很乱,判断是哪个接口) // 这里是统一拦截 项目有关的操作允许情况(特殊的地方比如项目配置有的在多种状态初始化ongoing都可以操作有的仅仅在Initializing还有 项目添加和更新,不走这里,特殊处理,不然在这里显得很乱,判断是哪个接口)
if (trialStatusStr.Value == StaticData.TrialState.TrialOngoing || _trialOpt == TrialOpt.BeforeOngoingCantOpt) if (trialStatusStr.Value == StaticData.TrialState.TrialOngoing || _trialOptList.Any(t=>t== TrialOpt.BeforeOngoingCantOpt) )
{ {
await next.Invoke(); await next.Invoke();
@ -159,7 +170,10 @@ namespace IRaCIS.Core.Application.Filter
} }
} }
else if (_trialOptList.Any(t => t == TrialOpt.AddOrUpdateTrial ||t ==TrialOpt.SignSystemDocNoTrialId))
{
await next.Invoke();
}
else else
{ {

View File

@ -876,7 +876,7 @@ namespace IRaCIS.Core.Application
/// <returns></returns> /// <returns></returns>
[HttpPut("{trialId:guid}/{isAbandon:bool}")] [HttpPut("{trialId:guid}/{isAbandon:bool}")]
[Authorize(Policy = IRaCISPolicy.PM)] [Authorize(Policy = IRaCISPolicy.PM)]
[TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "AfterStopCannNotOpt" })] [TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "AfterStopCannNotOpt", "AfterStopCannNotOpt" })]
public async Task<IResponseOutput> AbandonTrial(Guid trialId, /*Guid? signId,*/ bool isAbandon) public async Task<IResponseOutput> AbandonTrial(Guid trialId, /*Guid? signId,*/ bool isAbandon)
{ {
@ -911,7 +911,7 @@ namespace IRaCIS.Core.Application
/// <param name="trialConfig"></param> /// <param name="trialConfig"></param>
/// <returns></returns> /// <returns></returns>
[HttpPut] [HttpPut]
[TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "BeforeOngoingCantOpt" })] [TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "BeforeOngoingCantOpt", "AfterStopCannNotOpt" })]
//[TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "AfterStopCannNotOpt" })] //[TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "AfterStopCannNotOpt" })]
public async Task<IResponseOutput> ConfigTrialTaskInfo(TrialTaskConfig trialConfig) public async Task<IResponseOutput> ConfigTrialTaskInfo(TrialTaskConfig trialConfig)
{ {
@ -929,7 +929,7 @@ namespace IRaCIS.Core.Application
/// <param name="trialConfig"></param> /// <param name="trialConfig"></param>
/// <returns></returns> /// <returns></returns>
[HttpPut] [HttpPut]
[TypeFilter(typeof(TrialResourceFilter),Arguments = new object[] { "BeforeOngoingCantOpt" })] [TypeFilter(typeof(TrialResourceFilter),Arguments = new object[] { "BeforeOngoingCantOpt", "AfterStopCannNotOpt" })]
//[TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "AfterStopCannNotOpt" })] //[TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "AfterStopCannNotOpt" })]
public async Task<IResponseOutput> ConfigTrialReadingTaskViewRule(TrialReadingTaskViewConfig trialConfig) public async Task<IResponseOutput> ConfigTrialReadingTaskViewRule(TrialReadingTaskViewConfig trialConfig)
{ {

View File

@ -104,7 +104,7 @@ namespace IRaCIS.Application.Services
[UnitOfWork] [UnitOfWork]
[HttpPost] [HttpPost]
[Authorize(Policy = IRaCISPolicy.PM_APM)] [Authorize(Policy = IRaCISPolicy.PM_APM)]
[TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "BeforeOngoingCantOpt" })] [TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "BeforeOngoingCantOpt", "AfterStopCannNotOpt" })]
//[TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "AfterStopCannNotOpt" })] //[TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "AfterStopCannNotOpt" })]
public async Task<IResponseOutput> AddOrUpdateVisitStage(VisitPlanCommand visitPlan) public async Task<IResponseOutput> AddOrUpdateVisitStage(VisitPlanCommand visitPlan)
{ {
@ -207,7 +207,7 @@ namespace IRaCIS.Application.Services
[UnitOfWork] [UnitOfWork]
[HttpPost("{trialId:guid}")] [HttpPost("{trialId:guid}")]
[Authorize(Policy = IRaCISPolicy.PM_APM)] [Authorize(Policy = IRaCISPolicy.PM_APM)]
[TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "BeforeOngoingCantOpt" })] [TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "BeforeOngoingCantOpt", "AfterStopCannNotOpt" })]
//[TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "AfterStopCannNotOpt" })] //[TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "AfterStopCannNotOpt" })]
public async Task<IResponseOutput> ConfirmTrialVisitPlan(Guid trialId) public async Task<IResponseOutput> ConfirmTrialVisitPlan(Guid trialId)
{ {

View File

@ -58,6 +58,11 @@ public static class StaticData
//ongoing 前能操作 但是Stop后 也不能操作 //ongoing 前能操作 但是Stop后 也不能操作
public static readonly string BeforeOngoingCantOpt = "BeforeOngoingCantOpt"; public static readonly string BeforeOngoingCantOpt = "BeforeOngoingCantOpt";
public static readonly string AddOrUpdateTrial = "AddOrUpdateTrial";
public static readonly string SignSystemDocNoTrialId = "SignSystemDocNoTrialId";
} }