Commit ff285a55 authored by Piotr Gawron's avatar Piotr Gawron

Merge branch '931-minervanet-error-report-107' into 'master'

Resolve "MINERVANET - Error Report 107"

Closes #931

See merge request !927
parents 7f42c480 3af2f4e6
Pipeline #13864 passed with stage
in 14 minutes and 48 seconds
...@@ -16,7 +16,10 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority; ...@@ -16,7 +16,10 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import lcsb.mapviewer.api.*; import lcsb.mapviewer.api.*;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.model.security.PrivilegeType; import lcsb.mapviewer.model.security.PrivilegeType;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.services.interfaces.IUserService;
@RestController @RestController
@RequestMapping(value = "/projects/{projectId}/comments", produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/projects/{projectId}/comments", produces = MediaType.APPLICATION_JSON_VALUE)
...@@ -26,9 +29,12 @@ public class CommentController extends BaseController { ...@@ -26,9 +29,12 @@ public class CommentController extends BaseController {
private CommentRestImpl commentController; private CommentRestImpl commentController;
private IUserService userService;
@Autowired @Autowired
public CommentController(CommentRestImpl commentController) { public CommentController(CommentRestImpl commentController, IUserService userService) {
this.commentController = commentController; this.commentController = commentController;
this.userService = userService;
} }
@PreAuthorize("hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)") @PreAuthorize("hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)")
...@@ -63,7 +69,7 @@ public class CommentController extends BaseController { ...@@ -63,7 +69,7 @@ public class CommentController extends BaseController {
@PreAuthorize("hasAuthority('IS_ADMIN')" + @PreAuthorize("hasAuthority('IS_ADMIN')" +
" or hasAuthority('IS_CURATOR') and hasAuthority('WRITE_PROJECT:' + #projectId)" + " or hasAuthority('IS_CURATOR') and hasAuthority('WRITE_PROJECT:' + #projectId)" +
" or @commentService.getCommentById(#commentId)?.user?.login == authentication.name") " or @commentService.getOwnerByCommentId(#commentId)?.login == authentication.name")
@DeleteMapping(value = "/{commentId}/") @DeleteMapping(value = "/{commentId}/")
public Map<String, Object> removeComment( public Map<String, Object> removeComment(
@RequestBody(required = false) String body, @RequestBody(required = false) String body,
...@@ -129,10 +135,15 @@ public class CommentController extends BaseController { ...@@ -129,10 +135,15 @@ public class CommentController extends BaseController {
@RequestParam(value = "content") String content, @RequestParam(value = "content") String content,
@RequestParam(value = "pinned", defaultValue = "true") String pinned, @RequestParam(value = "pinned", defaultValue = "true") String pinned,
@RequestParam(value = "coordinates") String coordinates, @RequestParam(value = "coordinates") String coordinates,
@PathVariable(value = "modelId") String modelId) throws QueryException { @PathVariable(value = "modelId") String modelId, Authentication authentication) throws QueryException {
Point2D pointCoordinates = parseCoordinates(coordinates); Point2D pointCoordinates = parseCoordinates(coordinates);
User user = userService.getUserByLogin(authentication.getName());
if (user.getLogin().equals(Configuration.ANONYMOUS_LOGIN)) {
user = null;
}
return commentController.addComment(projectId, ElementIdentifierType.ALIAS.getJsName(), elementId, name, return commentController.addComment(projectId, ElementIdentifierType.ALIAS.getJsName(), elementId, name,
email, content, pinned.toLowerCase().equals("true"), pointCoordinates, modelId); email, content, pinned.toLowerCase().equals("true"), pointCoordinates, modelId, user);
} }
@PreAuthorize("hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)") @PreAuthorize("hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)")
...@@ -145,10 +156,14 @@ public class CommentController extends BaseController { ...@@ -145,10 +156,14 @@ public class CommentController extends BaseController {
@RequestParam(value = "content") String content, @RequestParam(value = "content") String content,
@RequestParam(value = "pinned", defaultValue = "true") String pinned, @RequestParam(value = "pinned", defaultValue = "true") String pinned,
@RequestParam(value = "coordinates") String coordinates, @RequestParam(value = "coordinates") String coordinates,
@PathVariable(value = "modelId") String modelId) throws QueryException { @PathVariable(value = "modelId") String modelId, Authentication authentication) throws QueryException {
Point2D pointCoordinates = parseCoordinates(coordinates); Point2D pointCoordinates = parseCoordinates(coordinates);
User user = userService.getUserByLogin(authentication.getName());
if (user.getLogin().equals(Configuration.ANONYMOUS_LOGIN)) {
user = null;
}
return commentController.addComment(projectId, ElementIdentifierType.REACTION.getJsName(), reactionId, name, return commentController.addComment(projectId, ElementIdentifierType.REACTION.getJsName(), reactionId, name,
email, content, pinned.toLowerCase().equals("true"), pointCoordinates, modelId); email, content, pinned.toLowerCase().equals("true"), pointCoordinates, modelId, user);
} }
@PreAuthorize("hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)") @PreAuthorize("hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)")
...@@ -160,10 +175,14 @@ public class CommentController extends BaseController { ...@@ -160,10 +175,14 @@ public class CommentController extends BaseController {
@RequestParam(value = "content") String content, @RequestParam(value = "content") String content,
@RequestParam(value = "pinned", defaultValue = "true") String pinned, @RequestParam(value = "pinned", defaultValue = "true") String pinned,
@PathVariable(value = "coordinates") String coordinates, @PathVariable(value = "coordinates") String coordinates,
@PathVariable(value = "modelId") String modelId) throws QueryException { @PathVariable(value = "modelId") String modelId, Authentication authentication) throws QueryException {
Point2D pointCoordinates = parseCoordinates(coordinates); Point2D pointCoordinates = parseCoordinates(coordinates);
User user = userService.getUserByLogin(authentication.getName());
if (user.getLogin().equals(Configuration.ANONYMOUS_LOGIN)) {
user = null;
}
return commentController.addComment(projectId, ElementIdentifierType.POINT.getJsName(), coordinates, name, return commentController.addComment(projectId, ElementIdentifierType.POINT.getJsName(), coordinates, name,
email, content, pinned.toLowerCase().equals("true"), pointCoordinates, modelId); email, content, pinned.toLowerCase().equals("true"), pointCoordinates, modelId, user);
} }
private Point2D parseCoordinates(String coordinates) throws QueryException { private Point2D parseCoordinates(String coordinates) throws QueryException {
......
...@@ -18,6 +18,7 @@ import lcsb.mapviewer.model.map.Comment; ...@@ -18,6 +18,7 @@ import lcsb.mapviewer.model.map.Comment;
import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.reaction.Reaction; import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.species.Element; import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.persist.dao.map.ReactionDao; import lcsb.mapviewer.persist.dao.map.ReactionDao;
import lcsb.mapviewer.persist.dao.map.species.ElementDao; import lcsb.mapviewer.persist.dao.map.species.ElementDao;
import lcsb.mapviewer.services.interfaces.ICommentService; import lcsb.mapviewer.services.interfaces.ICommentService;
...@@ -245,7 +246,7 @@ public class CommentRestImpl extends BaseRestImpl { ...@@ -245,7 +246,7 @@ public class CommentRestImpl extends BaseRestImpl {
} }
public Map<String, Object> addComment(String projectId, String elementType, String elementId, public Map<String, Object> addComment(String projectId, String elementType, String elementId,
String name, String email, String content, boolean pinned, Point2D pointCoordinates, String submodelId) String name, String email, String content, boolean pinned, Point2D pointCoordinates, String submodelId, User owner)
throws QueryException { throws QueryException {
Model model = getModelService().getLastModelByProjectId(projectId); Model model = getModelService().getLastModelByProjectId(projectId);
if (model == null) { if (model == null) {
...@@ -280,7 +281,7 @@ public class CommentRestImpl extends BaseRestImpl { ...@@ -280,7 +281,7 @@ public class CommentRestImpl extends BaseRestImpl {
} }
Comment comment = commentService.addComment(name, email, content, pointCoordinates, commentedObject, pinned, Comment comment = commentService.addComment(name, email, content, pointCoordinates, commentedObject, pinned,
submodel); submodel, owner);
return preparedComment(comment, createCommentColumnSet("")); return preparedComment(comment, createCommentColumnSet(""));
} }
......
...@@ -76,7 +76,7 @@ public class CommentService implements ICommentService { ...@@ -76,7 +76,7 @@ public class CommentService implements ICommentService {
@Override @Override
public Comment addComment(String name, String email, String content, Point2D coordinates, Object object, public Comment addComment(String name, String email, String content, Point2D coordinates, Object object,
boolean pinned, Model submodel) { boolean pinned, Model submodel, User owner) {
Comment comment = new Comment(); Comment comment = new Comment();
comment.setName(name); comment.setName(name);
comment.setEmail(email); comment.setEmail(email);
...@@ -87,7 +87,7 @@ public class CommentService implements ICommentService { ...@@ -87,7 +87,7 @@ public class CommentService implements ICommentService {
comment.setTableName(object.getClass()); comment.setTableName(object.getClass());
comment.setTableId(ObjectUtils.getIdOfObject(object)); comment.setTableId(ObjectUtils.getIdOfObject(object));
} }
comment.setUser(null); comment.setUser(owner);
comment.setPinned(pinned); comment.setPinned(pinned);
commentDao.add(comment); commentDao.add(comment);
...@@ -313,4 +313,15 @@ public class CommentService implements ICommentService { ...@@ -313,4 +313,15 @@ public class CommentService implements ICommentService {
&& !(Math.abs(y1 - y2) > COMMENT_POINT_DISTANCE_EPSILON); && !(Math.abs(y1 - y2) > COMMENT_POINT_DISTANCE_EPSILON);
} }
@Override
public User getOwnerByCommentId(String commentId) {
Comment comment = getCommentById(commentId);
if (comment == null || comment.getUser() == null) {
return null;
}
// fetch lazy data
comment.getUser().getLogin();
return comment.getUser();
}
} }
...@@ -38,7 +38,7 @@ public interface ICommentService { ...@@ -38,7 +38,7 @@ public interface ICommentService {
* @return comment object created based on the data provided as parameters * @return comment object created based on the data provided as parameters
*/ */
Comment addComment(String name, String email, String content, Point2D coordinates, Object object, Comment addComment(String name, String email, String content, Point2D coordinates, Object object,
boolean pinned, Model submodel); boolean pinned, Model submodel, User owner);
/** /**
* This method remove comment. Comment is not removed from the system, only * This method remove comment. Comment is not removed from the system, only
...@@ -81,5 +81,7 @@ public interface ICommentService { ...@@ -81,5 +81,7 @@ public interface ICommentService {
void removeCommentsForModel(ModelData model); void removeCommentsForModel(ModelData model);
Comment getCommentById(String commentId); Comment getCommentById(String commentId);
User getOwnerByCommentId(String commentId);
} }
...@@ -64,11 +64,11 @@ public class CommentServiceTest extends ServiceTestFunctions { ...@@ -64,11 +64,11 @@ public class CommentServiceTest extends ServiceTestFunctions {
@Test @Test
public void testGetAgregatedComments() throws Exception { public void testGetAgregatedComments() throws Exception {
commentService.addComment("John Doe", "a@a.pl", "Conteneta 1", new Point2D.Double(0, 1), alias, false, model); commentService.addComment("John Doe", "a@a.pl", "Conteneta 1", new Point2D.Double(0, 1), alias, false, model, userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
commentService.addComment("John Doe", "a@a.pl", "Contenetb 2", new Point2D.Double(0, 2), alias, false, model); commentService.addComment("John Doe", "a@a.pl", "Contenetb 2", new Point2D.Double(0, 2), alias, false, model, userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
commentService.addComment("John Doe", "a@a.pl", "Contenetc 3", new Point2D.Double(0, 3), alias2, false, model); commentService.addComment("John Doe", "a@a.pl", "Contenetc 3", new Point2D.Double(0, 3), alias2, false, model, userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
commentService.addComment("John Doe", "a@a.pl", "Contenetc 4", new Point2D.Double(0, 4), null, false, model); commentService.addComment("John Doe", "a@a.pl", "Contenetc 4", new Point2D.Double(0, 4), null, false, model, userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
commentService.addComment("John Doe", "a@a.pl", "Contenetc 5", new Point2D.Double(0, 5), null, false, model); commentService.addComment("John Doe", "a@a.pl", "Contenetc 5", new Point2D.Double(0, 5), null, false, model, userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
CommentService service = new CommentService(null, null, null, null); CommentService service = new CommentService(null, null, null, null);
service.setCommentDao(commentDao); service.setCommentDao(commentDao);
List<List<Comment>> comments = service.getAgregatedComments(model, null); List<List<Comment>> comments = service.getAgregatedComments(model, null);
...@@ -89,7 +89,7 @@ public class CommentServiceTest extends ServiceTestFunctions { ...@@ -89,7 +89,7 @@ public class CommentServiceTest extends ServiceTestFunctions {
@Test @Test
public void testAddComment() throws Exception { public void testAddComment() throws Exception {
long counter = commentService.getCommentCount(); long counter = commentService.getCommentCount();
Comment feedback = commentService.addComment("a", "b", "c", new Point2D.Double(0, 0), null, false, model); Comment feedback = commentService.addComment("a", "b", "c", new Point2D.Double(0, 0), null, false, model, userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
long counter2 = commentService.getCommentCount(); long counter2 = commentService.getCommentCount();
assertEquals(counter + 1, counter2); assertEquals(counter + 1, counter2);
commentDao.delete(feedback); commentDao.delete(feedback);
...@@ -99,7 +99,7 @@ public class CommentServiceTest extends ServiceTestFunctions { ...@@ -99,7 +99,7 @@ public class CommentServiceTest extends ServiceTestFunctions {
public void testAddCommentForReaction() throws Exception { public void testAddCommentForReaction() throws Exception {
long counter = commentService.getCommentCount(); long counter = commentService.getCommentCount();
Comment feedback = commentService.addComment("a", "b", "c", new Point2D.Double(0, 0), Comment feedback = commentService.addComment("a", "b", "c", new Point2D.Double(0, 0),
model.getReactions().iterator().next(), false, model); model.getReactions().iterator().next(), false, model, userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
long counter2 = commentService.getCommentCount(); long counter2 = commentService.getCommentCount();
assertEquals(counter + 1, counter2); assertEquals(counter + 1, counter2);
commentDao.delete(feedback); commentDao.delete(feedback);
...@@ -109,7 +109,7 @@ public class CommentServiceTest extends ServiceTestFunctions { ...@@ -109,7 +109,7 @@ public class CommentServiceTest extends ServiceTestFunctions {
public void testAddCommentForAlias() throws Exception { public void testAddCommentForAlias() throws Exception {
Element alias = model.getElementByElementId("sa1"); Element alias = model.getElementByElementId("sa1");
long counter = commentService.getCommentCount(); long counter = commentService.getCommentCount();
Comment feedback = commentService.addComment("a", "b", "c", new Point2D.Double(0, 0), alias, false, model); Comment feedback = commentService.addComment("a", "b", "c", new Point2D.Double(0, 0), alias, false, model, userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
long counter2 = commentService.getCommentCount(); long counter2 = commentService.getCommentCount();
assertEquals(counter + 1, counter2); assertEquals(counter + 1, counter2);
commentDao.delete(feedback); commentDao.delete(feedback);
......
...@@ -24,6 +24,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -24,6 +24,7 @@ import org.springframework.transaction.annotation.Transactional;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.model.Project; import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.map.Comment; import lcsb.mapviewer.model.map.Comment;
import lcsb.mapviewer.model.map.model.ModelData; import lcsb.mapviewer.model.map.model.ModelData;
...@@ -40,6 +41,8 @@ import lcsb.mapviewer.services.interfaces.IUserService; ...@@ -40,6 +41,8 @@ import lcsb.mapviewer.services.interfaces.IUserService;
@Rollback @Rollback
public class CommentControllerIntegrationTest extends ControllerIntegrationTest { public class CommentControllerIntegrationTest extends ControllerIntegrationTest {
Logger logger = LogManager.getLogger();
private static final String TEST_PROJECT = "test_project"; private static final String TEST_PROJECT = "test_project";
private static final String TEST_USER_PASSWORD = "test_user_pass"; private static final String TEST_USER_PASSWORD = "test_user_pass";
private static final String TEST_USER_LOGIN = "test_user"; private static final String TEST_USER_LOGIN = "test_user";
...@@ -47,10 +50,10 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest ...@@ -47,10 +50,10 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
private static final String TEST_CURATOR_LOGIN = "test_curator"; private static final String TEST_CURATOR_LOGIN = "test_curator";
private static final String TEST_ADMIN_PASSWORD = "test_admin"; private static final String TEST_ADMIN_PASSWORD = "test_admin";
private static final String TEST_ADMIN_LOGIN = "test_admin"; private static final String TEST_ADMIN_LOGIN = "test_admin";
Logger logger = LogManager.getLogger();
private ModelData map; private ModelData map;
private Reaction reaction; private Reaction reaction;
private Element element; private Element element;
private Project project;
@Autowired @Autowired
private CommentDao commentDao; private CommentDao commentDao;
...@@ -63,7 +66,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest ...@@ -63,7 +66,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
@Before @Before
public void setup() { public void setup() {
Project project = createProject(TEST_PROJECT); project = createProject(TEST_PROJECT);
project.setOwner(userService.getUserByLogin(BUILT_IN_TEST_ADMIN_LOGIN)); project.setOwner(userService.getUserByLogin(BUILT_IN_TEST_ADMIN_LOGIN));
map = project.getModels().iterator().next(); map = project.getModels().iterator().next();
reaction = map.getReactions().iterator().next(); reaction = map.getReactions().iterator().next();
...@@ -135,14 +138,14 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest ...@@ -135,14 +138,14 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
} }
private void createComments() { private void createComments() {
Comment comment = createComment(); Comment comment = createComment(map);
commentDao.add(comment); commentDao.add(comment);
comment = createComment(); comment = createComment(map);
comment.setPinned(true); comment.setPinned(true);
commentDao.add(comment); commentDao.add(comment);
comment = createComment(); comment = createComment(map);
comment.setDeleted(true); comment.setDeleted(true);
commentDao.add(comment); commentDao.add(comment);
} }
...@@ -176,7 +179,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest ...@@ -176,7 +179,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
MockHttpSession session = createSession(TEST_USER_LOGIN, TEST_USER_PASSWORD); MockHttpSession session = createSession(TEST_USER_LOGIN, TEST_USER_PASSWORD);
Comment comment = createComment(); Comment comment = createComment(map);
comment.setName("author name"); comment.setName("author name");
comment.setPinned(true); comment.setPinned(true);
commentDao.add(comment); commentDao.add(comment);
...@@ -201,7 +204,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest ...@@ -201,7 +204,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
MockHttpSession session = createSession(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD); MockHttpSession session = createSession(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
Comment comment = createComment(); Comment comment = createComment(map);
comment.setName("author name"); comment.setName("author name");
comment.setPinned(true); comment.setPinned(true);
commentDao.add(comment); commentDao.add(comment);
...@@ -226,7 +229,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest ...@@ -226,7 +229,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
MockHttpSession session = createSession(TEST_CURATOR_LOGIN, TEST_CURATOR_PASSWORD); MockHttpSession session = createSession(TEST_CURATOR_LOGIN, TEST_CURATOR_PASSWORD);
Comment comment = createComment(); Comment comment = createComment(map);
comment.setName("author name"); comment.setName("author name");
comment.setPinned(true); comment.setPinned(true);
commentDao.add(comment); commentDao.add(comment);
...@@ -267,7 +270,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest ...@@ -267,7 +270,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
MockHttpSession session = createSession(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD); MockHttpSession session = createSession(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
Comment comment = createComment(); Comment comment = createComment(map);
commentDao.add(comment); commentDao.add(comment);
RequestBuilder request = delete("/projects/" + TEST_PROJECT + "/comments/" + comment.getId() + "/") RequestBuilder request = delete("/projects/" + TEST_PROJECT + "/comments/" + comment.getId() + "/")
...@@ -286,7 +289,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest ...@@ -286,7 +289,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
MockHttpSession session = createSession(TEST_CURATOR_LOGIN, TEST_CURATOR_PASSWORD); MockHttpSession session = createSession(TEST_CURATOR_LOGIN, TEST_CURATOR_PASSWORD);
Comment comment = createComment(); Comment comment = createComment(map);
commentDao.add(comment); commentDao.add(comment);
RequestBuilder request = delete("/projects/" + TEST_PROJECT + "/comments/" + comment.getId() + "/") RequestBuilder request = delete("/projects/" + TEST_PROJECT + "/comments/" + comment.getId() + "/")
...@@ -305,7 +308,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest ...@@ -305,7 +308,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
MockHttpSession session = createSession(TEST_CURATOR_LOGIN, TEST_CURATOR_PASSWORD); MockHttpSession session = createSession(TEST_CURATOR_LOGIN, TEST_CURATOR_PASSWORD);
Comment comment = createComment(); Comment comment = createComment(map);
commentDao.add(comment); commentDao.add(comment);
RequestBuilder request = delete("/projects/" + TEST_PROJECT + "/comments/" + comment.getId() + "/") RequestBuilder request = delete("/projects/" + TEST_PROJECT + "/comments/" + comment.getId() + "/")
...@@ -318,12 +321,11 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest ...@@ -318,12 +321,11 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
@Test @Test
public void testRemoveAsOwner() throws Exception { public void testRemoveAsOwner() throws Exception {
User user = createCurator(TEST_USER_LOGIN, TEST_USER_PASSWORD); User user = createUser(TEST_USER_LOGIN, TEST_USER_PASSWORD, project);
MockHttpSession session = createSession(TEST_USER_LOGIN, TEST_USER_PASSWORD); MockHttpSession session = createSession(TEST_USER_LOGIN, TEST_USER_PASSWORD);
Comment comment = createComment(); Comment comment = createComment(map, user);
comment.setUser(user);
commentDao.add(comment); commentDao.add(comment);
RequestBuilder request = delete("/projects/" + TEST_PROJECT + "/comments/" + comment.getId() + "/") RequestBuilder request = delete("/projects/" + TEST_PROJECT + "/comments/" + comment.getId() + "/")
...@@ -338,7 +340,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest ...@@ -338,7 +340,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
@Test @Test
public void testRemoveAsGuestAccount() throws Exception { public void testRemoveAsGuestAccount() throws Exception {
Comment comment = createComment(); Comment comment = createComment(map);
commentDao.add(comment); commentDao.add(comment);
RequestBuilder request = delete("/projects/" + TEST_PROJECT + "/comments/" + comment.getId() + "/") RequestBuilder request = delete("/projects/" + TEST_PROJECT + "/comments/" + comment.getId() + "/")
...@@ -520,7 +522,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest ...@@ -520,7 +522,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
MockHttpSession session = createSession(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD); MockHttpSession session = createSession(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
Comment comment = createComment(); Comment comment = createComment(map);
commentDao.add(comment); commentDao.add(comment);
RequestBuilder request = get( RequestBuilder request = get(
...@@ -543,7 +545,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest ...@@ -543,7 +545,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
MockHttpSession session = createSession(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD); MockHttpSession session = createSession(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
Comment comment = createComment(); Comment comment = createComment(map);
commentDao.add(comment); commentDao.add(comment);
RequestBuilder request = get( RequestBuilder request = get(
...@@ -562,7 +564,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest ...@@ -562,7 +564,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
MockHttpSession session = createSession(TEST_CURATOR_LOGIN, TEST_CURATOR_PASSWORD); MockHttpSession session = createSession(TEST_CURATOR_LOGIN, TEST_CURATOR_PASSWORD);
Comment comment = createComment(); Comment comment = createComment(map);
commentDao.add(comment); commentDao.add(comment);
RequestBuilder request = get( RequestBuilder request = get(
...@@ -585,7 +587,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest ...@@ -585,7 +587,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
MockHttpSession session = createSession(TEST_USER_LOGIN, TEST_USER_PASSWORD); MockHttpSession session = createSession(TEST_USER_LOGIN, TEST_USER_PASSWORD);
Comment comment = createComment(); Comment comment = createComment(map);
commentDao.add(comment); commentDao.add(comment);
RequestBuilder request = get( RequestBuilder request = get(
...@@ -599,7 +601,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest ...@@ -599,7 +601,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
@Test @Test
public void testAddElementCommentAsUserWithAccess() throws Exception { public void testAddElementCommentAsUserWithAccess() throws Exception {
createUser(TEST_USER_LOGIN, TEST_USER_PASSWORD, map.getProject()); User user = createUser(TEST_USER_LOGIN, TEST_USER_PASSWORD, map.getProject());
MockHttpSession session = createSession(TEST_USER_LOGIN, TEST_USER_PASSWORD); MockHttpSession session = createSession(TEST_USER_LOGIN, TEST_USER_PASSWORD);
...@@ -621,6 +623,36 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest ...@@ -621,6 +623,36 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
.andExpect(status().is2xxSuccessful()); .andExpect(status().is2xxSuccessful());
assertEquals(1, commentDao.getCommentByModel(map, null, null).size()); assertEquals(1, commentDao.getCommentByModel(map, null, null).size());
Comment comment = commentDao.getCommentByModel(map, null, null).get(0);
assertEquals("Owner of the comment wasn't set properly", user, comment.getUser());
}
@Test
public void testAddElementCommentAsAnonymous() throws Exception {
String body = EntityUtils.toString(new UrlEncodedFormEntity(Arrays.asList(
new BasicNameValuePair("name", "test_user"),
new BasicNameValuePair("email", "a@a.lu"),
new BasicNameValuePair("content", "tes content"),
new BasicNameValuePair("pinned", "true"),
new BasicNameValuePair("coordinates", "10,2"),
new BasicNameValuePair("modelId", map.getId().toString()))));
userService.grantUserPrivilege(userService.getUserByLogin(Configuration.ANONYMOUS_LOGIN),
PrivilegeType.READ_PROJECT, TEST_PROJECT);
RequestBuilder request = post(
"/projects/" + TEST_PROJECT + "/comments/models/" + map.getId() + "/bioEntities/elements/" + element.getId())
.