From 6add34bb33d588add2f4253fae3cc97f320093f4 Mon Sep 17 00:00:00 2001 From: jendib Date: Sat, 23 May 2015 19:16:38 +0200 Subject: [PATCH] #20: Display logs on documents --- .../docs/core/dao/jpa/AuditLogDao.java | 1 + .../docs/rest/resource/AuditLogResource.java | 2 +- .../docs/rest/resource/FileResource.java | 5 +- .../src/app/docs/controller/DocumentView.js | 9 +- .../webapp/src/app/docs/directive/AuditLog.js | 15 ++++ docs-web/src/main/webapp/src/index.html | 1 + .../src/partial/docs/directive.auditlog.html | 32 +++++++ .../src/partial/docs/document.default.html | 87 +++++++++---------- .../src/partial/docs/document.view.html | 8 ++ .../sismics/docs/rest/TestFileResource.java | 6 ++ 10 files changed, 117 insertions(+), 49 deletions(-) create mode 100644 docs-web/src/main/webapp/src/app/docs/directive/AuditLog.js create mode 100644 docs-web/src/main/webapp/src/partial/docs/directive.auditlog.html diff --git a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/AuditLogDao.java b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/AuditLogDao.java index bb63923d..786173c8 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/AuditLogDao.java +++ b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/AuditLogDao.java @@ -75,6 +75,7 @@ public class AuditLogDao { if (criteria.getUserId() != null) { StringBuilder sb0 = new StringBuilder(" (l.LOG_IDENTITY_C = :userId and l.LOG_CLASSENTITY_C = 'User' "); sb0.append(" or l.LOG_IDENTITY_C in (select t.TAG_ID_C from T_TAG t where t.TAG_IDUSER_C = :userId) and l.LOG_CLASSENTITY_C = 'Tag' "); + // Show only logs from owned documents, ACL are lost on delete sb0.append(" or l.LOG_IDENTITY_C in (select d.DOC_ID_C from T_DOCUMENT d where d.DOC_IDUSER_C = :userId) and l.LOG_CLASSENTITY_C = 'Document') "); criteriaList.add(sb0.toString()); parameterMap.put("userId", criteria.getUserId()); diff --git a/docs-web/src/main/java/com/sismics/docs/rest/resource/AuditLogResource.java b/docs-web/src/main/java/com/sismics/docs/rest/resource/AuditLogResource.java index 8a40472d..3b431a95 100644 --- a/docs-web/src/main/java/com/sismics/docs/rest/resource/AuditLogResource.java +++ b/docs-web/src/main/java/com/sismics/docs/rest/resource/AuditLogResource.java @@ -45,7 +45,7 @@ public class AuditLogResource extends BaseResource { } // On a document or a user? - PaginatedList paginatedList = PaginatedLists.create(100, 0); + PaginatedList paginatedList = PaginatedLists.create(20, 0); SortCriteria sortCriteria = new SortCriteria(1, true); AuditLogCriteria criteria = new AuditLogCriteria(); if (documentId == null) { diff --git a/docs-web/src/main/java/com/sismics/docs/rest/resource/FileResource.java b/docs-web/src/main/java/com/sismics/docs/rest/resource/FileResource.java index 4f909015..f86383f4 100644 --- a/docs-web/src/main/java/com/sismics/docs/rest/resource/FileResource.java +++ b/docs-web/src/main/java/com/sismics/docs/rest/resource/FileResource.java @@ -57,6 +57,7 @@ import com.sismics.rest.exception.ServerException; import com.sismics.rest.util.ValidationUtil; import com.sismics.util.mime.MimeType; import com.sismics.util.mime.MimeTypeUtil; +import com.sun.jersey.api.client.ClientResponse.Status; import com.sun.jersey.multipart.FormDataBodyPart; import com.sun.jersey.multipart.FormDataParam; @@ -417,7 +418,7 @@ public class FileResource extends BaseResource { } } } catch (NoResultException e) { - throw new ClientException("FileNotFound", MessageFormat.format("File not found: {0}", fileId)); + return Response.status(Status.NOT_FOUND).build(); } @@ -461,7 +462,7 @@ public class FileResource extends BaseResource { } }; } catch (Exception e) { - throw new ServerException("FileError", "Error while reading the file", e); + return Response.status(Status.SERVICE_UNAVAILABLE).build(); } return Response.ok(stream) diff --git a/docs-web/src/main/webapp/src/app/docs/controller/DocumentView.js b/docs-web/src/main/webapp/src/app/docs/controller/DocumentView.js index 3bd93077..fe80252a 100644 --- a/docs-web/src/main/webapp/src/app/docs/controller/DocumentView.js +++ b/docs-web/src/main/webapp/src/app/docs/controller/DocumentView.js @@ -4,11 +4,18 @@ * Document view controller. */ angular.module('docs').controller('DocumentView', function ($scope, $state, $stateParams, $location, $dialog, $modal, Restangular, $upload, $q) { - // Load data from server + // Load document data from server Restangular.one('document', $stateParams.id).get().then(function(data) { $scope.document = data; }); + // Load audit log data from server + Restangular.one('auditlog').get({ + document: $stateParams.id + }).then(function(data) { + $scope.logs = data.logs; + }); + // Watch for ACLs change and group them for easy displaying $scope.$watch('document.acls', function(acls) { $scope.acls = _.groupBy(acls, function(acl) { diff --git a/docs-web/src/main/webapp/src/app/docs/directive/AuditLog.js b/docs-web/src/main/webapp/src/app/docs/directive/AuditLog.js new file mode 100644 index 00000000..42d8b391 --- /dev/null +++ b/docs-web/src/main/webapp/src/app/docs/directive/AuditLog.js @@ -0,0 +1,15 @@ +'use strict'; + +/** + * Audit log directive. + */ +angular.module('docs').directive('auditLog', function() { + return { + restrict: 'E', + templateUrl: 'partial/docs/directive.auditlog.html', + replace: true, + scope: { + logs: '=' + } + } +}); \ No newline at end of file diff --git a/docs-web/src/main/webapp/src/index.html b/docs-web/src/main/webapp/src/index.html index 8fee9ee4..ce5a6e97 100644 --- a/docs-web/src/main/webapp/src/index.html +++ b/docs-web/src/main/webapp/src/index.html @@ -62,6 +62,7 @@ + diff --git a/docs-web/src/main/webapp/src/partial/docs/directive.auditlog.html b/docs-web/src/main/webapp/src/partial/docs/directive.auditlog.html new file mode 100644 index 00000000..e15252b2 --- /dev/null +++ b/docs-web/src/main/webapp/src/partial/docs/directive.auditlog.html @@ -0,0 +1,32 @@ + + + + + +
{{ log.create_date | date: 'yyyy-MM-dd HH:mm' }} + {{ log.class }} + + created + updated + deleted + + + + : + + {{ log.message }} + + + Open + + + {{ log.message }} + + + {{ log.message }} + + + {{ log.message }} + + +
\ No newline at end of file diff --git a/docs-web/src/main/webapp/src/partial/docs/document.default.html b/docs-web/src/main/webapp/src/partial/docs/document.default.html index ba3b8790..23598581 100644 --- a/docs-web/src/main/webapp/src/partial/docs/document.default.html +++ b/docs-web/src/main/webapp/src/partial/docs/document.default.html @@ -1,61 +1,58 @@
-
-
-
- - - -
-
- +
+

Quick upload

+
+
+
+ + + +
+
+ +
+
+ +
+
-
- +
+ +
+

+ {{ file.status }} +

+
+
-
-
-

- {{ file.status }} -

-
- -
-
+

+ + Drag & drop files here to upload +

-

- - Drag & drop files here to upload -

-
- -
- +
+ +
- - - - - - - - - -
DateMessage
{{ log.create_date | date: 'yyyy-MM-dd HH:mm' }}{{ log.class }} {{ log.type }} {{ log.message }}
+
+

Latest activity

+ +
-
-
    -
  • Version: {{ app.current_version }}
  • -
  • Memory: {{ app.free_memory / 1000000 | number: 0 }}/{{ app.total_memory / 1000000 | number: 0 }} MB
  • -
-
+
+
    +
  • Version: {{ app.current_version }}
  • +
  • Memory: {{ app.free_memory / 1000000 | number: 0 }}/{{ app.total_memory / 1000000 | number: 0 }} MB
  • +
+
\ No newline at end of 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 1560225c..43988090 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 @@ -135,6 +135,14 @@
+ + + + Activity + + + +
diff --git a/docs-web/src/test/java/com/sismics/docs/rest/TestFileResource.java b/docs-web/src/test/java/com/sismics/docs/rest/TestFileResource.java index c29dfec5..dc66674d 100644 --- a/docs-web/src/test/java/com/sismics/docs/rest/TestFileResource.java +++ b/docs-web/src/test/java/com/sismics/docs/rest/TestFileResource.java @@ -178,6 +178,12 @@ public class TestFileResource extends BaseJerseyTest { json = response.getEntity(JSONObject.class); Assert.assertEquals("ok", json.getString("status")); + // Get the file data (not found) + fileResource = resource().path("/file/" + file1Id + "/data"); + fileResource.addFilter(new CookieAuthenticationFilter(file1AuthenticationToken)); + response = fileResource.get(ClientResponse.class); + Assert.assertEquals(Status.NOT_FOUND, Status.fromStatusCode(response.getStatus())); + // Check that files are deleted from FS storedFile = Paths.get(DirectoryUtil.getStorageDirectory().getPath(), file1Id).toFile(); java.io.File webFile = Paths.get(DirectoryUtil.getStorageDirectory().getPath(), file1Id + "_web").toFile();