WorkflowTaskPermissionChecker { public boolean hasPermission( long groupId, WorkflowTask workflowTask, PermissionChecker permissionChecker) { if (permissionChecker.isOmniadmin() || permissionChecker.isCompanyAdmin()) { return true; } int userNotificationEventsCount = UserNotificationEventLocalServiceUtil. getUserNotificationEventsCount( permissionChecker.getUserId(), PortletKeys.MY_WORKFLOW_TASK, HashMapBuilder.put( "workflowInstanceId", String.valueOf(workflowTask.getWorkflowInstanceId()) ).put( "workflowTaskId", String.valueOf(workflowTask.getWorkflowTaskId()) ).build()); if (hasAssetViewPermission(workflowTask, permissionChecker) && ((userNotificationEventsCount > 0) || (workflowTask.isCompleted() && (workflowTask.getAssigneeUserId() == permissionChecker.getUserId())))) { return true; } long[] roleIds = getRoleIds(groupId, permissionChecker); for (WorkflowTaskAssignee workflowTaskAssignee : workflowTask.getWorkflowTaskAssignees()) { if (isWorkflowTaskAssignableToRoles( workflowTaskAssignee, roleIds) || isWorkflowTaskAssignableToUser( workflowTaskAssignee, permissionChecker.getUserId())) { return true; } } if (!hasAssetViewPermission(workflowTask, permissionChecker) && !permissionChecker.isContentReviewer( permissionChecker.getCompanyId(), groupId)) { return false; } return false; }  void check(
			long groupId, WorkflowTask workflowTask,
			PermissionChecker permissionChecker); boolean hasPermission(
		long groupId, WorkflowTask workflowTask,
		PermissionChecker permissionChecker);  }
@Test public void testCompanyAdminHasPermission() { Assert.assertTrue( _workflowTaskPermissionChecker.hasPermission( RandomTestUtil.randomLong(), mockWorkflowTask(), mockCompanyAdminPermissionChecker())); }
@Test public void testContentReviewerHasPermission() { PermissionChecker permissionChecker = mockContentReviewerPermissionChecker(RandomTestUtil.randomLong()); Assert.assertTrue( _workflowTaskPermissionChecker.hasPermission( RandomTestUtil.randomLong(), mockWorkflowTask( User.class.getName(), permissionChecker.getUserId()), permissionChecker)); }
@Test public void testContentReviewerRoleHasPermission() { long[] permissionCheckerRoleIds = randomPermissionCheckerRoleIds(); Assert.assertTrue( _workflowTaskPermissionChecker.hasPermission( RandomTestUtil.randomLong(), mockWorkflowTask( Role.class.getName(), permissionCheckerRoleIds[0]), mockContentReviewerPermissionChecker( RandomTestUtil.randomLong(), permissionCheckerRoleIds))); }
@Test public void testContentReviewerRoleWithAssetViewPermissionHasPermission() { mockAssetRendererHasViewPermission(true); long[] permissionCheckerRoleIds = randomPermissionCheckerRoleIds(); Assert.assertTrue( _workflowTaskPermissionChecker.hasPermission( RandomTestUtil.randomLong(), mockWorkflowTask( Role.class.getName(), permissionCheckerRoleIds[0]), mockPermissionChecker( RandomTestUtil.randomLong(), permissionCheckerRoleIds, false, false, false))); }
@Test public void testContentReviewerWithoutAssetViewPermissionHasPermissionOnCompletedTask() { long[] permissionCheckerRoleIds = randomPermissionCheckerRoleIds(); Assert.assertTrue( _workflowTaskPermissionChecker.hasPermission( RandomTestUtil.randomLong(), mockCompletedWorkflowTask( Role.class.getName(), permissionCheckerRoleIds[0]), mockPermissionChecker( RandomTestUtil.randomLong(), permissionCheckerRoleIds, false, false, false))); }
@Test public void testContentReviewerWithoutAssetViewPermissionHasPermissionOnPendingTask() { long[] permissionCheckerRoleIds = randomPermissionCheckerRoleIds(); Assert.assertTrue( _workflowTaskPermissionChecker.hasPermission( RandomTestUtil.randomLong(), mockWorkflowTask( Role.class.getName(), permissionCheckerRoleIds[0]), mockPermissionChecker( RandomTestUtil.randomLong(), permissionCheckerRoleIds, false, false, false))); }
@Test public void testNotAssigneeHasNoPermission() { long assigneeUserId = RandomTestUtil.randomLong(); Assert.assertFalse( _workflowTaskPermissionChecker.hasPermission( assigneeUserId, mockWorkflowTask(User.class.getName(), assigneeUserId), mockContentReviewerPermissionChecker( RandomTestUtil.randomLong()))); }
@Test public void testNotAssigneeRoleHasNoPermission() { long assigneeRoleId = RandomTestUtil.randomLong(); Assert.assertFalse( _workflowTaskPermissionChecker.hasPermission( assigneeRoleId, mockWorkflowTask(Role.class.getName(), assigneeRoleId), mockContentReviewerPermissionChecker( RandomTestUtil.randomLong()))); }
@Test public void testNotContentReviewerHasNoPermission() { Assert.assertFalse( _workflowTaskPermissionChecker.hasPermission( RandomTestUtil.randomLong(), mockWorkflowTask(), mockPermissionChecker( RandomTestUtil.randomLong(), new long[0], false, false, false))); }
@Test public void testNotContentReviewerWithAssetViewPermissionHasNoPermissionOnCompletedTask() { mockAssetRendererHasViewPermission(true); Assert.assertFalse( _workflowTaskPermissionChecker.hasPermission( RandomTestUtil.randomLong(), mockCompletedWorkflowTask(), mockPermissionChecker( RandomTestUtil.randomLong(), new long[0], false, false, false))); }
@Test public void testNotContentReviewerWithAssetViewPermissionHasNoPermissionOnPendingTask() { mockAssetRendererHasViewPermission(true); Assert.assertFalse( _workflowTaskPermissionChecker.hasPermission( RandomTestUtil.randomLong(), mockWorkflowTask(), mockPermissionChecker( RandomTestUtil.randomLong(), new long[0], false, false, false))); }
@Test public void testNotContentReviewerWithAssetViewPermissionHasPermissionOnPendingTaskWithNotification() { mockAssetRendererHasViewPermission(true); mockUserNotificationEventLocalServiceUtil(1); Assert.assertTrue( _workflowTaskPermissionChecker.hasPermission( RandomTestUtil.randomLong(), mockWorkflowTask(), mockPermissionChecker( RandomTestUtil.randomLong(), new long[0], false, false, false))); }
@Test public void testNotContentReviewerWithoutAssetViewPermissionHasNoPermissionOnCompletedTask() { mockAssetRendererHasViewPermission(false); Assert.assertFalse( _workflowTaskPermissionChecker.hasPermission( RandomTestUtil.randomLong(), mockCompletedWorkflowTask(), mockPermissionChecker( RandomTestUtil.randomLong(), new long[0], false, false, false))); }
@Test public void testNotContentReviewerWithoutAssetViewPermissionHasNoPermissionOnPendingTask() { mockAssetRendererHasViewPermission(false); Assert.assertFalse( _workflowTaskPermissionChecker.hasPermission( RandomTestUtil.randomLong(), mockWorkflowTask(), mockPermissionChecker( RandomTestUtil.randomLong(), new long[0], false, false, false))); }
@Test public void testOmniadminHasPermission() { Assert.assertTrue( _workflowTaskPermissionChecker.hasPermission( RandomTestUtil.randomLong(), mockWorkflowTask(), mockOmniadminPermissionChecker())); }