@Override public DocumentModel getThreadForComment(DocumentModel comment) throws CommentSecurityException { if (comment.getPropertyValue(COMMENT_PARENT_ID) != null) { return second.getThreadForComment(comment); } return first.getThreadForComment(comment); }
@Override public void handleNotifications(Event event) { EventContext ctx = event.getContext(); DocumentEventContext docCtx = (DocumentEventContext) ctx; if (docCtx.getSourceDocument().getType().equals("Post") || docCtx.getSourceDocument().getType().equals(CommentsConstants.COMMENT_DOC_TYPE)) { CommentManager commentManager = Framework.getService(CommentManager.class); DocumentModel thread = commentManager.getThreadForComment(docCtx.getSourceDocument()); if (thread != null) { Object[] args = { thread, null }; docCtx.setArgs(args); } } } }
@Override protected void writeEntityBody(Comment entity, JsonGenerator jg) throws IOException { writeCommentEntity(entity, jg); CoreSession session = ctx.getSession(null).getSession(); NuxeoPrincipal principal = session.getPrincipal(); PermissionProvider permissionProvider = Framework.getService(PermissionProvider.class); // Write permissions of current user on the annotation, // which are the ones granted on the commented document Collection<String> permissions = CoreInstance.doPrivileged(session, s -> { if (entity.getId() == null) { return Collections.emptyList(); } DocumentRef ancestorRef = new IdRef( (String) commentManager.getThreadForComment(s.getDocument(new IdRef(entity.getId()))) .getPropertyValue(COMMENT_PARENT_ID)); return s.filterGrantedPermissions(principal, ancestorRef, Arrays.asList(permissionProvider.getPermissions())); }); jg.writeArrayFieldStart(COMMENT_PERMISSIONS); for (String permission : permissions) { jg.writeString(permission); } jg.writeEndArray(); boolean includeRepliesSummary = ctx.getFetched(COMMENT_ENTITY_TYPE).contains(FETCH_REPLIES_SUMMARY); if (includeRepliesSummary) { writeRepliesSummary(session, entity, jg); } }