@RequestMapping(value = "/account/groups/edit/removeMember", method = RequestMethod.POST) public ModelAndView removeMembership( @RequestParam String groupId, @RequestParam String username) { Collection<Group> groups = groupService.getGroupsWhereCurrentUserIsAdmin(); Group currentGroup = null; for (Group group : groups) { if (group.getGroupId().equals(groupId)) { currentGroup = group; break; } } if (currentGroup == null) { return reinitializePage(); } User memberToRemove = userService.getUserByUsername(username); if (memberToRemove == null) { return new ModelAndView( "redirect:/tatami/account/groups/edit?wrongUser=true&groupId=" + currentGroup.getGroupId()); } groupService.removeMemberFromGroup(memberToRemove, currentGroup); return new ModelAndView( "redirect:/tatami/account/groups/edit?memberRemove=true&groupId=" + currentGroup.getGroupId()); }
@RequestMapping(value = "/account/groups/edit", method = RequestMethod.GET) public ModelAndView editGroup( @RequestParam String groupId, @RequestParam(required = false) boolean editGroup, @RequestParam(required = false) boolean memberAdd, @RequestParam(required = false) boolean memberRemove, @RequestParam(required = false) boolean noUser, @RequestParam(required = false) boolean wrongUser) { ModelAndView mv = basicModelAndView(); mv.addObject("editGroup", editGroup); mv.addObject("memberAdd", memberAdd); mv.addObject("memberRemove", memberRemove); mv.addObject("noUser", noUser); mv.addObject("wrongUser", wrongUser); Collection<Group> groups = groupService.getGroupsWhereCurrentUserIsAdmin(); Group group = null; for (Group testGroup : groups) { if (testGroup.getGroupId().equals(groupId)) { group = testGroup; break; } } if (group == null) { return new ModelAndView("redirect:/tatami/account/groups"); } Collection<UserGroupDTO> users = groupService.getMembersForGroup(group.getGroupId()); mv.addObject("users", users); mv.addObject("group", group); mv.setViewName("account_groups_edit"); return mv; }
@RequestMapping(value = "/account/groups", method = RequestMethod.POST) public ModelAndView addNewGroup(@ModelAttribute("group") Group group) { group.setName(group.getName().replace("<", " ")); group.setDescription(group.getDescription().replace("<", " ")); if (group.getName() != null && !group.getName().equals("")) { groupService.createGroup(group.getName(), group.getDescription(), group.isPublicGroup()); return new ModelAndView("redirect:/tatami/account/groups?success=true"); } return reinitializePage(); }
private Collection<Group> getGroupDetails(User currentUser, Collection<String> groupIds) { String domain = DomainUtil.getDomainFromLogin(currentUser.getLogin()); Collection<Group> groups = new TreeSet<Group>(); for (String groupId : groupIds) { Group group = groupRepository.getGroupById(domain, groupId); Group groupDetails = groupDetailsRepository.getGroupDetails(groupId); group.setName(groupDetails.getName()); group.setPublicGroup(groupDetails.isPublicGroup()); group.setDescription(groupDetails.getDescription()); long counter = groupCounterRepository.getGroupCounter(domain, groupId); group.setCounter(counter); groups.add(group); } return groups; }
public void removeMemberFromGroup(User user, Group group) { String groupId = group.getGroupId(); Collection<String> userCurrentGroupIds = userGroupRepository.findGroups(user.getLogin()); boolean userIsAlreadyAMember = false; for (String testGroupId : userCurrentGroupIds) { if (testGroupId.equals(groupId)) { userIsAlreadyAMember = true; } } if (userIsAlreadyAMember) { groupMembersRepository.removeMember(groupId, user.getLogin()); groupCounterRepository.decrementGroupCounter(user.getDomain(), groupId); userGroupRepository.removeGroup(user.getLogin(), groupId); } else { if (log.isDebugEnabled()) { log.debug("User " + user.getLogin() + " is not a member of group " + group.getName()); } } }
@RequestMapping(value = "/account/groups/edit", method = RequestMethod.POST) public ModelAndView doEditGroup(@ModelAttribute("group") Group group) { if (group.getGroupId() == null) { return new ModelAndView("redirect:/tatami/account/groups"); } Collection<Group> groups = groupService.getGroupsWhereCurrentUserIsAdmin(); boolean isGroupManagedByCurrentUser = false; for (Group testGroup : groups) { if (testGroup.getGroupId().equals(group.getGroupId())) { isGroupManagedByCurrentUser = true; break; } } if (!isGroupManagedByCurrentUser) { return new ModelAndView("redirect:/tatami/account/groups"); } group.setDomain(authenticationService.getCurrentUser().getDomain()); group.setName(group.getName().replace("<", " ")); group.setDescription(group.getDescription().replace("<", " ")); groupService.editGroup(group); return new ModelAndView( "redirect:/tatami/account/groups/edit?editGroup=true&groupId=" + group.getGroupId()); }
@RequestMapping(value = "/account/groups/edit/addMember", method = RequestMethod.POST) public ModelAndView addMembership( @ModelAttribute("userGroupMembership") UserGroupMembership userGroupMembership) { if (log.isDebugEnabled()) { log.debug("Managing group membership for : " + userGroupMembership); } String groupId = userGroupMembership.getGroupId(); if (groupId == null || groupId.equals("")) { return reinitializePage(); } Collection<Group> groups = groupService.getGroupsWhereCurrentUserIsAdmin(); Group currentGroup = null; for (Group group : groups) { if (group.getGroupId().equals(groupId)) { currentGroup = group; break; } } if (currentGroup == null) { return reinitializePage(); } String username = userGroupMembership.getUsername(); if (username == null || username.equals("")) { return new ModelAndView( "redirect:/tatami/account/groups/edit?noUser=true&groupId=" + currentGroup.getGroupId()); } User newMember = userService.getUserByUsername(username); if (newMember == null) { return new ModelAndView( "redirect:/tatami/account/groups/edit?wrongUser=true&groupId=" + currentGroup.getGroupId()); } groupService.addMemberToGroup(newMember, currentGroup); return new ModelAndView( "redirect:/tatami/account/groups/edit?memberAdd=true&groupId=" + currentGroup.getGroupId()); }
public void editGroup(Group group) { groupDetailsRepository.editGroupDetails( group.getGroupId(), group.getName(), group.getDescription()); }