Closes #2296 - add ownerLongName during update

This commit is contained in:
Elena Mokeeva 2023-06-16 11:15:09 +02:00 committed by Elena Mokeeva
parent 3ee90248b5
commit e0ae4b9907
2 changed files with 105 additions and 103 deletions

View File

@ -51,8 +51,10 @@ import pro.taskana.testapi.TaskanaInject;
import pro.taskana.testapi.TaskanaIntegrationTest; import pro.taskana.testapi.TaskanaIntegrationTest;
import pro.taskana.testapi.builder.ObjectReferenceBuilder; import pro.taskana.testapi.builder.ObjectReferenceBuilder;
import pro.taskana.testapi.builder.TaskBuilder; import pro.taskana.testapi.builder.TaskBuilder;
import pro.taskana.testapi.builder.UserBuilder;
import pro.taskana.testapi.builder.WorkbasketAccessItemBuilder; import pro.taskana.testapi.builder.WorkbasketAccessItemBuilder;
import pro.taskana.testapi.security.WithAccessId; import pro.taskana.testapi.security.WithAccessId;
import pro.taskana.user.api.UserService;
import pro.taskana.workbasket.api.WorkbasketPermission; import pro.taskana.workbasket.api.WorkbasketPermission;
import pro.taskana.workbasket.api.WorkbasketService; import pro.taskana.workbasket.api.WorkbasketService;
import pro.taskana.workbasket.api.exceptions.NotAuthorizedOnWorkbasketException; import pro.taskana.workbasket.api.exceptions.NotAuthorizedOnWorkbasketException;
@ -61,6 +63,8 @@ import pro.taskana.workbasket.api.models.WorkbasketSummary;
@TaskanaIntegrationTest @TaskanaIntegrationTest
public class UpdateTaskAccTest { public class UpdateTaskAccTest {
@TaskanaInject TaskService taskService; @TaskanaInject TaskService taskService;
@TaskanaInject UserService userService;
@TaskanaInject ClassificationService classificationService; @TaskanaInject ClassificationService classificationService;
@TaskanaInject WorkbasketService workbasketService; @TaskanaInject WorkbasketService workbasketService;
@ -569,12 +573,30 @@ public class UpdateTaskAccTest {
@Nested @Nested
@TestInstance(Lifecycle.PER_CLASS) @TestInstance(Lifecycle.PER_CLASS)
class WithEnforceServiceLevelDisabled implements TaskanaConfigurationModifier { class WithEnforceServiceLevelDisabledAndAdditionalUserInfoEnabled
implements TaskanaConfigurationModifier {
@TaskanaInject TaskService taskService; @TaskanaInject TaskService taskService;
@Override @Override
public TaskanaConfiguration.Builder modify(TaskanaConfiguration.Builder builder) { public TaskanaConfiguration.Builder modify(TaskanaConfiguration.Builder builder) {
return builder.enforceServiceLevel(false); return builder.addAdditionalUserInfo(true).enforceServiceLevel(false);
}
@WithAccessId(user = "businessadmin")
@BeforeAll
void setup() throws Exception {
UserBuilder.newUser()
.id("user-1-2")
.firstName("Max")
.lastName("Mustermann")
.longName("Max Mustermann")
.buildAndStore(userService, "businessadmin");
UserBuilder.newUser()
.id("user-1-1")
.firstName("Ella")
.lastName("Mustermann")
.longName("Ella Mustermann")
.buildAndStore(userService, "businessadmin");
} }
@WithAccessId(user = "user-1-2") @WithAccessId(user = "user-1-2")
@ -596,5 +618,42 @@ public class UpdateTaskAccTest {
assertThat(updatedTask.getPlanned()).isEqualTo(planned); assertThat(updatedTask.getPlanned()).isEqualTo(planned);
assertThat(updatedTask.getDue()).isEqualTo(due); assertThat(updatedTask.getDue()).isEqualTo(due);
} }
@WithAccessId(user = "user-1-2")
@Test
void should_SetOwnerLongName_When_NotChangingOwner() throws Exception {
Task task =
TaskBuilder.newTask()
.owner("user-1-2")
.classificationSummary(defaultClassificationSummary)
.workbasketSummary(defaultWorkbasketSummary)
.primaryObjRef(defaultObjectReference)
.buildAndStore(taskService);
task.setNote("New Note");
Task updatedTask = taskService.updateTask(task);
assertThat(updatedTask.getNote()).isEqualTo("New Note");
assertThat(updatedTask.getOwner()).isEqualTo("user-1-2");
assertThat(updatedTask.getOwnerLongName()).isEqualTo("Max Mustermann");
}
@WithAccessId(user = "user-1-2")
@Test
void should_SetOwnerLongName_When_ChangingOwner() throws Exception {
Task task =
TaskBuilder.newTask()
.owner("user-1-2")
.classificationSummary(defaultClassificationSummary)
.workbasketSummary(defaultWorkbasketSummary)
.primaryObjRef(defaultObjectReference)
.buildAndStore(taskService);
task.setOwner("user-1-1");
Task updatedTask = taskService.updateTask(task);
assertThat(updatedTask.getOwner()).isEqualTo("user-1-1");
assertThat(updatedTask.getOwnerLongName()).isEqualTo("Ella Mustermann");
}
} }
} }

View File

@ -157,27 +157,21 @@ public class TaskServiceImpl implements TaskService {
@Override @Override
public Task claim(String taskId) public Task claim(String taskId)
throws TaskNotFoundException, throws TaskNotFoundException, InvalidOwnerException, NotAuthorizedOnWorkbasketException,
InvalidOwnerException,
NotAuthorizedOnWorkbasketException,
InvalidTaskStateException { InvalidTaskStateException {
return claim(taskId, false); return claim(taskId, false);
} }
@Override @Override
public Task forceClaim(String taskId) public Task forceClaim(String taskId)
throws TaskNotFoundException, throws TaskNotFoundException, InvalidOwnerException, NotAuthorizedOnWorkbasketException,
InvalidOwnerException,
NotAuthorizedOnWorkbasketException,
InvalidTaskStateException { InvalidTaskStateException {
return claim(taskId, true); return claim(taskId, true);
} }
@Override @Override
public Task cancelClaim(String taskId) public Task cancelClaim(String taskId)
throws TaskNotFoundException, throws TaskNotFoundException, InvalidOwnerException, NotAuthorizedOnWorkbasketException,
InvalidOwnerException,
NotAuthorizedOnWorkbasketException,
InvalidTaskStateException { InvalidTaskStateException {
return this.cancelClaim(taskId, false); return this.cancelClaim(taskId, false);
} }
@ -194,67 +188,51 @@ public class TaskServiceImpl implements TaskService {
@Override @Override
public Task requestReview(String taskId) public Task requestReview(String taskId)
throws InvalidTaskStateException, throws InvalidTaskStateException, TaskNotFoundException, InvalidOwnerException,
TaskNotFoundException,
InvalidOwnerException,
NotAuthorizedOnWorkbasketException { NotAuthorizedOnWorkbasketException {
return requestReview(taskId, false); return requestReview(taskId, false);
} }
@Override @Override
public Task forceRequestReview(String taskId) public Task forceRequestReview(String taskId)
throws InvalidTaskStateException, throws InvalidTaskStateException, TaskNotFoundException, InvalidOwnerException,
TaskNotFoundException,
InvalidOwnerException,
NotAuthorizedOnWorkbasketException { NotAuthorizedOnWorkbasketException {
return requestReview(taskId, true); return requestReview(taskId, true);
} }
@Override @Override
public Task requestChanges(String taskId) public Task requestChanges(String taskId)
throws InvalidTaskStateException, throws InvalidTaskStateException, TaskNotFoundException, InvalidOwnerException,
TaskNotFoundException,
InvalidOwnerException,
NotAuthorizedOnWorkbasketException { NotAuthorizedOnWorkbasketException {
return requestChanges(taskId, false); return requestChanges(taskId, false);
} }
@Override @Override
public Task forceRequestChanges(String taskId) public Task forceRequestChanges(String taskId)
throws InvalidTaskStateException, throws InvalidTaskStateException, TaskNotFoundException, InvalidOwnerException,
TaskNotFoundException,
InvalidOwnerException,
NotAuthorizedOnWorkbasketException { NotAuthorizedOnWorkbasketException {
return requestChanges(taskId, true); return requestChanges(taskId, true);
} }
@Override @Override
public Task completeTask(String taskId) public Task completeTask(String taskId)
throws TaskNotFoundException, throws TaskNotFoundException, InvalidOwnerException, NotAuthorizedOnWorkbasketException,
InvalidOwnerException,
NotAuthorizedOnWorkbasketException,
InvalidTaskStateException { InvalidTaskStateException {
return completeTask(taskId, false); return completeTask(taskId, false);
} }
@Override @Override
public Task forceCompleteTask(String taskId) public Task forceCompleteTask(String taskId)
throws TaskNotFoundException, throws TaskNotFoundException, InvalidOwnerException, NotAuthorizedOnWorkbasketException,
InvalidOwnerException,
NotAuthorizedOnWorkbasketException,
InvalidTaskStateException { InvalidTaskStateException {
return completeTask(taskId, true); return completeTask(taskId, true);
} }
@Override @Override
public Task createTask(Task taskToCreate) public Task createTask(Task taskToCreate)
throws WorkbasketNotFoundException, throws WorkbasketNotFoundException, ClassificationNotFoundException,
ClassificationNotFoundException, TaskAlreadyExistException, InvalidArgumentException, AttachmentPersistenceException,
TaskAlreadyExistException, ObjectReferencePersistenceException, NotAuthorizedOnWorkbasketException {
InvalidArgumentException,
AttachmentPersistenceException,
ObjectReferencePersistenceException,
NotAuthorizedOnWorkbasketException {
if (createTaskPreprocessorManager.isEnabled()) { if (createTaskPreprocessorManager.isEnabled()) {
taskToCreate = createTaskPreprocessorManager.processTaskBeforeCreation(taskToCreate); taskToCreate = createTaskPreprocessorManager.processTaskBeforeCreation(taskToCreate);
@ -434,18 +412,14 @@ public class TaskServiceImpl implements TaskService {
@Override @Override
public Task transfer(String taskId, String destinationWorkbasketId, boolean setTransferFlag) public Task transfer(String taskId, String destinationWorkbasketId, boolean setTransferFlag)
throws TaskNotFoundException, throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedOnWorkbasketException,
WorkbasketNotFoundException,
NotAuthorizedOnWorkbasketException,
InvalidTaskStateException { InvalidTaskStateException {
return taskTransferrer.transfer(taskId, destinationWorkbasketId, setTransferFlag); return taskTransferrer.transfer(taskId, destinationWorkbasketId, setTransferFlag);
} }
@Override @Override
public Task transfer(String taskId, String workbasketKey, String domain, boolean setTransferFlag) public Task transfer(String taskId, String workbasketKey, String domain, boolean setTransferFlag)
throws TaskNotFoundException, throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedOnWorkbasketException,
WorkbasketNotFoundException,
NotAuthorizedOnWorkbasketException,
InvalidTaskStateException { InvalidTaskStateException {
return taskTransferrer.transfer(taskId, workbasketKey, domain, setTransferFlag); return taskTransferrer.transfer(taskId, workbasketKey, domain, setTransferFlag);
} }
@ -527,13 +501,9 @@ public class TaskServiceImpl implements TaskService {
@Override @Override
public Task updateTask(Task task) public Task updateTask(Task task)
throws InvalidArgumentException, throws InvalidArgumentException, TaskNotFoundException, ConcurrencyException,
TaskNotFoundException, AttachmentPersistenceException, ObjectReferencePersistenceException,
ConcurrencyException, ClassificationNotFoundException, NotAuthorizedOnWorkbasketException,
AttachmentPersistenceException,
ObjectReferencePersistenceException,
ClassificationNotFoundException,
NotAuthorizedOnWorkbasketException,
InvalidTaskStateException { InvalidTaskStateException {
String userId = taskanaEngine.getEngine().getCurrentUserContext().getUserid(); String userId = taskanaEngine.getEngine().getCurrentUserContext().getUserid();
TaskImpl newTaskImpl = (TaskImpl) task; TaskImpl newTaskImpl = (TaskImpl) task;
@ -582,8 +552,7 @@ public class TaskServiceImpl implements TaskService {
@Override @Override
public BulkOperationResults<String, TaskanaException> transferTasks( public BulkOperationResults<String, TaskanaException> transferTasks(
String destinationWorkbasketId, List<String> taskIds, boolean setTransferFlag) String destinationWorkbasketId, List<String> taskIds, boolean setTransferFlag)
throws InvalidArgumentException, throws InvalidArgumentException, WorkbasketNotFoundException,
WorkbasketNotFoundException,
NotAuthorizedOnWorkbasketException { NotAuthorizedOnWorkbasketException {
return taskTransferrer.transfer(taskIds, destinationWorkbasketId, setTransferFlag); return taskTransferrer.transfer(taskIds, destinationWorkbasketId, setTransferFlag);
} }
@ -594,8 +563,7 @@ public class TaskServiceImpl implements TaskService {
String destinationWorkbasketDomain, String destinationWorkbasketDomain,
List<String> taskIds, List<String> taskIds,
boolean setTransferFlag) boolean setTransferFlag)
throws InvalidArgumentException, throws InvalidArgumentException, WorkbasketNotFoundException,
WorkbasketNotFoundException,
NotAuthorizedOnWorkbasketException { NotAuthorizedOnWorkbasketException {
return taskTransferrer.transfer( return taskTransferrer.transfer(
taskIds, destinationWorkbasketKey, destinationWorkbasketDomain, setTransferFlag); taskIds, destinationWorkbasketKey, destinationWorkbasketDomain, setTransferFlag);
@ -603,21 +571,15 @@ public class TaskServiceImpl implements TaskService {
@Override @Override
public void deleteTask(String taskId) public void deleteTask(String taskId)
throws TaskNotFoundException, throws TaskNotFoundException, NotAuthorizedException, NotAuthorizedOnWorkbasketException,
NotAuthorizedException, InvalidTaskStateException, InvalidCallbackStateException {
NotAuthorizedOnWorkbasketException,
InvalidTaskStateException,
InvalidCallbackStateException {
deleteTask(taskId, false); deleteTask(taskId, false);
} }
@Override @Override
public void forceDeleteTask(String taskId) public void forceDeleteTask(String taskId)
throws TaskNotFoundException, throws TaskNotFoundException, NotAuthorizedException, NotAuthorizedOnWorkbasketException,
NotAuthorizedException, InvalidTaskStateException, InvalidCallbackStateException {
NotAuthorizedOnWorkbasketException,
InvalidTaskStateException,
InvalidCallbackStateException {
deleteTask(taskId, true); deleteTask(taskId, true);
} }
@ -763,30 +725,22 @@ public class TaskServiceImpl implements TaskService {
@Override @Override
public TaskComment updateTaskComment(TaskComment taskComment) public TaskComment updateTaskComment(TaskComment taskComment)
throws ConcurrencyException, throws ConcurrencyException, TaskCommentNotFoundException, TaskNotFoundException,
TaskCommentNotFoundException, InvalidArgumentException, NotAuthorizedOnTaskCommentException,
TaskNotFoundException,
InvalidArgumentException,
NotAuthorizedOnTaskCommentException,
NotAuthorizedOnWorkbasketException { NotAuthorizedOnWorkbasketException {
return taskCommentService.updateTaskComment(taskComment); return taskCommentService.updateTaskComment(taskComment);
} }
@Override @Override
public void deleteTaskComment(String taskCommentId) public void deleteTaskComment(String taskCommentId)
throws TaskCommentNotFoundException, throws TaskCommentNotFoundException, TaskNotFoundException, InvalidArgumentException,
TaskNotFoundException, NotAuthorizedOnTaskCommentException, NotAuthorizedOnWorkbasketException {
InvalidArgumentException,
NotAuthorizedOnTaskCommentException,
NotAuthorizedOnWorkbasketException {
taskCommentService.deleteTaskComment(taskCommentId); taskCommentService.deleteTaskComment(taskCommentId);
} }
@Override @Override
public TaskComment getTaskComment(String taskCommentid) public TaskComment getTaskComment(String taskCommentid)
throws TaskCommentNotFoundException, throws TaskCommentNotFoundException, TaskNotFoundException, InvalidArgumentException,
TaskNotFoundException,
InvalidArgumentException,
NotAuthorizedOnWorkbasketException { NotAuthorizedOnWorkbasketException {
return taskCommentService.getTaskComment(taskCommentid); return taskCommentService.getTaskComment(taskCommentid);
} }
@ -911,9 +865,7 @@ public class TaskServiceImpl implements TaskService {
@Override @Override
public Task terminateTask(String taskId) public Task terminateTask(String taskId)
throws TaskNotFoundException, throws TaskNotFoundException, NotAuthorizedException, NotAuthorizedOnWorkbasketException,
NotAuthorizedException,
NotAuthorizedOnWorkbasketException,
InvalidTaskStateException { InvalidTaskStateException {
taskanaEngine.getEngine().checkRoleMembership(TaskanaRole.ADMIN, TaskanaRole.TASK_ADMIN); taskanaEngine.getEngine().checkRoleMembership(TaskanaRole.ADMIN, TaskanaRole.TASK_ADMIN);
@ -1257,9 +1209,7 @@ public class TaskServiceImpl implements TaskService {
} }
private Task claim(String taskId, boolean forceClaim) private Task claim(String taskId, boolean forceClaim)
throws TaskNotFoundException, throws TaskNotFoundException, InvalidOwnerException, NotAuthorizedOnWorkbasketException,
InvalidOwnerException,
NotAuthorizedOnWorkbasketException,
InvalidTaskStateException { InvalidTaskStateException {
TaskImpl task; TaskImpl task;
try { try {
@ -1303,9 +1253,7 @@ public class TaskServiceImpl implements TaskService {
} }
private Task requestReview(String taskId, boolean force) private Task requestReview(String taskId, boolean force)
throws TaskNotFoundException, throws TaskNotFoundException, InvalidTaskStateException, InvalidOwnerException,
InvalidTaskStateException,
InvalidOwnerException,
NotAuthorizedOnWorkbasketException { NotAuthorizedOnWorkbasketException {
String userId = taskanaEngine.getEngine().getCurrentUserContext().getUserid(); String userId = taskanaEngine.getEngine().getCurrentUserContext().getUserid();
TaskImpl task; TaskImpl task;
@ -1356,9 +1304,7 @@ public class TaskServiceImpl implements TaskService {
} }
private Task requestChanges(String taskId, boolean force) private Task requestChanges(String taskId, boolean force)
throws InvalidTaskStateException, throws InvalidTaskStateException, TaskNotFoundException, InvalidOwnerException,
TaskNotFoundException,
InvalidOwnerException,
NotAuthorizedOnWorkbasketException { NotAuthorizedOnWorkbasketException {
String userId = taskanaEngine.getEngine().getCurrentUserContext().getUserid(); String userId = taskanaEngine.getEngine().getCurrentUserContext().getUserid();
TaskImpl task; TaskImpl task;
@ -1487,9 +1433,7 @@ public class TaskServiceImpl implements TaskService {
} }
private Task cancelClaim(String taskId, boolean forceUnclaim) private Task cancelClaim(String taskId, boolean forceUnclaim)
throws TaskNotFoundException, throws TaskNotFoundException, InvalidOwnerException, NotAuthorizedOnWorkbasketException,
InvalidOwnerException,
NotAuthorizedOnWorkbasketException,
InvalidTaskStateException { InvalidTaskStateException {
String userId = taskanaEngine.getEngine().getCurrentUserContext().getUserid(); String userId = taskanaEngine.getEngine().getCurrentUserContext().getUserid();
TaskImpl task; TaskImpl task;
@ -1533,9 +1477,7 @@ public class TaskServiceImpl implements TaskService {
} }
private Task completeTask(String taskId, boolean isForced) private Task completeTask(String taskId, boolean isForced)
throws TaskNotFoundException, throws TaskNotFoundException, InvalidOwnerException, NotAuthorizedOnWorkbasketException,
InvalidOwnerException,
NotAuthorizedOnWorkbasketException,
InvalidTaskStateException { InvalidTaskStateException {
String userId = taskanaEngine.getEngine().getCurrentUserContext().getUserid(); String userId = taskanaEngine.getEngine().getCurrentUserContext().getUserid();
TaskImpl task; TaskImpl task;
@ -1578,11 +1520,8 @@ public class TaskServiceImpl implements TaskService {
} }
private void deleteTask(String taskId, boolean forceDelete) private void deleteTask(String taskId, boolean forceDelete)
throws TaskNotFoundException, throws TaskNotFoundException, NotAuthorizedException, NotAuthorizedOnWorkbasketException,
NotAuthorizedException, InvalidTaskStateException, InvalidCallbackStateException {
NotAuthorizedOnWorkbasketException,
InvalidTaskStateException,
InvalidCallbackStateException {
taskanaEngine.getEngine().checkRoleMembership(TaskanaRole.ADMIN); taskanaEngine.getEngine().checkRoleMembership(TaskanaRole.ADMIN);
TaskImpl task; TaskImpl task;
try { try {
@ -1736,10 +1675,8 @@ public class TaskServiceImpl implements TaskService {
} }
private void standardSettingsOnTaskCreation(TaskImpl task, Classification classification) private void standardSettingsOnTaskCreation(TaskImpl task, Classification classification)
throws InvalidArgumentException, throws InvalidArgumentException, ClassificationNotFoundException,
ClassificationNotFoundException, AttachmentPersistenceException, ObjectReferencePersistenceException {
AttachmentPersistenceException,
ObjectReferencePersistenceException {
final Instant now = Instant.now(); final Instant now = Instant.now();
task.setId(IdGenerator.generateWithPrefix(IdGenerator.ID_PREFIX_TASK)); task.setId(IdGenerator.generateWithPrefix(IdGenerator.ID_PREFIX_TASK));
if (task.getExternalId() == null) { if (task.getExternalId() == null) {
@ -2110,6 +2047,12 @@ public class TaskServiceImpl implements TaskService {
throw new InvalidTaskStateException( throw new InvalidTaskStateException(
oldTaskImpl.getId(), oldTaskImpl.getState(), TaskState.READY, TaskState.READY_FOR_REVIEW); oldTaskImpl.getId(), oldTaskImpl.getState(), TaskState.READY, TaskState.READY_FOR_REVIEW);
} }
if (isOwnerChanged && taskanaEngine.getEngine().getConfiguration().isAddAdditionalUserInfo()) {
User user = userMapper.findById(newTaskImpl.getOwner());
if (user != null) {
newTaskImpl.setOwnerLongName(user.getLongName());
}
}
} }
private void updateClassificationSummary(TaskImpl newTaskImpl, TaskImpl oldTaskImpl) private void updateClassificationSummary(TaskImpl newTaskImpl, TaskImpl oldTaskImpl)