Commit a51848f6 authored by igoshin's avatar igoshin Committed by Matija Obreza
Browse files

Final version of user story "Add team member"

#10511
parent d38cf10e
......@@ -16,8 +16,6 @@
package org.genesys2.server.service;
import java.util.List;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Team;
import org.genesys2.server.model.impl.User;
......@@ -26,6 +24,8 @@ import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.access.prepost.PreAuthorize;
import java.util.List;
public interface TeamService {
/**
......@@ -40,21 +40,21 @@ public interface TeamService {
/**
* Add a User to the team
*
* @param team
* @param teamUuid
* @param user
* @return
*/
@PreAuthorize("hasRole('ADMINISTRATOR') || hasPermission(#team, 'CREATE')")
Team addTeamMember(Team team, User user);
Team addTeamMember(String teamUuid, User user);
/**
* Remove User from the Team
*
* @param team
* @param teamUuid
* @param user
*/
@PreAuthorize("hasRole('ADMINISTRATOR') || hasPermission(#team, 'CREATE')")
Team removeTeamMember(Team team, User user);
Team removeTeamMember(String teamUuid, User user);
/**
* Remove current user from team
......
......@@ -16,10 +16,6 @@
package org.genesys2.server.service.impl;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.model.impl.FaoInstitute;
......@@ -37,6 +33,10 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@Service
@Transactional(readOnly = true)
public class TeamServiceImpl implements TeamService {
......@@ -76,7 +76,8 @@ public class TeamServiceImpl implements TeamService {
@Override
@Transactional(readOnly = false)
@PreAuthorize("hasRole('ADMINISTRATOR') || hasPermission(#team, 'CREATE')")
public Team addTeamMember(Team team, User user) {
public Team addTeamMember(String teamUuid, User user) {
Team team = teamRepository.findOneByUuid(teamUuid);
if (team.getMembers().contains(user)) {
LOG.info("User already member of this team");
return team;
......@@ -92,7 +93,8 @@ public class TeamServiceImpl implements TeamService {
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') || hasPermission(#team, 'CREATE')")
@Transactional(readOnly = false)
public Team removeTeamMember(Team team, User user) {
public Team removeTeamMember(String teamUuid, User user) {
Team team = teamRepository.findOneByUuid(teamUuid);
if (team.getMembers().remove(user)) {
teamRepository.save(team);
LOG.info("Removed " + user + " from " + team);
......
......@@ -17,15 +17,18 @@
package org.genesys2.server.servlet.controller;
import org.genesys2.server.model.impl.Team;
import org.genesys2.server.model.impl.User;
import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.TeamService;
import org.genesys2.server.service.UserService;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
......@@ -46,6 +49,9 @@ public class TeamController extends BaseController {
@Autowired
private TeamService teamService;
@Autowired
private UserService userService;
@RequestMapping("")
@PreAuthorize("hasRole('ADMINISTRATOR')")
public String viewAll(ModelMap model, @RequestParam(value = "page", required = false, defaultValue = "1") int page) {
......@@ -65,4 +71,39 @@ public class TeamController extends BaseController {
return "/team/details";
}
@RequestMapping("/{teamUuid}/addMember")
public String addTeamMember(@PathVariable("teamUuid") String uuid,
@RequestParam("email") String email, ModelMap model) {
Team team = teamService.getTeam(uuid);
if (team == null) {
throw new ResourceNotFoundException();
}
User user = null;
try {
user = userService.getUserByEmail(email);
} catch (UsernameNotFoundException e) {
model.addAttribute("team", team);
model.addAttribute("teammembers", teamService.getMembers(team));
model.addAttribute("blurp", contentService.getArticle(team, "blurp", getLocale()));
model.addAttribute("error", "error");
return "/team/details";
}
teamService.addTeamMember(uuid, user);
return "redirect:/team/" + uuid;
}
@PreAuthorize("hasRole('ADMINISTRATOR')")
@RequestMapping("/{teamUuid}/{uuid}/deleteMember")
public String deleteTeamMember(@PathVariable("teamUuid") String teamUuid,
@PathVariable("uuid") String uuid) {
User user = userService.getUserByUuid(uuid);
teamService.removeTeamMember(teamUuid,user);
return "redirect:/team/" + teamUuid;
}
}
......@@ -435,8 +435,9 @@ verification.token-key=Validation key
login.invalid-token=Invalid access token
descriptor.category=Descriptor category
method.coding-table=Coding tableoauth-client.info=Client info
method.coding-table=Coding table
oauth-client.info=Client info
oauth-client.list=List of oauth clients
clinet.details.client.id=Client details id
clinet.details.additional.info=Additional info
......@@ -447,3 +448,6 @@ oauth-client=Client
oauth-client.token.issue.date=Issue date
oauth-client.expires.date=Expires date
oauth-client.issued.tokens=Issued tokens
team.user.enter.email=Enter user email
user.not.found=User not found
......@@ -23,11 +23,28 @@
<c:forEach items="${teammembers}" var="user" varStatus="status">
<li class="${status.count % 2 == 0 ? 'even' : 'odd'}">
<c:out value="${user.name}" />
<security:authorize access="hasRole('ADMINISTRATOR')">
<a href="<c:url value="/team/${team.uuid}/${user.uuid}/deleteMember"/> "><spring:message code="delete"/></a>
</security:authorize>
</li>
</c:forEach>
</ul>
<security:authorize access="hasRole('ADMINISTRATOR') or hasPermission(#team, 'WRITE')">
<form action="<c:url value="/team/${team.uuid}/addMember"/>" class="form-horizontal">
<div class="form-group">
<label for="email" class="col-lg-1 control-label"><spring:message code="team.user.enter.email"/></label>
<div class="col-lg-3"><input type="text" id="email" name="email" class="form-control"/></div>
<div class="col-lg-3"><input type="submit" class="btn btn-green" value="<spring:message code="add"/>"/>
</div>
</div>
</form>
</security:authorize>
<c:if test="${error ne null}">
<div class="alert alert-danger"><spring:message code="user.not.found"/></div>
</c:if>
<div class="audit-info">
<div class="audit-info">
<c:if test="${team.lastModifiedBy ne null}"><spring:message code="audit.lastModifiedBy" arguments="${jspHelper.userFullName(team.lastModifiedBy)}" /></c:if>
<fmt:formatDate value="${team.lastModifiedDate}" type="both" />
</div>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment