Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #2269 - Implement READTASKS Permission #2285

Merged
merged 1 commit into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ void setup() throws Exception {
.accessId("businessadmin")
.permission(WorkbasketPermission.OPEN)
.permission(WorkbasketPermission.READ)
.permission(WorkbasketPermission.READTASKS)
.permission(WorkbasketPermission.APPEND)
.buildAndStore(workbasketService, "admin");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ private String createTaskWithExistingClassification(ClassificationSummary classi
.accessId(currentUserContext.getUserid())
.permission(WorkbasketPermission.OPEN)
.permission(WorkbasketPermission.READ)
.permission(WorkbasketPermission.READTASKS)
.permission(WorkbasketPermission.APPEND)
.buildAndStore(workbasketService, "businessadmin");

Expand All @@ -156,6 +157,7 @@ private List<String> createTasksWithExistingClassificationInAttachment(
.accessId(currentUserContext.getUserid())
.permission(WorkbasketPermission.OPEN)
.permission(WorkbasketPermission.READ)
.permission(WorkbasketPermission.READTASKS)
.permission(WorkbasketPermission.APPEND)
.buildAndStore(workbasketService, "businessadmin");
ClassificationSummary classificationSummaryWithSpecifiedServiceLevel =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void setUp(ClassificationService classificationService, WorkbasketService workba
.workbasketId(workbasketSummary.getId())
.accessId("whatever")
.permission(WorkbasketPermission.READ)
.permission(WorkbasketPermission.READTASKS)
.buildAndStore(workbasketService);

TaskBuilder taskBuilder =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ void setup() throws Exception {
.accessId("user-1-1")
.permission(WorkbasketPermission.OPEN)
.permission(WorkbasketPermission.READ)
.permission(WorkbasketPermission.READTASKS)
.permission(WorkbasketPermission.APPEND)
.buildAndStore(workbasketService);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ void setup() throws Exception {
.accessId("user-1-2")
.permission(WorkbasketPermission.OPEN)
.permission(WorkbasketPermission.READ)
.permission(WorkbasketPermission.READTASKS)
.permission(WorkbasketPermission.APPEND)
.buildAndStore(workbasketService);

Expand Down Expand Up @@ -257,7 +258,8 @@ void should_ThrowNotAuthorizedException_When_UserHasNoReadPermissionAndTaskIsRea
catchThrowableOfType(call, NotAuthorizedOnWorkbasketException.class);
assertThat(e.getCurrentUserId()).isEqualTo("user-taskrouter");
assertThat(e.getWorkbasketId()).isEqualTo(defaultWorkbasketSummary.getId());
assertThat(e.getRequiredPermissions()).containsExactlyInAnyOrder(WorkbasketPermission.READ);
assertThat(e.getRequiredPermissions())
.containsExactlyInAnyOrder(WorkbasketPermission.READ, WorkbasketPermission.READTASKS);

;
}
Expand All @@ -280,7 +282,8 @@ void should_ThrowNotAuthorizedException_When_UserHasNoReadPermissionAndTaskIsRea
catchThrowableOfType(call, NotAuthorizedOnWorkbasketException.class);
assertThat(e.getCurrentUserId()).isEqualTo("user-taskrouter");
assertThat(e.getWorkbasketId()).isEqualTo(defaultWorkbasketSummary.getId());
assertThat(e.getRequiredPermissions()).containsExactlyInAnyOrder(WorkbasketPermission.READ);
assertThat(e.getRequiredPermissions())
.containsExactlyInAnyOrder(WorkbasketPermission.READ, WorkbasketPermission.READTASKS);
}

@WithAccessId(user = "user-1-2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void setup() throws Exception {
.accessId("user-1-2")
.permission(WorkbasketPermission.OPEN)
.permission(WorkbasketPermission.READ)
.permission(WorkbasketPermission.READTASKS)
.permission(WorkbasketPermission.APPEND)
.buildAndStore(workbasketService);

Expand Down Expand Up @@ -117,7 +118,8 @@ void should_ThrowException_When_SetOwnerViaUpdateTaskIsNotAuthorizedOnWorkbasket
catchThrowableOfType(call2, NotAuthorizedOnWorkbasketException.class);
assertThat(e2.getWorkbasketId()).isEqualTo(defaultWorkbasketSummary.getId());
assertThat(e2.getCurrentUserId()).isEqualTo("user-1-1");
assertThat(e2.getRequiredPermissions()).containsExactly(WorkbasketPermission.READ);
assertThat(e2.getRequiredPermissions())
.containsExactly(WorkbasketPermission.READ, WorkbasketPermission.READTASKS);
}

@WithAccessId(user = "user-1-2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ void setup() throws Exception {
.accessId("user-1-2")
.permission(WorkbasketPermission.OPEN)
.permission(WorkbasketPermission.READ)
.permission(WorkbasketPermission.READTASKS)
.permission(WorkbasketPermission.APPEND)
.buildAndStore(workbasketService);

Expand Down Expand Up @@ -130,7 +131,8 @@ void should_ThrowException_When_UserNotAuthorized() throws Exception {

NotAuthorizedOnWorkbasketException e =
catchThrowableOfType(call, NotAuthorizedOnWorkbasketException.class);
assertThat(e.getRequiredPermissions()).containsExactly(WorkbasketPermission.READ);
assertThat(e.getRequiredPermissions())
.containsExactly(WorkbasketPermission.READ, WorkbasketPermission.READTASKS);
assertThat(e.getCurrentUserId()).isEqualTo("user-taskrouter");
assertThat(e.getWorkbasketId()).isEqualTo(defaultWorkbasketSummary.getId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ void setup(ClassificationService classificationService, WorkbasketService workba
.workbasketId(defaultWorkbasketSummary.getId())
.accessId("user-1-1")
.permission(WorkbasketPermission.READ)
.permission(WorkbasketPermission.READTASKS)
.permission(WorkbasketPermission.APPEND)
.buildAndStore(workbasketService);

Expand Down Expand Up @@ -217,7 +218,8 @@ void should_ThrowException_When_UserIsNotAuthorizedOnTask() throws Exception {
assertThat(e.getCurrentUserId()).isEqualTo(currentUserContext.getUserid());
WorkbasketSummary workbasket = claimedTask.getWorkbasketSummary();
assertThat(e.getWorkbasketId()).isEqualTo(workbasket.getId());
assertThat(e.getRequiredPermissions()).containsExactly(WorkbasketPermission.READ);
assertThat(e.getRequiredPermissions())
.containsExactly(WorkbasketPermission.READ, WorkbasketPermission.READTASKS);
}

@WithAccessId(user = "user-1-1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ void setup(ClassificationService classificationService, WorkbasketService workba
.workbasketId(defaultWorkbasketSummary.getId())
.accessId("user-1-1")
.permission(WorkbasketPermission.READ)
.permission(WorkbasketPermission.READTASKS)
.permission(WorkbasketPermission.APPEND)
.buildAndStore(workbasketService);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ void setup() throws Exception {
.accessId("user-1-2")
.permission(WorkbasketPermission.OPEN)
.permission(WorkbasketPermission.READ)
.permission(WorkbasketPermission.READTASKS)
.permission(WorkbasketPermission.APPEND)
.buildAndStore(workbasketService);
defaultObjectReference = defaultTestObjectReference().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void setup() throws Exception {
.accessId("user-1-1")
.permission(WorkbasketPermission.OPEN)
.permission(WorkbasketPermission.READ)
.permission(WorkbasketPermission.READTASKS)
.permission(WorkbasketPermission.APPEND)
.buildAndStore(workbasketService);
defaultObjectReference = defaultTestObjectReference().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void setup() throws Exception {
.accessId("user-1-2")
.permission(WorkbasketPermission.OPEN)
.permission(WorkbasketPermission.READ)
.permission(WorkbasketPermission.READTASKS)
.permission(WorkbasketPermission.APPEND)
.buildAndStore(workbasketService);
task1 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void setup() throws Exception {
.accessId("user-1-1")
.permission(WorkbasketPermission.OPEN)
.permission(WorkbasketPermission.READ)
.permission(WorkbasketPermission.READTASKS)
.permission(WorkbasketPermission.APPEND)
.buildAndStore(workbasketService);
defaultObjectReference = defaultTestObjectReference().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ class GetTaskAccTest {

ClassificationSummary defaultClassificationSummary;
WorkbasketSummary defaultWorkbasketSummary;
WorkbasketSummary wbWithoutReadTasksPerm;
WorkbasketSummary wbWithoutReadPerm;
ObjectReference defaultObjectReference;
Task task;
Task task2;
Task task3;
Map<String, String> callbackInfo;

@WithAccessId(user = "admin")
Expand All @@ -62,6 +66,8 @@ void setup() throws Exception {
defaultClassificationSummary =
defaultTestClassification().buildAndStoreAsSummary(classificationService);
defaultWorkbasketSummary = defaultTestWorkbasket().buildAndStoreAsSummary(workbasketService);
wbWithoutReadTasksPerm = defaultTestWorkbasket().buildAndStoreAsSummary(workbasketService);
wbWithoutReadPerm = defaultTestWorkbasket().buildAndStoreAsSummary(workbasketService);
defaultObjectReference = defaultTestObjectReference().build();
callbackInfo = createSimpleCustomPropertyMap(3);

Expand All @@ -70,6 +76,21 @@ void setup() throws Exception {
.accessId("user-1-1")
.permission(WorkbasketPermission.OPEN)
.permission(WorkbasketPermission.READ)
.permission(WorkbasketPermission.READTASKS)
.permission(WorkbasketPermission.APPEND)
.buildAndStore(workbasketService);
WorkbasketAccessItemBuilder.newWorkbasketAccessItem()
.workbasketId(wbWithoutReadTasksPerm.getId())
.accessId("user-1-1")
.permission(WorkbasketPermission.OPEN)
.permission(WorkbasketPermission.READ)
.permission(WorkbasketPermission.APPEND)
.buildAndStore(workbasketService);
WorkbasketAccessItemBuilder.newWorkbasketAccessItem()
.workbasketId(wbWithoutReadPerm.getId())
.accessId("user-1-1")
.permission(WorkbasketPermission.OPEN)
.permission(WorkbasketPermission.READTASKS)
.permission(WorkbasketPermission.APPEND)
.buildAndStore(workbasketService);

Expand Down Expand Up @@ -123,6 +144,20 @@ void setup() throws Exception {
.workbasketSummary(defaultWorkbasketSummary)
.primaryObjRef(defaultObjectReference)
.buildAndStore(taskService);

task2 =
TaskBuilder.newTask()
.workbasketSummary(wbWithoutReadTasksPerm)
.classificationSummary(defaultClassificationSummary)
.primaryObjRef(defaultObjectReference)
.buildAndStore(taskService);

task3 =
TaskBuilder.newTask()
.workbasketSummary(wbWithoutReadPerm)
.classificationSummary(defaultClassificationSummary)
.primaryObjRef(defaultObjectReference)
.buildAndStore(taskService);
}

@WithAccessId(user = "user-1-1")
Expand Down Expand Up @@ -182,6 +217,34 @@ void should_ReturnTask_When_RequestingTaskByTaskId() throws Exception {
assertThat(readTask).hasNoNullFieldsOrPropertiesExcept("ownerLongName", "completed");
}

@WithAccessId(user = "user-1-1")
@Test
void should_ThrowException_When_NoReadTasksPerm() {
ThrowingCallable call = () -> taskService.getTask(task2.getId());

NotAuthorizedOnWorkbasketException e =
catchThrowableOfType(call, NotAuthorizedOnWorkbasketException.class);

assertThat(e.getRequiredPermissions())
.containsExactlyInAnyOrder(WorkbasketPermission.READ, WorkbasketPermission.READTASKS);
assertThat(e.getCurrentUserId()).isEqualTo("user-1-1");
assertThat(e.getWorkbasketId()).isEqualTo(wbWithoutReadTasksPerm.getId());
}

@WithAccessId(user = "user-1-1")
@Test
void should_ThrowException_When_UserHasReadTasksButNoReadPerm() {
ThrowingCallable call = () -> taskService.getTask(task3.getId());

NotAuthorizedOnWorkbasketException e =
catchThrowableOfType(call, NotAuthorizedOnWorkbasketException.class);

assertThat(e.getRequiredPermissions())
.containsExactlyInAnyOrder(WorkbasketPermission.READ, WorkbasketPermission.READTASKS);
assertThat(e.getCurrentUserId()).isEqualTo("user-1-1");
assertThat(e.getWorkbasketId()).isEqualTo(wbWithoutReadPerm.getId());
}

@WithAccessId(user = "user-1-1")
@Test
void should_ThrowException_When_RequestedTaskByIdIsNotExisting() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ void setup() throws Exception {
.accessId("user-1-1")
.permission(WorkbasketPermission.OPEN)
.permission(WorkbasketPermission.READ)
.permission(WorkbasketPermission.READTASKS)
.permission(WorkbasketPermission.APPEND)
.buildAndStore(workbasketService);
defaultObjectReference = defaultTestObjectReference().build();
Expand Down
Loading