diff --git a/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/bean/TaskActionBean.java b/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/bean/TaskActionBean.java index 046a892dd46..b48abab025e 100644 --- a/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/bean/TaskActionBean.java +++ b/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/bean/TaskActionBean.java @@ -130,11 +130,34 @@ public boolean canChangePriority(ITask task) { return isNotDone(task) && hasPermission(task, IPermission.TASK_WRITE_ORIGINAL_PRIORITY); } + /** + * Logic to check if user can change task expiry date: + * - Task not null + * - Task state is different from DONE, DESTROYED + * - User has permission TaskWriteExpiryTimestamp + * - The task has expiry handler or has expiry option 'Nobody & delete' + * + * @param task + * @return condition whether the user can change expiry time + */ + public boolean canChangeExpiry(ITask task) { - List taskStates = Arrays.asList(TaskBusinessState.DONE, TaskBusinessState.DESTROYED); - return (hasPermission(task, IPermission.TASK_WRITE_EXPIRY_TIMESTAMP) - || (task != null && StringUtils.isNotBlank(task.getExpiryTaskStartElementPid()))) - && !taskStates.contains(task.getBusinessState()); + List nonChangeableExpiryStates = Arrays.asList(TaskState.DONE, + TaskState.DESTROYED); + + if (task == null || nonChangeableExpiryStates.contains(task.getState())) { + return false; + } + + boolean isAutoDeleteAfterExpiry = StringUtils + .isBlank(task.getExpiryActivatorName()) + && StringUtils.isBlank(task.getExpiryTaskStartElementPid()); + + boolean hasExpiryHandler = StringUtils + .isNotBlank(task.getExpiryTaskStartElementPid()); + + return hasPermission(task, IPermission.TASK_WRITE_EXPIRY_TIMESTAMP) + && (isAutoDeleteAfterExpiry || hasExpiryHandler); } public boolean canChangeDelayTimestamp(ITask task) {