Search in sources :

Example 1 with WorkbasketPermission

use of pro.taskana.WorkbasketPermission in project taskana by Taskana.

the class WorkbasketServiceImplTest method testGetWorkbasketById.

@Test
public void testGetWorkbasketById() throws NotAuthorizedException, WorkbasketNotFoundException {
    String wbId = "ID-1";
    Workbasket wb = createTestWorkbasket(wbId, "key-1");
    WorkbasketPermission authorization = WorkbasketPermission.READ;
    doReturn(wb).when(workbasketMapperMock).findById(wbId);
    doNothing().when(cutSpy).checkAuthorization(wb.getId(), authorization);
    Workbasket actualWb = cutSpy.getWorkbasket(wbId);
    verify(taskanaEngineImplMock, times(1)).openConnection();
    verify(workbasketMapperMock, times(1)).findById(wbId);
    verify(cutSpy, times(1)).checkAuthorization(wb.getId(), authorization);
    verify(taskanaEngineImplMock, times(1)).returnConnection();
    verify(taskanaEngineImplMock, times(1)).isUserInRole(any());
    verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock, taskanaEngineImplMock, taskanaEngineConfigurationMock);
    assertThat(actualWb, equalTo(wb));
}
Also used : WorkbasketPermission(pro.taskana.WorkbasketPermission) Workbasket(pro.taskana.Workbasket) Test(org.junit.Test)

Example 2 with WorkbasketPermission

use of pro.taskana.WorkbasketPermission in project taskana by Taskana.

the class WorkbasketServiceImplTest method testGetWorkbasketById_NonAuthorizedUser.

@Test(expected = NotAuthorizedException.class)
public void testGetWorkbasketById_NonAuthorizedUser() throws WorkbasketNotFoundException, NotAuthorizedException {
    String wbId = "ID-1";
    Workbasket wb = createTestWorkbasket(wbId, "Key-1");
    WorkbasketPermission authorization = WorkbasketPermission.READ;
    doReturn(wb).when(workbasketMapperMock).findById(wbId);
    doThrow(NotAuthorizedException.class).when(cutSpy).checkAuthorization(wb.getId(), authorization);
    try {
        cutSpy.getWorkbasket(wbId);
    } catch (NotAuthorizedException ex) {
        verify(taskanaEngineImplMock, times(1)).openConnection();
        verify(workbasketMapperMock, times(1)).findById(wbId);
        verify(cutSpy, times(1)).checkAuthorization(wb.getId(), authorization);
        verify(taskanaEngineImplMock, times(1)).returnConnection();
        verify(taskanaEngineImplMock, times(1)).isUserInRole(any());
        verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock, taskanaEngineImplMock, taskanaEngineConfigurationMock);
        throw ex;
    }
}
Also used : WorkbasketPermission(pro.taskana.WorkbasketPermission) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) Workbasket(pro.taskana.Workbasket) Test(org.junit.Test)

Example 3 with WorkbasketPermission

use of pro.taskana.WorkbasketPermission in project taskana by Taskana.

the class WorkbasketServiceImplTest method testGetWorkbasketByKey_NonAuthorizedUser.

@Test(expected = NotAuthorizedException.class)
public void testGetWorkbasketByKey_NonAuthorizedUser() throws WorkbasketNotFoundException, NotAuthorizedException {
    String wbKey = "Key-1";
    Workbasket wb = createTestWorkbasket("ID", wbKey);
    WorkbasketPermission authorization = WorkbasketPermission.READ;
    doReturn(wb).when(workbasketMapperMock).findByKeyAndDomain(wbKey, "domain");
    doThrow(NotAuthorizedException.class).when(cutSpy).checkAuthorization(wbKey, "domain", authorization);
    try {
        cutSpy.getWorkbasket(wbKey, "domain");
    } catch (NotAuthorizedException ex) {
        verify(taskanaEngineImplMock, times(1)).openConnection();
        verify(workbasketMapperMock, times(1)).findByKeyAndDomain(wbKey, "domain");
        verify(cutSpy, times(1)).checkAuthorization(wbKey, "domain", authorization);
        verify(taskanaEngineImplMock, times(1)).returnConnection();
        verify(taskanaEngineImplMock, times(1)).isUserInRole(any());
        verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock, taskanaEngineImplMock, taskanaEngineConfigurationMock);
        throw ex;
    }
}
Also used : WorkbasketPermission(pro.taskana.WorkbasketPermission) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) Workbasket(pro.taskana.Workbasket) Test(org.junit.Test)

Example 4 with WorkbasketPermission

use of pro.taskana.WorkbasketPermission in project taskana by Taskana.

the class GetWorkbasketAccTest method testGetWorkbasketPermissions.

@WithAccessId(userName = "user_1_1", groupNames = { "group_1" })
@Test
public void testGetWorkbasketPermissions() {
    WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
    List<WorkbasketPermission> permissions = workbasketService.getPermissionsForWorkbasket("WBI:100000000000000000000000000000000007");
    Assert.assertEquals(4, permissions.size());
    Assert.assertTrue(permissions.contains(WorkbasketPermission.READ));
    Assert.assertTrue(permissions.contains(WorkbasketPermission.OPEN));
    Assert.assertTrue(permissions.contains(WorkbasketPermission.TRANSFER));
    Assert.assertTrue(permissions.contains(WorkbasketPermission.APPEND));
}
Also used : WorkbasketService(pro.taskana.WorkbasketService) WorkbasketPermission(pro.taskana.WorkbasketPermission) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 5 with WorkbasketPermission

use of pro.taskana.WorkbasketPermission in project taskana by Taskana.

the class WorkbasketServiceImpl method getPermissionsForWorkbasket.

@Override
public List<WorkbasketPermission> getPermissionsForWorkbasket(String workbasketId) {
    List<WorkbasketPermission> permissions = new ArrayList<>();
    WorkbasketAccessItem wbAcc = workbasketAccessMapper.findByWorkbasketAndAccessId(workbasketId, CurrentUserContext.getAccessIds());
    this.addWorkbasketAccessItemValuesToPermissionSet(wbAcc, permissions);
    return permissions;
}
Also used : WorkbasketPermission(pro.taskana.WorkbasketPermission) WorkbasketAccessItem(pro.taskana.WorkbasketAccessItem) ArrayList(java.util.ArrayList)

Aggregations

WorkbasketPermission (pro.taskana.WorkbasketPermission)6 Test (org.junit.Test)5 Workbasket (pro.taskana.Workbasket)4 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)2 AbstractAccTest (acceptance.AbstractAccTest)1 ArrayList (java.util.ArrayList)1 WorkbasketAccessItem (pro.taskana.WorkbasketAccessItem)1 WorkbasketService (pro.taskana.WorkbasketService)1 WithAccessId (pro.taskana.security.WithAccessId)1