From 7e5aa9aecf11e7356dc3ffe90bcab83fde4d16c5 Mon Sep 17 00:00:00 2001 From: jendib Date: Sat, 21 Nov 2015 20:31:21 +0100 Subject: [PATCH] Closes #44: Comments visible from share app + metadata-complete="true" in web.xml to skip annotations scanning (second try with Jetty 9) --- docs-parent/pom.xml | 2 +- .../util/filter/TokenBasedSecurityFilter.java | 3 ++ docs-web/pom.xml | 1 - docs-web/src/dev/main/webapp/web-override.xml | 3 +- .../docs/rest/resource/CommentResource.java | 13 +++++---- docs-web/src/main/webapp/WEB-INF/web.xml | 5 +++- .../webapp/src/app/share/controller/Share.js | 7 +++++ .../src/partial/docs/document.view.html | 4 +-- .../main/webapp/src/partial/share/share.html | 29 ++++++++++++++++++- .../src/stress/main/webapp/web-override.xml | 16 ---------- .../sismics/docs/rest/TestShareResource.java | 8 +++++ 11 files changed, 61 insertions(+), 30 deletions(-) delete mode 100644 docs-web/src/stress/main/webapp/web-override.xml diff --git a/docs-parent/pom.xml b/docs-parent/pom.xml index 895168e5..8015a475 100644 --- a/docs-parent/pom.xml +++ b/docs-parent/pom.xml @@ -32,7 +32,7 @@ 4.2 2.0.0-RC1 1.53 - 2.9 + 2.9.1 4.1.0.Final 3.1.0 1.6.3 diff --git a/docs-web-common/src/main/java/com/sismics/util/filter/TokenBasedSecurityFilter.java b/docs-web-common/src/main/java/com/sismics/util/filter/TokenBasedSecurityFilter.java index 037cc94c..2e65cc9a 100644 --- a/docs-web-common/src/main/java/com/sismics/util/filter/TokenBasedSecurityFilter.java +++ b/docs-web-common/src/main/java/com/sismics/util/filter/TokenBasedSecurityFilter.java @@ -158,6 +158,9 @@ public class TokenBasedSecurityFilter implements Filter { Set baseFunctionSet = userBaseFuction.findByRoleId(user.getRoleId()); userPrincipal.setBaseFunctionSet(baseFunctionSet); + // Add email + userPrincipal.setEmail(user.getEmail()); + request.setAttribute(PRINCIPAL_ATTRIBUTE, userPrincipal); } diff --git a/docs-web/pom.xml b/docs-web/pom.xml index 5fee5f2a..29016e40 100644 --- a/docs-web/pom.xml +++ b/docs-web/pom.xml @@ -219,7 +219,6 @@ /docs-web - src/dev/main/webapp/web-override.xml diff --git a/docs-web/src/dev/main/webapp/web-override.xml b/docs-web/src/dev/main/webapp/web-override.xml index ea56b8c9..1dea0dae 100644 --- a/docs-web/src/dev/main/webapp/web-override.xml +++ b/docs-web/src/dev/main/webapp/web-override.xml @@ -3,7 +3,8 @@ xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" - version="3.0"> + version="3.0" + metadata-complete="true"> diff --git a/docs-web/src/main/java/com/sismics/docs/rest/resource/CommentResource.java b/docs-web/src/main/java/com/sismics/docs/rest/resource/CommentResource.java index 52017f8a..a940e989 100644 --- a/docs-web/src/main/java/com/sismics/docs/rest/resource/CommentResource.java +++ b/docs-web/src/main/java/com/sismics/docs/rest/resource/CommentResource.java @@ -11,6 +11,7 @@ import javax.ws.rs.GET; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; @@ -65,8 +66,9 @@ public class CommentResource extends BaseResource { // Returns the comment JsonObjectBuilder response = Json.createObjectBuilder() .add("id", comment.getId()) - .add("creator", principal.getName()) .add("content", comment.getContent()) + .add("creator", principal.getName()) + .add("creator_gravatar", ImageUtil.computeGravatar(principal.getEmail())) .add("create_date", comment.getCreateDate().getTime()); return Response.ok().entity(response.build()).build(); } @@ -120,14 +122,13 @@ public class CommentResource extends BaseResource { */ @GET @Path("{documentId: [a-z0-9\\-]+}") - public Response get(@PathParam("documentId") String documentId) { - if (!authenticate()) { - throw new ForbiddenClientException(); - } + public Response get(@PathParam("documentId") String documentId, + @QueryParam("share") String shareId) { + authenticate(); // Read access on doc gives access to read comments DocumentDao documentDao = new DocumentDao(); - if (documentDao.getDocument(documentId, PermType.READ, principal.getId()) == null) { + if (documentDao.getDocument(documentId, PermType.READ, shareId == null ? principal.getId() : shareId) == null) { return Response.status(Status.NOT_FOUND).build(); } diff --git a/docs-web/src/main/webapp/WEB-INF/web.xml b/docs-web/src/main/webapp/WEB-INF/web.xml index de15dab3..0c5629fb 100644 --- a/docs-web/src/main/webapp/WEB-INF/web.xml +++ b/docs-web/src/main/webapp/WEB-INF/web.xml @@ -3,7 +3,8 @@ xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" - version="3.0"> + version="3.0" + metadata-complete="true"> Docs @@ -55,4 +56,6 @@ JerseyServlet /api/* + + diff --git a/docs-web/src/main/webapp/src/app/share/controller/Share.js b/docs-web/src/main/webapp/src/app/share/controller/Share.js index c1e15ae6..c85f65c8 100644 --- a/docs-web/src/main/webapp/src/app/share/controller/Share.js +++ b/docs-web/src/main/webapp/src/app/share/controller/Share.js @@ -20,6 +20,13 @@ angular.module('share').controller('Share', function($scope, $state, $stateParam $scope.files = data.files; }); + // Load comments from server + Restangular.one('comment', $stateParams.documentId).get({ share: $stateParams.shareId }).then(function(data) { + $scope.comments = data.comments; + }, function(response) { + $scope.commentsError = response; + }); + /** * Navigate to the selected file. */ diff --git a/docs-web/src/main/webapp/src/partial/docs/document.view.html b/docs-web/src/main/webapp/src/partial/docs/document.view.html index b7f25544..f3f4ad86 100644 --- a/docs-web/src/main/webapp/src/partial/docs/document.view.html +++ b/docs-web/src/main/webapp/src/partial/docs/document.view.html @@ -74,9 +74,7 @@
- - - +
{{ comment.creator }} diff --git a/docs-web/src/main/webapp/src/partial/share/share.html b/docs-web/src/main/webapp/src/partial/share/share.html index 42efc1b1..25833a68 100644 --- a/docs-web/src/main/webapp/src/partial/share/share.html +++ b/docs-web/src/main/webapp/src/partial/share/share.html @@ -1,5 +1,5 @@
-
+
+ +
+ + +
+

+

Loading...

+

No comments on this document yet

+

Error loading comments

+
+ +
+
+ +
+
+ {{ comment.creator }} +

+ {{ comment.content }}
+ {{ comment.create_date | date: 'yyyy-MM-dd' }} +

+
+
+
\ No newline at end of file diff --git a/docs-web/src/stress/main/webapp/web-override.xml b/docs-web/src/stress/main/webapp/web-override.xml deleted file mode 100644 index ea56b8c9..00000000 --- a/docs-web/src/stress/main/webapp/web-override.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - default - - useFileMappedBuffer - false - - - diff --git a/docs-web/src/test/java/com/sismics/docs/rest/TestShareResource.java b/docs-web/src/test/java/com/sismics/docs/rest/TestShareResource.java index ba641334..eea8ab85 100644 --- a/docs-web/src/test/java/com/sismics/docs/rest/TestShareResource.java +++ b/docs-web/src/test/java/com/sismics/docs/rest/TestShareResource.java @@ -78,6 +78,14 @@ public class TestShareResource extends BaseJerseyTest { Assert.assertEquals(document1Id, json.getString("id")); Assert.assertEquals(3, json.getJsonArray("acls").size()); // 2 for the creator, 1 for the share + // Get all comments from this document anonymously + json = target().path("/comment/" + document1Id) + .queryParam("share", share1Id) + .request() + .get(JsonObject.class); + JsonArray comments = json.getJsonArray("comments"); + Assert.assertEquals(0, comments.size()); + // Get all files from this document anonymously json = target().path("/file/list") .queryParam("id", document1Id)