/** * Constructor which fills dto fields from user. * * @param user copying source */ public UserSecurityDto(JCUser user) { this.userId = user.getId(); }
/** * User must have permissions to edit own or other profiles. * So we must check them for users, who try to edit profiles. * * @param editedUserId an identifier of edited user */ private void checkPermissionsToEditProfile(long editedUserId) { JCUser editorUser = userService.getCurrentUser(); if (editorUser.getId() == editedUserId) { userService.checkPermissionToEditOwnProfile(editorUser.getId()); } else { userService.checkPermissionToEditOtherProfiles(editorUser.getId()); } }
/** * User doesn't need to have permission to edit his password and notifications. * For other users we have to check permission to edit other profiles. * * @param editedUserId an identifier of edited user * @see <a href="http://jira.jtalks.org/browse/JC-1740">JC-1740</a> */ private void checkPermissionForEditNotificationsOrSecurity(long editedUserId) { JCUser editorUser = userService.getCurrentUser(); if (editorUser.getId() != editedUserId) { userService.checkPermissionToEditOtherProfiles(editorUser.getId()); } }
private JCUser updateCacheAndGet(long principalId){ JCUser cached = CACHED_USER.get(); if (cached == null || cached.getId() != principalId){ cached = JCUser.copyUser(userDao.loadById(principalId)); CACHED_USER.set(cached); } return cached; }
/** * Customized serialization of the fields {@link org.jtalks.common.model.entity.Entity#id}, * {@link org.jtalks.common.model.entity.Entity#uuid} * * Note: The {@link org.jtalks.common.model.entity.User#groups} is marked as transient and will not be serialized * (for more details pls. see at <a href="http://jira.jtalks.org/browse/POULPE-528">JIRA</a>). * * @serialData {@link org.jtalks.common.model.entity.Entity#id}, * {@link org.jtalks.common.model.entity.Entity#uuid}, * and the hole entities {@link org.jtalks.common.model.entity.User}, * {@link org.jtalks.jcommune.model.entity.JCUser} * expect for the transient fields {@link org.jtalks.common.model.entity.User#groups} and * {@link org.jtalks.jcommune.model.entity.JCUser#contacts} * @param s * @throws IOException */ private void writeObject(ObjectOutputStream s) throws IOException { s.defaultWriteObject(); s.writeLong(getId()); s.writeObject(getUuid()); } }
/** * Makes URL to mark topic page as read. * For anonymous user returns empty optional. * * @param user current user * @param page page to mark as read * @return Optional url string */ public Optional<String> getMarkAsReadUrl(JCUser user, String page) { if (user.isAnonymous()) { return Optional.absent(); } return Optional.of("{topicId}/page/{pageNum}/markread?userId={userId}&lastModified={lastModified}" .replace("{topicId}", String.valueOf(getId())) .replace("{pageNum}", page) .replace("{userId}", String.valueOf(user.getId())) .replace("{lastModified}", String.valueOf(getLastModificationPostDate().getMillis())) ); } }
/** * Constructor which fills dto fields from user. * * @param user copying source */ public EditUserProfileDto(JCUser user) { this.userId = user.getId(); this.username = user.getUsername(); this.userProfileVersion = user.getVersion(); }
/** * Get link to user's profile. * * @param username user's name * @return null when user doesn't exist, otherwise link to user's profile */ private String getLinkToUserProfile(String username, UserDao userDao) { String userPofileLink = null; JCUser user = userDao.getByUsername(username); if (user != null && user.getUsername().equals(username)) { userPofileLink = getApplicationNameAsContextPath() + "/users/" + user.getId(); LOGGER.trace("{} has the following url of profile - {}", username, userPofileLink); } else { LOGGER.trace("Mentioned user wasn't find: {}", username); } return userPofileLink; }
/** * Constructor which fills dto fields from user. * * @param user copying source */ public UserNotificationsDto(JCUser user) { this.userId = user.getId(); this.autosubscribe = user.isAutosubscribe(); this.mentioningNotificationsEnabled = user.isMentioningNotificationsEnabled(); this.sendPmNotification = user.isSendPmNotification(); }
/** * Update user profile info. Check if the user enter valid data and update profile in database. * In error case return into the edit profile page and draw the error. * <p/> * * @param editedProfileDto dto populated by user * @param result binding result which contains the validation result * @param response http servlet response * @return return to user profile page * @throws org.jtalks.jcommune.plugin.api.exceptions.NotFoundException * if edited user doesn't exist in system */ @RequestMapping(value = "/users/*/profile", method = RequestMethod.POST) public ModelAndView saveEditedProfile(@Valid @ModelAttribute(EDITED_USER) EditUserProfileDto editedProfileDto, BindingResult result, HttpServletResponse response) throws NotFoundException { if (result.hasErrors()) { return new ModelAndView(EDIT_PROFILE, EDITED_USER, editedProfileDto); } long editedUserId = editedProfileDto.getUserProfileDto().getUserId(); checkPermissionsToEditProfile(editedUserId); JCUser user = retryTemplate.execute(new SaveProfileRetryCallback(editedUserId, editedProfileDto, PROFILE)); //redirect to the view profile page return new ModelAndView("redirect:/users/" + user.getId() + "/" + PROFILE); }
/** * Update user notification settings. Check if the user enter valid data and update settings in database. * In error case return into the edit profile page and draw the error. * <p/> * * @param editedProfileDto dto populated by user * @param result binding result which contains the validation result * @param response http servlet response * @return in case of errors return back to edit notifications page, in another case return to user profile page * @throws org.jtalks.jcommune.plugin.api.exceptions.NotFoundException * if edited user doesn't exist in system */ @RequestMapping(value = "/users/*/notifications", method = RequestMethod.POST) public ModelAndView saveEditedNotifications(@Valid @ModelAttribute(EDITED_USER) EditUserProfileDto editedProfileDto, BindingResult result, HttpServletResponse response) throws NotFoundException { if (result.hasErrors()) { return new ModelAndView(EDIT_PROFILE, EDITED_USER, editedProfileDto); } long editedUserId = editedProfileDto.getUserNotificationsDto().getUserId(); checkPermissionForEditNotificationsOrSecurity(editedUserId); JCUser user = retryTemplate.execute(new SaveProfileRetryCallback(editedUserId, editedProfileDto, NOTIFICATIONS)); //redirect to the view profile page return new ModelAndView("redirect:/users/" + user.getId() + "/" + NOTIFICATIONS); }
/** * Render the page with a form for creation new Private Message with empty {@link PrivateMessageDto} bound. * * @return {@code ModelAndView} with the form */ @RequestMapping(value = "/pm/new", method = RequestMethod.GET) public ModelAndView newPmPage(@RequestParam(value = "recipientId", required = false) Long recipientId) throws NotFoundException { Long senderId = userService.getCurrentUser().getId(); pmService.checkPermissionsToSend(senderId); PrivateMessageDto pmDto = new PrivateMessageDto(); if (recipientId != null) { String name = userService.get(recipientId).getUsername(); pmDto.setRecipient(name); } return new ModelAndView(PM_FORM) .addObject(DTO, pmDto); }
/** * Update user contacts. Check if the user enter valid data and update contacts in database. * In error case return into the edit profile page and draw the error. * <p/> * * @param editedProfileDto dto populated by user * @param result binding result which contains the validation result * @param response http servlet response * @return in case of errors return back to edit contacts page, in another case return to user profile page * @throws org.jtalks.jcommune.plugin.api.exceptions.NotFoundException * if edited user doesn't exist in system */ @RequestMapping(value = "/users/*/contacts", method = RequestMethod.POST) public ModelAndView saveEditedContacts(@Valid @ModelAttribute(EDITED_USER) EditUserProfileDto editedProfileDto, BindingResult result, HttpServletResponse response) throws NotFoundException { if (result.hasErrors()) { editedProfileDto.getUserContactsDto().setContactTypes(contactsService.getAvailableContactTypes()); return new ModelAndView(EDIT_PROFILE, EDITED_USER, editedProfileDto); } long editedUserId = editedProfileDto.getUserId(); checkPermissionsToEditProfile(editedUserId); JCUser user = retryTemplate.execute(new SaveProfileRetryCallback(editedUserId, editedProfileDto, CONTACTS)); //redirect to the view profile page return new ModelAndView("redirect:/users/" + user.getId() + "/" + CONTACTS); }
/** * Update user security info. Check if the user enter valid data and update user security info in database. * In error case return into the edit profile page and draw the error. * <p/> * * @param editedProfileDto dto populated by user * @param result binding result which contains the validation result * @param response http servlet response * @return in case of errors return back to edit security page, in another case return to user profile page * @throws org.jtalks.jcommune.plugin.api.exceptions.NotFoundException * if edited user doesn't exist in system */ @RequestMapping(value = "/users/*/security", method = RequestMethod.POST) public ModelAndView saveEditedSecurity(@Valid @ModelAttribute(EDITED_USER) EditUserProfileDto editedProfileDto, BindingResult result, HttpServletResponse response, RedirectAttributes redirectAttributes) throws NotFoundException { if (result.hasErrors()) { return new ModelAndView(EDIT_PROFILE, EDITED_USER, editedProfileDto); } long editedUserId = editedProfileDto.getUserSecurityDto().getUserId(); checkPermissionForEditNotificationsOrSecurity(editedUserId); JCUser user = retryTemplate.execute(new SaveProfileRetryCallback(editedUserId, editedProfileDto, SECURITY)); if (editedProfileDto.getUserSecurityDto().getNewUserPassword() != null) { redirectAttributes.addFlashAttribute(IS_PASSWORD_CHANGED_ATTRIB, true); } //redirect to the view profile page return new ModelAndView("redirect:/users/" + user.getId() + "/" + SECURITY); }
/** * Creates CodeReviewCommentDto from {@link PostComment} * * @param comment to create dto * @throws java.lang.NumberFormatException if comment have no line_number attribute * or if this attribute have invalid value */ public CodeReviewCommentDto(PostComment comment) { this.id = comment.getId(); this.lineNumber = Integer.parseInt(comment.getAttributes().get(LINE_NUMBER_PROPERTY_NAME)); this.body = comment.getBody(); this.authorId = comment.getAuthor().getId(); this.authorUsername = comment.getAuthor().getUsername(); if (comment.getUserChanged() != null) { this.editorId = comment.getUserChanged().getId(); this.editorUsername = comment.getUserChanged().getUsername(); } this.modificationDate = comment.getModificationDate(); }
public CommentDto(PostComment postComment, JodaDateTimeTool dateTimeTool) { this.id = postComment.getId(); this.authorUsername = postComment.getAuthor().getUsername(); this.body = postComment.getBody(); this.formattedCreationDate = dateTimeTool.format(postComment.getCreationDate()); this.authorId = postComment.getAuthor().getId(); }
return getCustomErrorJsonResponse("unexpectedError"); return new JsonResponse(JsonResponseStatus.FAIL, user.getId()); } else { return new JsonResponse(JsonResponseStatus.FAIL);
/** * Constructor which fills dto fields from user. * * @param user copying source */ public UserProfileDto(JCUser user) { this.userId = user.getId(); this.firstName = user.getFirstName(); this.lastName = user.getLastName(); this.email = user.getEmail(); this.signature = user.getSignature(); this.pageSize = user.getPageSize(); this.location = user.getLocation(); this.postCount = user.getPostCount(); this.registrationDate = user.getRegistrationDate(); this.lastLogin = user.getLastLogin(); }
copy.setId(user.getId()); copy.setFirstName(user.getFirstName()); copy.setLastName(user.getLastName());