diff --git a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/DocumentDao.java b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/DocumentDao.java index aab9bdbe..95c9b579 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/DocumentDao.java +++ b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/DocumentDao.java @@ -207,7 +207,7 @@ public class DocumentDao { Map parameterMap = new HashMap(); List criteriaList = new ArrayList(); - StringBuilder sb = new StringBuilder("select d.DOC_ID_C c0, d.DOC_TITLE_C c1, d.DOC_DESCRIPTION_C c2, d.DOC_CREATEDATE_D c3, d.DOC_LANGUAGE_C c4, "); + StringBuilder sb = new StringBuilder("select distinct d.DOC_ID_C c0, d.DOC_TITLE_C c1, d.DOC_DESCRIPTION_C c2, d.DOC_CREATEDATE_D c3, d.DOC_LANGUAGE_C c4, "); sb.append(" (select count(s.SHA_ID_C) from T_SHARE s, T_ACL ac where ac.ACL_SOURCEID_C = d.DOC_ID_C and ac.ACL_TARGETID_C = s.SHA_ID_C and ac.ACL_DELETEDATE_D is null and s.SHA_DELETEDATE_D is null) c5, "); sb.append(" (select count(f.FIL_ID_C) from T_FILE f where f.FIL_DELETEDATE_D is null and f.FIL_IDDOC_C = d.DOC_ID_C) c6 "); sb.append(" from T_DOCUMENT d "); diff --git a/docs-web/src/main/webapp/src/app/docs/controller/DocumentViewPermissions.js b/docs-web/src/main/webapp/src/app/docs/controller/DocumentViewPermissions.js index b1e2d022..80231f2f 100644 --- a/docs-web/src/main/webapp/src/app/docs/controller/DocumentViewPermissions.js +++ b/docs-web/src/main/webapp/src/app/docs/controller/DocumentViewPermissions.js @@ -35,18 +35,21 @@ angular.module('docs').controller('DocumentViewPermissions', function ($scope, $ if ($scope.acl.perm == 'READWRITE') { acls = [{ source: $stateParams.id, - username: $scope.acl.username, - perm: 'READ' + target: $scope.acl.target.name, + perm: 'READ', + type: $scope.acl.target.type }, { source: $stateParams.id, - username: $scope.acl.username, - perm: 'WRITE' + target: $scope.acl.target.name, + perm: 'WRITE', + type: $scope.acl.target.type }]; } else { acls = [{ source: $stateParams.id, - username: $scope.acl.username, - perm: $scope.acl.perm + target: $scope.acl.target.name, + perm: $scope.acl.perm, + type: $scope.acl.target.type }]; } @@ -74,7 +77,20 @@ angular.module('docs').controller('DocumentViewPermissions', function ($scope, $ .get({ search: $viewValue }).then(function(data) { - deferred.resolve(_.pluck(data.users, 'name'), true); + var output = []; + + // Add the type to use later + output.push.apply(output, _.map(data.users, function(user) { + user.type = 'USER'; + return user; + })); + output.push.apply(output, _.map(data.groups, function(group) { + group.type = 'GROUP'; + return group; + })); + + // Send the data to the typeahead directive + deferred.resolve(output, true); }); return deferred.promise; }; diff --git a/docs-web/src/main/webapp/src/app/docs/directive/Acl.js b/docs-web/src/main/webapp/src/app/docs/directive/Acl.js new file mode 100644 index 00000000..ca1efbcc --- /dev/null +++ b/docs-web/src/main/webapp/src/app/docs/directive/Acl.js @@ -0,0 +1,15 @@ +'use strict'; + +/** + * ACL directive. + */ +angular.module('docs').directive('acl', function() { + return { + restrict: 'E', + template: '{{ data.type == \'SHARE\' ? \'Shared\' : (data.type == \'USER\' ? \'User\' : \'Group\') }} {{ data.name }}', + replace: true, + scope: { + data: '=' + } + } +}); \ 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 8edaaecf..c9623ec0 100644 --- a/docs-web/src/main/webapp/src/index.html +++ b/docs-web/src/main/webapp/src/index.html @@ -74,6 +74,7 @@ + diff --git a/docs-web/src/main/webapp/src/partial/docs/directive.typeahead.acl.html b/docs-web/src/main/webapp/src/partial/docs/directive.typeahead.acl.html new file mode 100644 index 00000000..4ad77ef5 --- /dev/null +++ b/docs-web/src/main/webapp/src/partial/docs/directive.typeahead.acl.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docs-web/src/main/webapp/src/partial/docs/document.view.permissions.html b/docs-web/src/main/webapp/src/partial/docs/document.view.permissions.html index cd1640bb..07160373 100644 --- a/docs-web/src/main/webapp/src/partial/docs/document.view.permissions.html +++ b/docs-web/src/main/webapp/src/partial/docs/document.view.permissions.html @@ -5,7 +5,7 @@ - {{ acl[0].type == 'SHARE' ? 'Shared' : 'User' }} {{ acl[0].name }} + {{ a.perm }} @@ -22,13 +22,19 @@
- +
+
+ + + +
@@ -43,7 +49,7 @@
- diff --git a/docs-web/src/test/java/com/sismics/docs/rest/TestAclResource.java b/docs-web/src/test/java/com/sismics/docs/rest/TestAclResource.java index fce7cec4..1da249fe 100644 --- a/docs-web/src/test/java/com/sismics/docs/rest/TestAclResource.java +++ b/docs-web/src/test/java/com/sismics/docs/rest/TestAclResource.java @@ -109,6 +109,16 @@ public class TestAclResource extends BaseJerseyTest { .param("target", "aclGroup2") .param("type", "GROUP")), JsonObject.class); + // List all documents with acl2 + json = target().path("/document/list") + .queryParam("sort_column", 3) + .queryParam("asc", true) + .request() + .cookie(TokenBasedSecurityFilter.COOKIE_NAME, acl2Token) + .get(JsonObject.class); + JsonArray documents = json.getJsonArray("documents"); + Assert.assertEquals(1, documents.size()); + // Get the document as acl1 json = target().path("/document/" + document1Id).request() .cookie(TokenBasedSecurityFilter.COOKIE_NAME, acl1Token)