修改项目状态拦截处理

Test.EIImageViewer
hang 2022-05-23 12:07:26 +08:00
parent c34e9dbda9
commit 97744b76d0
2 changed files with 15 additions and 35 deletions

View File

@ -31,6 +31,7 @@ namespace IRaCIS.Core.Application.Filter
{
#region 处理新的用户类型,不能操作项目相关接口
/// 后期列举出具体的类型,其他任何用户类型,都不允许操作
if( _userInfo.UserTypeEnumInt == (int)UserTypeEnum.CRA)
{
context.Result = new JsonResult(ResponseOutput.NotOk("Sorry,Your UserType does not allow this operation"));
@ -40,9 +41,7 @@ namespace IRaCIS.Core.Application.Filter
#endregion
//bool isEditTrialStatus = context.ActionDescriptor.DisplayName==null? false:context.ActionDescriptor.DisplayName.Contains("UpdateTrialStatus");
//bool isTrialAdd = context.ActionDescriptor.DisplayName == null ? false: context.ActionDescriptor.DisplayName.Contains("AddOrUpdateTrial");
//TrialId 传递的途径多种可能在path 可能在body 可能在数组中也可能在对象中可能就在url
var trialIdStr = string.Empty;
@ -72,31 +71,15 @@ namespace IRaCIS.Core.Application.Filter
{
trialIdStr = contentFromBody.Substring(trialIdIndex + "TrialId".Length + 4, 36);
}
//else if(isTrialAdd)
//{
// //项目的添加和编辑时例外 trailId 在Id字段中 同时,添加和更新时有区别的
// trialIdIndex = contentFromBody.IndexOf("\"Id\"");
// //添加时为-1 不进行操作
// if (trialIdIndex != -1)
// {
// trialIdStr = contentFromBody.Substring(trialIdIndex + "Id".Length + 4, 36);
// trialIdStr = Guid.TryParse(trialIdStr, out var trialId) ? trialId.ToString() : String.Empty ;
// }
//}
#endregion
}
//通过path 或者body 找到trialId 了
if (trialIdStr != string.Empty)
{
//如果没缓存数据,是不允许的 意外情况IIS回收了导致定时任务没执行或者缓存丢失
//如果没缓存数据,可能定时任务没执行或者缓存丢失 在此重新缓存
if (_provider.GetCount() == 0)
{
@ -113,20 +96,21 @@ namespace IRaCIS.Core.Application.Filter
var trialStatusStr = cacheResultDic[trialIdStr];
//项目完成和停止,都不能操作
if (trialStatusStr.Value == StaticData.TrialCompleted || trialStatusStr.Value == StaticData.TrialStopped)
{
context.Result = new JsonResult(ResponseOutput.NotOk("Only trial in ongoing state can the operation be performed"));
}
////项目完成和停止,都不能操作
//if (trialStatusStr.Value == StaticData.TrialCompleted || trialStatusStr.Value == StaticData.TrialStopped)
//{
// context.Result = new JsonResult(ResponseOutput.NotOk("Only trial in ongoing state can the operation be performed"));
//}
//仅仅管理员 在项目暂停 并且是编辑项目接口时 才放开操作 遗漏了正常情况 TrialOngoing
if (/*(trialStatusStr.Value == StaticData.TrialPaused && _userInfo.UserTypeEnumInt == (int)UserTypeEnum.SuperAdmin && isEditTrialStatus)||*/ trialStatusStr.Value == StaticData.TrialOngoing)
// 这里是统一拦截 项目有关的操作允许情况(特殊的地方比如项目配置有的在多种状态初始化ongoing都可以操作有的仅仅在Initializing还有 项目添加和更新,不走这里,特殊处理,不然在这里显得很乱,判断是哪个接口)
if (trialStatusStr.Value == StaticData.TrialOngoing)
{
await next.Invoke();
}
//项目暂停的基础上,是其他人,或者不是编辑项目状态,那么要禁止操作
// 项目停止、或者完成 不允许操作
else
{
context.Result = new JsonResult(ResponseOutput.NotOk("Only trial in ongoing state can the operation be performed"));
@ -134,11 +118,7 @@ namespace IRaCIS.Core.Application.Filter
}
}
////没有找到trialId 判断是否是项目添加
//else if (isTrialAdd)
//{
// await next.Invoke();
//}
else
{
//如果项目相关接口没有传递trialId 会来到这里,提醒,以便修改

View File

@ -54,7 +54,7 @@ namespace IRaCIS.Core.Application
//验证 仅仅在 Initializing/Ongoing 才可以操作
private async Task VerifyOnlyInOngoingOrInitialIzingOptAsync(Guid trialId)
{
if (!await _trialRepository.AnyAsync(t => t.Id == signConfirmDTO.TrialId && (t.TrialStatusStr == StaticData.TrialInitializing || t.TrialStatusStr == StaticData.TrialOngoing)))
if (!await _trialRepository.AnyAsync(t => t.Id == trialId && (t.TrialStatusStr == StaticData.TrialInitializing || t.TrialStatusStr == StaticData.TrialOngoing)))
{
throw new BusinessValidationFailedException("项目不在Initializing/Ongoing不允许确认配置");
}
@ -146,7 +146,7 @@ namespace IRaCIS.Core.Application
[HttpPut]
public async Task<IResponseOutput> ConfigTrialBasicInfo(BasicTrialConfig trialConfig)
{
await VerifyOnlyInOngoingOrInitialIzingOptAsync(signConfirmDTO.TrialId);
await VerifyOnlyInOngoingOrInitialIzingOptAsync(trialConfig.TrialId);
var trialInfo = (await _trialRepository.FirstOrDefaultAsync(t => t.Id == trialConfig.TrialId)).IfNullThrowException();