forked from Yara724/api
YARA-1045
This commit is contained in:
@@ -45,6 +45,10 @@ import {
|
||||
buildExpertAssignConflictForOtherReviewer,
|
||||
resolvePersistentReviewAssigneeId,
|
||||
} from "src/helpers/expert-workflow-review-assignee";
|
||||
import {
|
||||
EXPERT_WORKFLOW_LOCK_TTL_MS,
|
||||
expertWorkflowLockExpiredAt,
|
||||
} from "src/helpers/expert-workflow-lock";
|
||||
import { RequestManagementDbService } from "src/request-management/entities/db-service/request-management.db.service";
|
||||
import { BlameRequestDbService } from "src/request-management/entities/db-service/blame-request.db.service";
|
||||
import {
|
||||
@@ -110,9 +114,6 @@ function statementToFormKey(statement?: {
|
||||
export class ExpertBlameService {
|
||||
private readonly logger = new Logger(ExpertBlameService.name);
|
||||
|
||||
/** Blame V2 `workflow.locked` TTL (must match checks in lock/reply/resend). */
|
||||
private readonly blameV2LockTtlMs = 15 * 60 * 1000;
|
||||
|
||||
constructor(
|
||||
private readonly requestManagementDbService: RequestManagementDbService,
|
||||
private readonly blameRequestDbService: BlameRequestDbService,
|
||||
@@ -743,11 +744,11 @@ export class ExpertBlameService {
|
||||
}
|
||||
const la = doc.workflow.lockedAt;
|
||||
if (!la) return true;
|
||||
return Date.now() < new Date(la as Date).getTime() + this.blameV2LockTtlMs;
|
||||
return Date.now() < new Date(la as Date).getTime() + EXPERT_WORKFLOW_LOCK_TTL_MS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist unlock when blame V2 workflow lock is older than {@link blameV2LockTtlMs}.
|
||||
* Persist unlock when blame V2 workflow lock is older than {@link EXPERT_WORKFLOW_LOCK_TTL_MS}.
|
||||
* V1 uses in-memory `scheduleUnlock`; V2 only stored `workflow.lockedAt`, so locks never cleared until now.
|
||||
*/
|
||||
private async expireBlameCaseWorkflowLockV2IfStale(
|
||||
@@ -765,7 +766,7 @@ export class ExpertBlameService {
|
||||
}
|
||||
if (
|
||||
lockedAt &&
|
||||
Date.now() < new Date(lockedAt as Date).getTime() + this.blameV2LockTtlMs
|
||||
Date.now() < new Date(lockedAt as Date).getTime() + EXPERT_WORKFLOW_LOCK_TTL_MS
|
||||
) {
|
||||
return;
|
||||
}
|
||||
@@ -1244,7 +1245,7 @@ export class ExpertBlameService {
|
||||
throw new BadRequestException("Request is locked by another expert");
|
||||
}
|
||||
|
||||
const fifteenMinutes = new Date(Date.now() + 15 * 60 * 1000);
|
||||
const lockExpiresAt = expertWorkflowLockExpiredAt();
|
||||
const lockSnapshot = await this.snapshotFieldExpert(actorDetail.sub);
|
||||
|
||||
const updateResult = await this.requestManagementDbService.findOneAndUpdate(
|
||||
@@ -1256,7 +1257,7 @@ export class ExpertBlameService {
|
||||
$set: {
|
||||
lockFile: true,
|
||||
blameStatus: ReqBlameStatus.ReviewRequest,
|
||||
unlockTime: fifteenMinutes,
|
||||
unlockTime: lockExpiresAt,
|
||||
lockTime: new Date(),
|
||||
actorLocked: {
|
||||
fullName: actorDetail.fullName,
|
||||
@@ -1433,7 +1434,7 @@ export class ExpertBlameService {
|
||||
$set: {
|
||||
"workflow.locked": true,
|
||||
"workflow.lockedAt": now,
|
||||
"workflow.expiredAt": new Date(now.getTime() + this.blameV2LockTtlMs),
|
||||
"workflow.expiredAt": new Date(now.getTime() + EXPERT_WORKFLOW_LOCK_TTL_MS),
|
||||
"workflow.lockedBy": lockedByPayload,
|
||||
},
|
||||
$push: {
|
||||
@@ -1564,7 +1565,7 @@ export class ExpertBlameService {
|
||||
}
|
||||
|
||||
/**
|
||||
* V2: Lock blame case for 15 minutes (blameCases collection).
|
||||
* V2: Lock blame case for 30 minutes (blameCases collection).
|
||||
* Delegates to {@link assignBlameCaseForReviewV2}; maps conflict to BadRequest for legacy clients.
|
||||
*/
|
||||
async lockRequestV2(
|
||||
@@ -1649,7 +1650,7 @@ export class ExpertBlameService {
|
||||
const lockedAt = request.workflow?.lockedAt;
|
||||
if (lockedAt) {
|
||||
const lockExpiryTime =
|
||||
new Date(lockedAt).getTime() + this.blameV2LockTtlMs;
|
||||
new Date(lockedAt).getTime() + EXPERT_WORKFLOW_LOCK_TTL_MS;
|
||||
if (Date.now() > lockExpiryTime) {
|
||||
throw new ForbiddenException(
|
||||
"Your lock time has expired. Please lock the request again.",
|
||||
@@ -1891,11 +1892,11 @@ export class ExpertBlameService {
|
||||
const lockedAt = request.workflow?.lockedAt;
|
||||
const isLockedByCurrentActor = lockedByActorId === actorId;
|
||||
|
||||
// Check if lock has expired (15 minutes)
|
||||
// Check if lock has expired (30 minutes)
|
||||
let isLockExpired = false;
|
||||
if (lockedAt) {
|
||||
const lockExpiryTime =
|
||||
new Date(lockedAt).getTime() + this.blameV2LockTtlMs;
|
||||
new Date(lockedAt).getTime() + EXPERT_WORKFLOW_LOCK_TTL_MS;
|
||||
isLockExpired = Date.now() > lockExpiryTime;
|
||||
}
|
||||
|
||||
@@ -2057,11 +2058,11 @@ export class ExpertBlameService {
|
||||
const lockedAt = request.workflow?.lockedAt;
|
||||
const isLockedByCurrentActor = lockedByActorId === actorId;
|
||||
|
||||
// Check if lock has expired (15 minutes)
|
||||
// Check if lock has expired (30 minutes)
|
||||
let isLockExpired = false;
|
||||
if (lockedAt) {
|
||||
const lockExpiryTime =
|
||||
new Date(lockedAt).getTime() + this.blameV2LockTtlMs;
|
||||
new Date(lockedAt).getTime() + EXPERT_WORKFLOW_LOCK_TTL_MS;
|
||||
isLockExpired = Date.now() > lockExpiryTime;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user