@Before public void initialize() { when(taskContext.getUserGroupCallback()).thenReturn(userGroupCallback); when(taskContext.getTaskQueryService()).thenReturn(taskQueryService); when(taskQueryService.getTaskInstanceById(TASK_ID)).thenReturn(task); when(task.getPeopleAssignments()).thenReturn(peopleAssignments); command = new GetUserTaskCommand(USER_ID, TASK_ID); }
@Override public Task execute(Context cntxt) { TaskContext context = (TaskContext) cntxt; Task task = context.getTaskQueryService().getTaskInstanceById(taskId); if (task == null) { throw new IllegalStateException("Unable to find task with id " + taskId); } if (!checkUserPermissions(userId, task, context)) { throw new PermissionDeniedException("User " + userId + " isn't allowed to see the task " + taskId); } return task; }
@Test public void testUserOnPotentialOwnersGroups() { List<String> userGroups = new ArrayList<>(); userGroups.add("user"); when(userGroupCallback.getGroupsForUser(USER_ID)).thenReturn(userGroups); List<OrganizationalEntity> potentialOwners = new ArrayList<>(); potentialOwners.add(new GroupImpl("user")); when(peopleAssignments.getPotentialOwners()).thenReturn(potentialOwners); Task commandTask = command.execute(taskContext); assertEquals(task, commandTask); }
Task task = userTaskService.execute(containerId, new GetUserTaskCommand(registry.getIdentityProvider().getName(), taskId)); if (task == null) { throw new IllegalStateException("No task with id " + taskId + " found");
@Test public void testUserOnBusinessAdministratorGroups() { List<String> userGroups = new ArrayList<>(); userGroups.add("admin"); when(userGroupCallback.getGroupsForUser(USER_ID)).thenReturn(userGroups); List<OrganizationalEntity> admins = new ArrayList<>(); admins.add(new GroupImpl("admin")); when(peopleAssignments.getBusinessAdministrators()).thenReturn(admins); Task commandTask = command.execute(taskContext); assertEquals(task, commandTask); }
protected boolean checkUserPermissions(String userId, Task task, TaskContext context) { List<String> usersGroup = context.getUserGroupCallback().getGroupsForUser(userId); usersGroup.add(userId); if (checkUserPermissions(usersGroup, task.getPeopleAssignments().getPotentialOwners())) { return true; } return checkUserPermissions(usersGroup, task.getPeopleAssignments().getBusinessAdministrators()); }
public String getTaskRenderedForm(String renderer, String containerId, long taskId) { String resolvedContainerId = registry.getContainerId(containerId, new ByTaskIdContainerLocator(taskId)); Task task = userTaskService.execute(resolvedContainerId, new GetUserTaskCommand(registry.getIdentityProvider().getName(), taskId)); if (task == null) { throw new TaskNotFoundException("No task with id " + taskId + " found");
@Test(expected = PermissionDeniedException.class) public void testUserWithoutPermission() { when(userGroupCallback.getGroupsForUser(USER_ID)).thenReturn(new ArrayList<String>()); when(peopleAssignments.getBusinessAdministrators()).thenReturn(new ArrayList<OrganizationalEntity>()); command.execute(taskContext); fail(); } }
@Test(expected = IllegalStateException.class) public void testGetUnexistentClass() { when(taskQueryService.getTaskInstanceById(TASK_ID)).thenReturn(null); command.execute(taskContext); fail(); }