private boolean currentUserIsAuthor(JCUser currentUser, PrivateMessage privateMessage) { boolean isAuthor = false; try { //because a recipient can be deleted. isAuthor = currentUser.equals(privateMessage.getUserTo()); } catch (org.hibernate.ObjectNotFoundException e) { logger.warn("The recipient doesn't exist", e); } return isAuthor; }
/** * Create the full private message dto from {@link PrivateMessage} * * @param pm private message for conversion * @return dto for full private message */ public static PrivateMessageDto getFullPmDtoFor(PrivateMessage pm) { PrivateMessageDto dto = new PrivateMessageDto(); dto.setBody(pm.getBody()); dto.setTitle(pm.getTitle()); if (pm.getUserTo() != null) { dto.setRecipient(pm.getUserTo().getUsername()); } dto.setId(pm.getId()); return dto; }
/** * {@inheritDoc} */ @Override @PreAuthorize("hasPermission(#id, 'PRIVATE_MESSAGE', 'GeneralPermission.READ')") public PrivateMessage get(Long id) throws NotFoundException { PrivateMessage pm = super.get(id); if (!hasCurrentUserAccessToPM(pm)) { throw new NotFoundException(String.format("current user has no right to read pm %s with id %d", userService.getCurrentUser(), id)); } if (this.ifMessageShouldBeMarkedAsRead(pm)) { pm.setRead(true); this.getDao().saveOrUpdate(pm); userDataCache.decrementNewMessageCountFor(pm.getUserTo().getUsername()); } return pm; }