Skip to content

Commit

Permalink
Closes #2389 Possibility to keep the Owner and OwnerLongName of a tas…
Browse files Browse the repository at this point in the history
…k when cancelClaiming
  • Loading branch information
Jörg Heffner committed Sep 28, 2023
1 parent 6750202 commit a808f62
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@
import pro.taskana.testapi.builder.WorkbasketAccessItemBuilder;
import pro.taskana.testapi.security.WithAccessId;
import pro.taskana.user.api.UserService;
import pro.taskana.user.api.models.User;
import pro.taskana.workbasket.api.WorkbasketPermission;
import pro.taskana.workbasket.api.WorkbasketService;
import pro.taskana.workbasket.api.exceptions.NotAuthorizedOnWorkbasketException;
import pro.taskana.workbasket.api.models.WorkbasketSummary;

@TaskanaIntegrationTest
class ClaimTaskAccTest {
class ClaimTaskAccTest implements TaskanaConfigurationModifier {
@TaskanaInject TaskService taskService;
@TaskanaInject ClassificationService classificationService;
@TaskanaInject WorkbasketService workbasketService;
Expand All @@ -56,6 +57,11 @@ class ClaimTaskAccTest {
WorkbasketSummary wbWithoutReadTasks;
WorkbasketSummary wbWithoutRead;

@Override
public TaskanaConfiguration.Builder modify(TaskanaConfiguration.Builder builder) {
return builder.addAdditionalUserInfo(true);
}

@WithAccessId(user = "businessadmin")
@BeforeAll
void setup() throws Exception {
Expand Down Expand Up @@ -371,6 +377,29 @@ void should_CancelClaimTask_When_TaskIsClaimed() throws Exception {
assertThat(unclaimedTask.getOwnerLongName()).isNull();
}

@WithAccessId(user = "user-1-2")
@Test
void should_KeepOwnerAndOwnerLongName_When_CancelClaimWithKeepOwner() throws Exception {
Task claimedTask =
TaskBuilder.newTask()
.state(TaskState.CLAIMED)
.claimed(Instant.now())
.owner("user-1-2")
.classificationSummary(defaultClassificationSummary)
.workbasketSummary(defaultWorkbasketSummary)
.primaryObjRef(defaultObjectReference)
.buildAndStore(taskService);

Task unclaimedTask = taskService.cancelClaim(claimedTask.getId(),true);

assertThat(unclaimedTask).isNotNull();
assertThat(unclaimedTask.getState()).isEqualTo(TaskState.READY);
assertThat(unclaimedTask.getClaimed()).isNull();
assertThat(unclaimedTask.isRead()).isTrue();
assertThat(unclaimedTask.getOwner()).isEqualTo("user-1-2");
assertThat(unclaimedTask.getOwnerLongName()).isEqualTo("Long name of user-1-2");
}

@WithAccessId(user = "user-1-2")
@Test
void should_CancelClaimTask_When_TaskIsInReview() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,44 @@ Task cancelClaim(String taskId)
NotAuthorizedOnWorkbasketException,
InvalidTaskStateException;

/**
* Cancel the claim of an existing {@linkplain Task} if it was claimed by the current user before.
*
* @param taskId the {@linkplain Task#getId() id} of the {@linkplain Task} which should be
* unclaimed
* @param keepOwner If set to true,
* will keep the {@linkplain Task#getOwner()} and {@linkplain Task#getOwnerLongName()}
* @return the unclaimed {@linkplain Task}
* @throws TaskNotFoundException if the {@linkplain Task} with taskId was not found
* @throws InvalidTaskStateException if the {@linkplain Task} is already in one of the {@linkplain
* TaskState#END_STATES}
* @throws InvalidOwnerException if the {@linkplain Task} is claimed by another user
* @throws NotAuthorizedOnWorkbasketException if the current user has no {@linkplain
* WorkbasketPermission#READ} for the {@linkplain Workbasket} the {@linkplain Task} is in
*/
Task cancelClaim(String taskId, boolean keepOwner)
throws TaskNotFoundException,
InvalidOwnerException,
NotAuthorizedOnWorkbasketException,
InvalidTaskStateException;

/**
* Cancel the claim of an existing {@linkplain Task} even if it was claimed by another user.
*
* @param taskId the {@linkplain Task#getId() id} of the {@linkplain Task} which should be
* unclaimed
* @param keepOwner If set to true,
* will keep the {@linkplain Task#getOwner()} and {@linkplain Task#getOwnerLongName()}
* @return the unclaimed {@linkplain Task}
* @throws TaskNotFoundException if the {@linkplain Task} with taskId was not found
* @throws InvalidTaskStateException if the {@linkplain Task} is already in one of the {@linkplain
* TaskState#END_STATES}
* @throws NotAuthorizedOnWorkbasketException if the current user has no {@linkplain
* WorkbasketPermission#READ} for the {@linkplain Workbasket} the {@linkplain Task} is in
*/
Task forceCancelClaim(String taskId, boolean keepOwner)
throws TaskNotFoundException, NotAuthorizedOnWorkbasketException, InvalidTaskStateException;

/**
* Cancel the claim of an existing {@linkplain Task} even if it was claimed by another user.
*
Expand Down
Loading

0 comments on commit a808f62

Please sign in to comment.