Closes #44: Comments visible from share app

+ metadata-complete="true" in web.xml to skip annotations scanning
(second try with Jetty 9)
This commit is contained in:
jendib 2015-11-21 20:31:21 +01:00
parent 1c7381376c
commit 7e5aa9aecf
11 changed files with 61 additions and 30 deletions

View File

@ -32,7 +32,7 @@
<org.imgscalr.imgscalr-lib.version>4.2</org.imgscalr.imgscalr-lib.version>
<org.apache.pdfbox.pdfbox.version>2.0.0-RC1</org.apache.pdfbox.pdfbox.version>
<org.bouncycastle.bcprov-jdk15on.version>1.53</org.bouncycastle.bcprov-jdk15on.version>
<joda-time.joda-time.version>2.9</joda-time.joda-time.version>
<joda-time.joda-time.version>2.9.1</joda-time.joda-time.version>
<org.hibernate.hibernate.version>4.1.0.Final</org.hibernate.hibernate.version>
<javax.servlet.javax.servlet-api.version>3.1.0</javax.servlet.javax.servlet-api.version>
<com.levigo.jbig2.levigo-jbig2-imageio.version>1.6.3</com.levigo.jbig2.levigo-jbig2-imageio.version>

View File

@ -158,6 +158,9 @@ public class TokenBasedSecurityFilter implements Filter {
Set<String> baseFunctionSet = userBaseFuction.findByRoleId(user.getRoleId());
userPrincipal.setBaseFunctionSet(baseFunctionSet);
// Add email
userPrincipal.setEmail(user.getEmail());
request.setAttribute(PRINCIPAL_ATTRIBUTE, userPrincipal);
}

View File

@ -219,7 +219,6 @@
</systemProperties>
<webApp>
<contextPath>/docs-web</contextPath>
<overrideDescriptor>src/dev/main/webapp/web-override.xml</overrideDescriptor>
</webApp>
</configuration>
</plugin>

View File

@ -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">
<!-- Override init parameter to avoid nasty file locking issue on windows. -->
<servlet>

View File

@ -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();
}

View File

@ -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">
<display-name>Docs</display-name>
<!-- This filter is used to process a couple things in the request context -->
@ -55,4 +56,6 @@
<servlet-name>JerseyServlet</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
<absolute-ordering/>
</web-app>

View File

@ -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.
*/

View File

@ -74,9 +74,7 @@
<div ng-repeat="comment in comments" class="media" style="overflow: hidden">
<div class="pull-left">
<a href="#">
<img ng-src="http://www.gravatar.com/avatar/{{ comment.creator_gravatar }}?s=40&d=identicon" class="media-object" />
</a>
</div>
<div class="media-body">
<strong>{{ comment.creator }}</strong>

View File

@ -1,5 +1,5 @@
<div class="row">
<div class="well col-md-12">
<div class="col-md-10">
<div class="page-header">
<h1>
{{ document.title }} <small>{{ document.create_date | date: 'yyyy-MM-dd' }}</small>
@ -26,4 +26,31 @@
<div ui-view="file"></div>
</div>
<div class="col-md-2">
<p class="page-header">
<span class="glyphicon glyphicon-comment"></span>
Comments
</p>
<div ng-show="!comments || comments.length == 0" class="text-center text-muted">
<h1 class="glyphicon glyphicon-comment"></h1>
<p ng-show="!comments && !commentsError">Loading...</p>
<p ng-show="comments.length == 0">No comments on this document yet</p>
<p ng-show="!comments && commentsError">Error loading comments</p>
</div>
<div ng-repeat="comment in comments" class="media" style="overflow: hidden">
<div class="pull-left">
<img ng-src="http://www.gravatar.com/avatar/{{ comment.creator_gravatar }}?s=40&d=identicon" class="media-object" />
</div>
<div class="media-body">
<strong>{{ comment.creator }}</strong>
<p>
{{ comment.content }}<br />
<span class="text-muted">{{ comment.create_date | date: 'yyyy-MM-dd' }}</span>
</p>
</div>
</div>
</div>
</div>

View File

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="docs"
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">
<!-- Override init parameter to avoid nasty file locking issue on windows. -->
<servlet>
<servlet-name>default</servlet-name>
<init-param>
<param-name>useFileMappedBuffer</param-name>
<param-value>false</param-value>
</init-param>
</servlet>
</web-app>

View File

@ -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)