use of org.jbpm.casemgmt.api.model.instance.CommentInstance in project jbpm by kiegroup.
the class CommentNotificationEventListener method collectOrgEntitiesByRole.
protected Set<OrganizationalEntity> collectOrgEntitiesByRole(List<String> mentionedRoles, CaseCommentEvent event, StringBuilder commentContent) {
Set<OrganizationalEntity> recipients = new HashSet<>();
CommentInstance comment = event.getComment();
for (String roleName : mentionedRoles) {
if (comment.getRestrictedTo() != null && !comment.getRestrictedTo().isEmpty() && !comment.getRestrictedTo().contains(roleName)) {
// mentioned role is not allowed to see this comment so remove it from the list
continue;
}
try {
Collection<OrganizationalEntity> assignments = ((CaseAssignment) event.getCaseFile()).getAssignments(roleName);
recipients.addAll(assignments);
String assignmnetsFlatten = assignments.stream().map(oe -> oe.getId()).collect(Collectors.joining(","));
String updatedCommentContent = commentContent.toString().replaceAll("@" + roleName, assignmnetsFlatten);
commentContent.setLength(0);
commentContent.append(updatedCommentContent);
} catch (IllegalArgumentException e) {
logger.debug("Role {} does not exist in case {}", roleName, event.getCaseId());
}
}
return recipients;
}
use of org.jbpm.casemgmt.api.model.instance.CommentInstance in project jbpm by kiegroup.
the class AuthorizationManagerImpl method checkCommentAuthorization.
@Override
public void checkCommentAuthorization(String caseId, CaseFileInstance caseFileInstance, CommentInstance commentInstance) {
CommentInstanceImpl comment = ((CommentInstanceImpl) commentInstance);
if (comment.getRestrictedTo() == null || comment.getRestrictedTo().isEmpty()) {
return;
}
List<String> callerAuthorization = collectUserAuthInfo();
logger.debug("Caller {} authorization set is {}", identityProvider.getName(), callerAuthorization);
List<String> callerCaseRoles = getCallerRoles(caseFileInstance, callerAuthorization);
logger.debug("Caller {} case role set is {}", identityProvider.getName(), callerCaseRoles);
List<String> requiredRoles = comment.getRestrictedTo();
if (requiredRoles.isEmpty() || requiredRoles.stream().anyMatch(role -> callerCaseRoles.contains(role))) {
logger.debug("Caller has access to comment {}", comment.getId());
return;
}
logger.warn("User {} does not have access to comment {} in case {}, required roles are {} and user has {}", identityProvider.getName(), comment.getId(), caseId, requiredRoles, callerCaseRoles);
throw new SecurityException(MessageFormat.format(NO_AUTH_TO_COMMENT, identityProvider.getName(), comment.getId(), caseId));
}
use of org.jbpm.casemgmt.api.model.instance.CommentInstance in project jbpm by kiegroup.
the class AuthorizationManagerImpl method filterByCommentAuthorization.
@Override
public List<CommentInstance> filterByCommentAuthorization(String caseId, CaseFileInstance caseFileInstance, List<CommentInstance> comments) {
if (comments == null || comments.isEmpty()) {
logger.debug("No comments to be filtered");
return comments;
}
List<String> callerAuthorization = collectUserAuthInfo();
logger.debug("Caller {} authorization set is {}", identityProvider.getName(), callerAuthorization);
List<String> callerCaseRoles = getCallerRoles(caseFileInstance, callerAuthorization);
logger.debug("Caller {} case role set is {}", identityProvider.getName(), callerCaseRoles);
List<CommentInstance> filteredComments = new ArrayList<>(comments);
for (CommentInstance commentInstance : comments) {
CommentInstanceImpl comment = ((CommentInstanceImpl) commentInstance);
List<String> requiredRoles = comment.getRestrictedTo();
if (requiredRoles == null || requiredRoles.isEmpty()) {
continue;
}
if (requiredRoles.isEmpty() || requiredRoles.stream().anyMatch(role -> callerCaseRoles.contains(role))) {
logger.debug("Caller {} has access to comment {}", identityProvider.getName(), comment.getId());
continue;
}
logger.debug("Caller {} does not have access to comment {}", identityProvider.getName(), comment.getId());
filteredComments.remove(comment);
}
return filteredComments;
}
use of org.jbpm.casemgmt.api.model.instance.CommentInstance in project jbpm by kiegroup.
the class CaseServiceImplTest method testCaseWithComments.
@Test
public void testCaseWithComments() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl("john"));
Map<String, Object> data = new HashMap<>();
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_STAGE_AUTO_START_CASE_P_ID, data, roleAssignments);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_AUTO_START_CASE_P_ID, caseFile);
assertNotNull(caseId);
assertEquals(FIRST_CASE_ID, caseId);
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
Collection<CommentInstance> caseComments = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext());
assertNotNull(caseComments);
assertEquals(0, caseComments.size());
String commentId = caseService.addCaseComment(FIRST_CASE_ID, "poul", "just a tiny comment");
assertNotNull(commentId);
caseComments = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext());
assertNotNull(caseComments);
assertEquals(1, caseComments.size());
CommentInstance comment = caseComments.iterator().next();
assertComment(comment, "poul", "just a tiny comment");
assertEquals(commentId, comment.getId());
caseService.updateCaseComment(FIRST_CASE_ID, comment.getId(), comment.getAuthor(), "Updated " + comment.getComment());
caseComments = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext());
assertNotNull(caseComments);
assertEquals(1, caseComments.size());
comment = caseComments.iterator().next();
assertComment(comment, "poul", "Updated just a tiny comment");
caseService.addCaseComment(FIRST_CASE_ID, "mary", "another comment");
caseService.addCaseComment(FIRST_CASE_ID, "john", "third comment");
caseComments = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext());
assertNotNull(caseComments);
assertEquals(3, caseComments.size());
Iterator<CommentInstance> it = caseComments.iterator();
assertComment(it.next(), "poul", "Updated just a tiny comment");
assertComment(it.next(), "mary", "another comment");
assertComment(it.next(), "john", "third comment");
caseComments = caseService.getCaseComments(FIRST_CASE_ID, CommentSortBy.Author, new QueryContext());
assertNotNull(caseComments);
assertEquals(3, caseComments.size());
it = caseComments.iterator();
assertComment(it.next(), "john", "third comment");
assertComment(it.next(), "mary", "another comment");
assertComment(it.next(), "poul", "Updated just a tiny comment");
caseService.removeCaseComment(FIRST_CASE_ID, comment.getId());
caseComments = caseService.getCaseComments(FIRST_CASE_ID, CommentSortBy.Author, new QueryContext());
assertEquals(2, caseComments.size());
it = caseComments.iterator();
assertComment(it.next(), "john", "third comment");
assertComment(it.next(), "mary", "another comment");
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
use of org.jbpm.casemgmt.api.model.instance.CommentInstance in project jbpm by kiegroup.
the class CaseServiceImplTest method testCaseWithCommentsWithRestrictions.
@Test
public void testCaseWithCommentsWithRestrictions() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl("john"));
roleAssignments.put("participant", new UserImpl("mary"));
Map<String, Object> data = new HashMap<>();
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_STAGE_AUTO_START_CASE_P_ID, data, roleAssignments);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_AUTO_START_CASE_P_ID, caseFile);
assertNotNull(caseId);
assertEquals(FIRST_CASE_ID, caseId);
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
Collection<CommentInstance> caseComments = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext());
assertNotNull(caseComments);
assertEquals(0, caseComments.size());
caseService.addCaseComment(FIRST_CASE_ID, "poul", "just a tiny comment", "owner");
caseComments = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext());
assertNotNull(caseComments);
assertEquals(1, caseComments.size());
CommentInstance comment = caseComments.iterator().next();
assertComment(comment, "poul", "just a tiny comment");
// mary is not the owner so should not see the comment that is only for role owner role
identityProvider.setName("mary");
caseComments = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext());
assertNotNull(caseComments);
assertEquals(0, caseComments.size());
try {
caseService.updateCaseComment(FIRST_CASE_ID, comment.getId(), comment.getAuthor(), "Updated " + comment.getComment(), "participant", "owner");
fail("mary should not be able to update comment that she has no access to");
} catch (SecurityException e) {
// mary is not allowed to update comments that she has no access to
assertTrue(e.getMessage().contains("User mary does not have access to comment"));
}
identityProvider.setName("john");
caseService.updateCaseComment(FIRST_CASE_ID, comment.getId(), comment.getAuthor(), "Updated " + comment.getComment(), "participant", "owner");
caseComments = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext());
assertNotNull(caseComments);
assertEquals(1, caseComments.size());
comment = caseComments.iterator().next();
assertComment(comment, "poul", "Updated just a tiny comment");
// now mary as participant should see the updated comment
identityProvider.setName("mary");
caseComments = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext());
assertNotNull(caseComments);
assertEquals(1, caseComments.size());
identityProvider.setName("john");
// no restrictions
caseService.addCaseComment(FIRST_CASE_ID, "mary", "another comment");
caseComments = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext());
assertNotNull(caseComments);
assertEquals(2, caseComments.size());
Iterator<CommentInstance> it = caseComments.iterator();
assertComment(it.next(), "poul", "Updated just a tiny comment");
assertComment(it.next(), "mary", "another comment");
// second comment has no restrictions so should be seen by anyone
identityProvider.setName("mary");
caseComments = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext());
assertNotNull(caseComments);
assertEquals(2, caseComments.size());
identityProvider.setName("john");
caseService.addCaseComment(FIRST_CASE_ID, "john", "private comment", "owner");
caseComments = caseService.getCaseComments(FIRST_CASE_ID, CommentSortBy.Author, new QueryContext());
assertNotNull(caseComments);
assertEquals(3, caseComments.size());
comment = caseComments.iterator().next();
assertComment(comment, "john", "private comment");
identityProvider.setName("mary");
try {
caseService.removeCaseComment(FIRST_CASE_ID, comment.getId());
fail("mary should not be able to remove comment that she has no access to");
} catch (SecurityException e) {
// mary is not allowed to removed comments that she has no access to
assertTrue(e.getMessage().contains("User mary does not have access to comment"));
}
caseComments = caseService.getCaseComments(FIRST_CASE_ID, CommentSortBy.Author, new QueryContext());
assertEquals(2, caseComments.size());
identityProvider.setName("john");
caseComments = caseService.getCaseComments(FIRST_CASE_ID, CommentSortBy.Author, new QueryContext());
assertEquals(3, caseComments.size());
caseService.removeCaseComment(FIRST_CASE_ID, comment.getId());
caseComments = caseService.getCaseComments(FIRST_CASE_ID, CommentSortBy.Author, new QueryContext());
assertEquals(2, caseComments.size());
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
Aggregations