Skip to content

Commit

Permalink
Closes #2269 - Implement READTASKS Permission
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesrdi committed Jun 6, 2023
1 parent 696d2de commit 57e3441
Show file tree
Hide file tree
Showing 31 changed files with 160 additions and 24 deletions.
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 @@ -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
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
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
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
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 @@ -52,8 +52,10 @@ class GetTaskAccTest {

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

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

Expand All @@ -70,6 +73,14 @@ 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);

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

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

@WithAccessId(user = "user-1-1")
Expand Down Expand Up @@ -182,6 +200,20 @@ 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_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
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import pro.taskana.testapi.security.WithAccessId;
import pro.taskana.workbasket.api.WorkbasketPermission;
import pro.taskana.workbasket.api.WorkbasketService;
import pro.taskana.workbasket.api.exceptions.NotAuthorizedToQueryWorkbasketException;
import pro.taskana.workbasket.api.models.WorkbasketSummary;

@TaskanaIntegrationTest
Expand Down Expand Up @@ -93,6 +94,7 @@ private void persistPermission(WorkbasketSummary workbasketSummary) throws Excep
.permission(WorkbasketPermission.OPEN)
.permission(WorkbasketPermission.READ)
.permission(WorkbasketPermission.APPEND)
.permission(WorkbasketPermission.READTASKS)
.buildAndStore(workbasketService, "businessadmin");
}

Expand Down Expand Up @@ -273,15 +275,30 @@ void should_ResolveUnderScore_When_UsingAnyLikeQuery() throws Exception {
class TaskId {

WorkbasketSummary wb;
WorkbasketSummary wbWithoutReadTasksPerm;
TaskSummary taskSummary1;
TaskSummary taskSummary2;
TaskSummary taskSummary3;

@WithAccessId(user = "user-1-1")
@BeforeAll
void setup() throws Exception {
wb = createWorkbasketWithPermission();
wbWithoutReadTasksPerm =
defaultTestWorkbasket().buildAndStoreAsSummary(workbasketService, "businessadmin");

WorkbasketAccessItemBuilder.newWorkbasketAccessItem()
.workbasketId(wbWithoutReadTasksPerm.getId())
.accessId(currentUserContext.getUserid())
.permission(WorkbasketPermission.OPEN)
.permission(WorkbasketPermission.READ)
.permission(WorkbasketPermission.APPEND)
.buildAndStore(workbasketService, "businessadmin");

taskSummary1 = taskInWorkbasket(wb).buildAndStoreAsSummary(taskService);
taskSummary2 = taskInWorkbasket(wb).buildAndStoreAsSummary(taskService);
taskSummary3 =
taskInWorkbasket(wbWithoutReadTasksPerm).buildAndStoreAsSummary(taskService, "admin");
}

@WithAccessId(user = "user-1-1")
Expand Down Expand Up @@ -309,6 +326,13 @@ void should_FilterByTaskId_When_QueryingForIdNotIn() {

assertThat(list).containsExactly(taskSummary2);
}

@WithAccessId(user = "user-1-1")
@Test
void should_ReturnNothing_When_WorkbasketHasOfTaskHasNoReadTasksPerm() {
List<TaskSummary> list = taskService.createTaskQuery().idIn(taskSummary3.getId()).list();
assertThat(list.isEmpty());
}
}

@Nested
Expand Down Expand Up @@ -1458,16 +1482,30 @@ class WorkbasketId {

WorkbasketSummary wb1;
WorkbasketSummary wb2;
WorkbasketSummary wbWithoutReadTasksPerm;
TaskSummary taskSummary1;
TaskSummary taskSummary2;
TaskSummary taskSummary3;

@WithAccessId(user = "user-1-1")
@BeforeAll
void setup() throws Exception {
wb1 = createWorkbasketWithPermission();
wb2 = createWorkbasketWithPermission();
wbWithoutReadTasksPerm =
defaultTestWorkbasket().buildAndStoreAsSummary(workbasketService, "admin");

WorkbasketAccessItemBuilder.newWorkbasketAccessItem()
.workbasketId(wbWithoutReadTasksPerm.getId())
.accessId(currentUserContext.getUserid())
.permission(WorkbasketPermission.OPEN)
.permission(WorkbasketPermission.READ)
.buildAndStore(workbasketService, "businessadmin");

taskSummary1 = taskInWorkbasket(wb1).buildAndStoreAsSummary(taskService);
taskSummary2 = taskInWorkbasket(wb2).buildAndStoreAsSummary(taskService);
taskSummary3 =
taskInWorkbasket(wbWithoutReadTasksPerm).buildAndStoreAsSummary(taskService, "admin");
}

@WithAccessId(user = "user-1-1")
Expand All @@ -1490,6 +1528,18 @@ void should_ApplyFilter_When_QueryingForIdNotIn() {

assertThat(list).containsExactly(taskSummary2);
}

@WithAccessId(user = "user-1-1")
@Test
void should_ThrowException_When_WorkBasketHasOpenReadButNoReadTasksPermission() {
assertThatThrownBy(
() ->
taskService
.createTaskQuery()
.workbasketIdIn(wbWithoutReadTasksPerm.getId())
.list())
.isInstanceOf(NotAuthorizedToQueryWorkbasketException.class);
}
}

@Nested
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,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 @@ -60,6 +60,7 @@ void setup(ClassificationService classificationService, WorkbasketService workba
.workbasketId(defaultWorkbasketSummary.getId())
.accessId("user-1-1")
.permission(WorkbasketPermission.READ)
.permission(WorkbasketPermission.READTASKS)
.permission(WorkbasketPermission.APPEND)
.permission(WorkbasketPermission.TRANSFER)
.buildAndStore(workbasketService);
Expand All @@ -68,6 +69,7 @@ void setup(ClassificationService classificationService, WorkbasketService workba
.workbasketId(newWorkbasket.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 @@ -57,6 +57,7 @@ void setup(ClassificationService classificationService, WorkbasketService workba
.workbasketId(defaultWorkbasketSummary.getId())
.accessId("user-1-1")
.permission(WorkbasketPermission.READ)
.permission(WorkbasketPermission.READTASKS)
.permission(WorkbasketPermission.APPEND)
.permission(WorkbasketPermission.TRANSFER)
.buildAndStore(workbasketService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,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 @@ -61,6 +61,7 @@ void setup(ClassificationService classificationService, WorkbasketService workba
.workbasketId(defaultWorkbasketSummary.getId())
.accessId("user-1-1")
.permission(WorkbasketPermission.READ)
.permission(WorkbasketPermission.READTASKS)
.permission(WorkbasketPermission.APPEND)
.permission(WorkbasketPermission.TRANSFER)
.buildAndStore(workbasketService);
Expand All @@ -69,6 +70,7 @@ void setup(ClassificationService classificationService, WorkbasketService workba
.workbasketId(newWorkbasket.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 @@ -58,6 +58,7 @@ void setup(ClassificationService classificationService, WorkbasketService workba
.workbasketId(defaultWorkbasketSummary.getId())
.accessId("user-1-1")
.permission(WorkbasketPermission.READ)
.permission(WorkbasketPermission.READTASKS)
.permission(WorkbasketPermission.APPEND)
.permission(WorkbasketPermission.TRANSFER)
.buildAndStore(workbasketService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,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 @@ -74,6 +74,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 @@ -46,6 +46,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 @@ -50,6 +50,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 @@ -61,6 +61,7 @@ void setup() throws Exception {
.accessId("user-1-1")
.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 @@ -53,6 +53,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

0 comments on commit 57e3441

Please sign in to comment.