/** * {@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; }
/** * {@inheritDoc} */ @Override @PreAuthorize("hasPermission(#userFrom.id, 'USER', 'ProfilePermission.SEND_PRIVATE_MESSAGES')") public PrivateMessage sendMessage(String title, String body, JCUser recipient, JCUser userFrom) { PrivateMessage pm = new PrivateMessage(recipient, userFrom, title, body); pm.setRead(false); pm.setStatus(PrivateMessageStatus.SENT); this.getDao().saveOrUpdate(pm); userDataCache.incrementNewMessageCountFor(recipient.getUsername()); securityService.createAclBuilder().grant(GeneralPermission.READ).to(recipient).on(pm).flush(); securityService.createAclBuilder().grant(GeneralPermission.READ).to(userFrom).on(pm).flush(); if (isSendNotificationMessage(recipient)) { mailService.sendReceivedPrivateMessageNotification(recipient, pm); } logger.debug("Private message to user {} was sent. Message id={}", recipient.getUsername(), pm.getId()); return pm; }
/** * {@inheritDoc} */ @Override @PreAuthorize("hasPermission(#userFrom.id, 'USER', 'ProfilePermission.SEND_PRIVATE_MESSAGES')") public PrivateMessage sendDraft(long id, String title, String body, JCUser recipient, JCUser userFrom) throws NotFoundException { PrivateMessage pm = new PrivateMessage(recipient, userFrom, title, body); pm.setId(id); pm.setRead(false); pm.setStatus(PrivateMessageStatus.SENT); this.getDao().saveOrUpdate(pm); userDataCache.incrementNewMessageCountFor(recipient.getUsername()); securityService.deleteFromAcl(pm); securityService.createAclBuilder().grant(GeneralPermission.READ).to(recipient).on(pm).flush(); securityService.createAclBuilder().grant(GeneralPermission.READ).to(userFrom).on(pm).flush(); if (isSendNotificationMessage(recipient)) { mailService.sendReceivedPrivateMessageNotification(recipient, pm); } logger.debug("Private message(was draft) to user {} was sent. Message id={}", recipient.getUsername(), pm.getId()); return pm; }