diff --git a/docs-core/pom.xml b/docs-core/pom.xml index 3c1730c1..498aee4b 100644 --- a/docs-core/pom.xml +++ b/docs-core/pom.xml @@ -5,7 +5,7 @@ com.sismics.docs docs-parent - 1.0-SNAPSHOT + 1.4-SNAPSHOT .. diff --git a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/TagDao.java b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/TagDao.java index a00ee16a..c9a74f01 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/TagDao.java +++ b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/TagDao.java @@ -1,6 +1,12 @@ package com.sismics.docs.core.dao.jpa; -import java.util.*; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; import javax.persistence.EntityManager; import javax.persistence.NoResultException; @@ -8,11 +14,8 @@ import javax.persistence.Query; import com.google.common.base.Joiner; import com.sismics.docs.core.constant.AuditLogType; -import com.sismics.docs.core.dao.jpa.criteria.GroupCriteria; import com.sismics.docs.core.dao.jpa.criteria.TagCriteria; -import com.sismics.docs.core.dao.jpa.dto.GroupDto; import com.sismics.docs.core.dao.jpa.dto.TagDto; -import com.sismics.docs.core.dao.jpa.dto.TagStatDto; import com.sismics.docs.core.model.jpa.DocumentTag; import com.sismics.docs.core.model.jpa.Tag; import com.sismics.docs.core.util.AuditLogUtil; diff --git a/docs-core/src/main/java/com/sismics/util/jpa/DbOpenHelper.java b/docs-core/src/main/java/com/sismics/util/jpa/DbOpenHelper.java index dac8b80c..fcc4f3f2 100644 --- a/docs-core/src/main/java/com/sismics/util/jpa/DbOpenHelper.java +++ b/docs-core/src/main/java/com/sismics/util/jpa/DbOpenHelper.java @@ -5,7 +5,6 @@ import java.io.FilenameFilter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.io.Writer; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; diff --git a/docs-core/src/test/java/com/sismics/docs/core/util/TestFileUtil.java b/docs-core/src/test/java/com/sismics/docs/core/util/TestFileUtil.java index 8ce18dc4..4f7a58d9 100644 --- a/docs-core/src/test/java/com/sismics/docs/core/util/TestFileUtil.java +++ b/docs-core/src/test/java/com/sismics/docs/core/util/TestFileUtil.java @@ -9,7 +9,6 @@ import org.junit.Assert; import org.junit.Test; import com.google.common.collect.Lists; -import com.google.common.io.ByteStreams; import com.google.common.io.Resources; import com.sismics.docs.core.dao.jpa.dto.DocumentDto; import com.sismics.docs.core.model.jpa.File; diff --git a/docs-stress/pom.xml b/docs-stress/pom.xml index 6c917af7..e6cb862b 100644 --- a/docs-stress/pom.xml +++ b/docs-stress/pom.xml @@ -5,7 +5,7 @@ com.sismics.docs docs-parent - 1.0-SNAPSHOT + 1.4-SNAPSHOT .. diff --git a/docs-web-common/pom.xml b/docs-web-common/pom.xml index 427999c7..1a736939 100644 --- a/docs-web-common/pom.xml +++ b/docs-web-common/pom.xml @@ -5,7 +5,7 @@ com.sismics.docs docs-parent - 1.0-SNAPSHOT + 1.4-SNAPSHOT .. diff --git a/docs-web-common/src/test/java/com/sismics/docs/rest/util/ClientUtil.java b/docs-web-common/src/test/java/com/sismics/docs/rest/util/ClientUtil.java index 968f9adb..db201e34 100644 --- a/docs-web-common/src/test/java/com/sismics/docs/rest/util/ClientUtil.java +++ b/docs-web-common/src/test/java/com/sismics/docs/rest/util/ClientUtil.java @@ -69,7 +69,7 @@ public class ClientUtil { * Creates a group. * * @param name Name - * @param parent Parent + * @param parentId Parent ID */ public void createGroup(String name, String parentId) { // Login admin to create the group diff --git a/docs-web/pom.xml b/docs-web/pom.xml index e4f2420a..a3cba6c6 100644 --- a/docs-web/pom.xml +++ b/docs-web/pom.xml @@ -5,7 +5,7 @@ com.sismics.docs docs-parent - 1.0-SNAPSHOT + 1.4-SNAPSHOT .. diff --git a/docs-web/src/main/java/com/sismics/docs/rest/resource/AppResource.java b/docs-web/src/main/java/com/sismics/docs/rest/resource/AppResource.java index 6e96ad94..b5426eb2 100644 --- a/docs-web/src/main/java/com/sismics/docs/rest/resource/AppResource.java +++ b/docs-web/src/main/java/com/sismics/docs/rest/resource/AppResource.java @@ -209,7 +209,8 @@ public class AppResource extends BaseResource { sb.append(" left join T_FILE f on f.FIL_ID_C = al.LOG_IDENTITY_C and f.FIL_DELETEDATE_D is null "); sb.append(" left join T_TAG t on t.TAG_ID_C = al.LOG_IDENTITY_C and t.TAG_DELETEDATE_D is null "); sb.append(" left join T_USER u on u.USE_ID_C = al.LOG_IDENTITY_C and u.USE_DELETEDATE_D is null "); - sb.append(" where d.DOC_ID_C is null and a.ACL_ID_C is null and c.COM_ID_C is null and f.FIL_ID_C is null and t.TAG_ID_C is null and u.USE_ID_C is null)"); + sb.append(" left join T_GROUP g on g.GRP_ID_C = al.LOG_IDENTITY_C and g.GRP_DELETEDATE_D is null "); + sb.append(" where d.DOC_ID_C is null and a.ACL_ID_C is null and c.COM_ID_C is null and f.FIL_ID_C is null and t.TAG_ID_C is null and u.USE_ID_C is null and g.GRP_ID_C is null)"); Query q = em.createNativeQuery(sb.toString()); log.info("Deleting {} orphan audit logs", q.executeUpdate()); @@ -217,8 +218,10 @@ public class AppResource extends BaseResource { sb = new StringBuilder("update T_ACL a set ACL_DELETEDATE_D = :dateNow where a.ACL_ID_C in (select a.ACL_ID_C from T_ACL a "); sb.append(" left join T_SHARE s on s.SHA_ID_C = a.ACL_TARGETID_C "); sb.append(" left join T_USER u on u.USE_ID_C = a.ACL_TARGETID_C "); + sb.append(" left join T_GROUP g on g.GRP_ID_C = a.ACL_TARGETID_C "); sb.append(" left join T_DOCUMENT d on d.DOC_ID_C = a.ACL_SOURCEID_C "); - sb.append(" where s.SHA_ID_C is null and u.USE_ID_C is null or d.DOC_ID_C is null)"); + sb.append(" left join T_TAG t on t.TAG_ID_C = a.ACL_SOURCEID_C "); + sb.append(" where s.SHA_ID_C is null and u.USE_ID_C is null and g.GRP_ID_C is null or d.DOC_ID_C is null and t.TAG_ID_C is null)"); q = em.createNativeQuery(sb.toString()); q.setParameter("dateNow", new Date()); log.info("Deleting {} orphan ACLs", q.executeUpdate()); @@ -262,6 +265,7 @@ public class AppResource extends BaseResource { log.info("Deleting {} soft deleted files", em.createQuery("delete File f where f.deleteDate is not null").executeUpdate()); log.info("Deleting {} soft deleted documents", em.createQuery("delete Document d where d.deleteDate is not null").executeUpdate()); log.info("Deleting {} soft deleted users", em.createQuery("delete User u where u.deleteDate is not null").executeUpdate()); + log.info("Deleting {} soft deleted groups", em.createQuery("delete Group g where g.deleteDate is not null").executeUpdate()); // Always return OK JsonObjectBuilder response = Json.createObjectBuilder() @@ -344,23 +348,22 @@ public class AppResource extends BaseResource { AclDao aclDao = new AclDao(); List aclDtoList = aclDao.getBySourceId(tagDto.getId()); String userId = userDao.getActiveByUsername(tagDto.getCreator()).getId(); - for (AclDto aclDto : aclDtoList) { - aclDao.delete(aclDto.getSourceId(), aclDto.getPerm(), aclDto.getTargetId(), userId); + + if (aclDtoList.size() == 0) { + // Create read ACL + Acl acl = new Acl(); + acl.setPerm(PermType.READ); + acl.setSourceId(tagDto.getId()); + acl.setTargetId(userId); + aclDao.create(acl, userId); + + // Create write ACL + acl = new Acl(); + acl.setPerm(PermType.WRITE); + acl.setSourceId(tagDto.getId()); + acl.setTargetId(userId); + aclDao.create(acl, userId); } - - // Create read ACL - Acl acl = new Acl(); - acl.setPerm(PermType.READ); - acl.setSourceId(tagDto.getId()); - acl.setTargetId(userId); - aclDao.create(acl, userId); - - // Create write ACL - acl = new Acl(); - acl.setPerm(PermType.WRITE); - acl.setSourceId(tagDto.getId()); - acl.setTargetId(userId); - aclDao.create(acl, userId); } // Always return OK diff --git a/docs-web/src/main/java/com/sismics/docs/rest/resource/ThemeResource.java b/docs-web/src/main/java/com/sismics/docs/rest/resource/ThemeResource.java index 82dc70d3..46032995 100644 --- a/docs-web/src/main/java/com/sismics/docs/rest/resource/ThemeResource.java +++ b/docs-web/src/main/java/com/sismics/docs/rest/resource/ThemeResource.java @@ -37,10 +37,6 @@ import java.util.Map; */ @Path("/theme") public class ThemeResource extends BaseResource { - // Filenames for images in theme directory - private static final String LOGO_IMAGE = "logo"; - private static final String BACKGROUND_IMAGE = "background"; - /** * Returns custom CSS stylesheet. * @@ -162,7 +158,7 @@ public class ThemeResource extends BaseResource { if (Files.exists(filePath)) { inputStream = Files.newInputStream(filePath); } else { - inputStream = getClass().getResource("/image/" + (type.equals(LOGO_IMAGE) ? "logo.png" : "background.jpg")).openStream(); + inputStream = getClass().getResource("/image/" + (type.equals("logo") ? "logo.png" : "background.jpg")).openStream(); } ByteStreams.copy(inputStream, outputStream); } finally { diff --git a/docs-web/src/main/webapp/src/app/docs/controller/document/DocumentViewPermissions.js b/docs-web/src/main/webapp/src/app/docs/controller/document/DocumentViewPermissions.js index 453605df..fe3a5b75 100644 --- a/docs-web/src/main/webapp/src/app/docs/controller/document/DocumentViewPermissions.js +++ b/docs-web/src/main/webapp/src/app/docs/controller/document/DocumentViewPermissions.js @@ -7,7 +7,7 @@ angular.module('docs').controller('DocumentViewPermissions', function($scope) { // Watch for ACLs change and group them for easy displaying $scope.$watch('document.inherited_acls', function(acls) { $scope.inheritedAcls = _.groupBy(acls, function(acl) { - return acl.source_id; + return acl.source_id + acl.id; }); }); }); \ No newline at end of file diff --git a/docs-web/src/main/webapp/src/app/docs/controller/tag/Tag.js b/docs-web/src/main/webapp/src/app/docs/controller/tag/Tag.js index c92f0e1b..33572c9f 100644 --- a/docs-web/src/main/webapp/src/app/docs/controller/tag/Tag.js +++ b/docs-web/src/main/webapp/src/app/docs/controller/tag/Tag.js @@ -3,13 +3,16 @@ /** * Tag controller. */ -angular.module('docs').controller('Tag', function($scope, $dialog, Restangular, $state) { +angular.module('docs').controller('Tag', function($scope, Restangular, $state) { $scope.tag = { name: '', color: '#3a87ad' }; // Retrieve tags - Restangular.one('tag/list').get().then(function(data) { - $scope.tags = data.tags; - }); + $scope.loadTags = function() { + Restangular.one('tag/list').get().then(function(data) { + $scope.tags = data.tags; + }); + }; + $scope.loadTags(); /** * Display a tag. @@ -27,26 +30,4 @@ angular.module('docs').controller('Tag', function($scope, $dialog, Restangular, $scope.tag = { name: '', color: '#3a87ad' }; }); }; - - /** - * Delete a tag. - */ - $scope.deleteTag = function(tag) { - var title = 'Delete tag'; - var msg = 'Do you really want to delete this tag?'; - var btns = [ - {result: 'cancel', label: 'Cancel'}, - {result: 'ok', label: 'OK', cssClass: 'btn-primary'} - ]; - - $dialog.messageBox(title, msg, btns, function(result) { - if (result == 'ok') { - Restangular.one('tag', tag.id).remove().then(function() { - $scope.tags = _.reject($scope.tags, function(t) { - return tag.id == t.id; - }); - }); - } - }); - }; }); \ No newline at end of file diff --git a/docs-web/src/main/webapp/src/app/docs/controller/tag/TagEdit.js b/docs-web/src/main/webapp/src/app/docs/controller/tag/TagEdit.js index 591de7b6..e77599da 100644 --- a/docs-web/src/main/webapp/src/app/docs/controller/tag/TagEdit.js +++ b/docs-web/src/main/webapp/src/app/docs/controller/tag/TagEdit.js @@ -3,7 +3,7 @@ /** * Tag edit controller. */ -angular.module('docs').controller('TagEdit', function($scope, $stateParams, Restangular) { +angular.module('docs').controller('TagEdit', function($scope, $stateParams, Restangular, $dialog, $state) { // Retrieve the tag Restangular.one('tag', $stateParams.id).get().then(function(data) { $scope.tag = data; @@ -23,4 +23,25 @@ angular.module('docs').controller('TagEdit', function($scope, $stateParams, Rest // Update the server Restangular.one('tag', $scope.tag.id).post('', $scope.tag); }; + + /** + * Delete a tag. + */ + $scope.deleteTag = function(tag) { + var title = 'Delete tag'; + var msg = 'Do you really want to delete this tag?'; + var btns = [ + {result: 'cancel', label: 'Cancel'}, + {result: 'ok', label: 'OK', cssClass: 'btn-primary'} + ]; + + $dialog.messageBox(title, msg, btns, function(result) { + if (result == 'ok') { + Restangular.one('tag', tag.id).remove().then(function() { + $scope.loadTags(); + $state.go('tag.default'); + }); + } + }); + }; }); \ 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 664eabd2..a6a7fb94 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 @@ -12,7 +12,7 @@
-
+
diff --git a/docs-web/src/main/webapp/src/partial/docs/tag.edit.html b/docs-web/src/main/webapp/src/partial/docs/tag.edit.html index 843a80a1..398470b6 100644 --- a/docs-web/src/main/webapp/src/partial/docs/tag.edit.html +++ b/docs-web/src/main/webapp/src/partial/docs/tag.edit.html @@ -1,6 +1,12 @@ -

{{ tag.name }} 

+
+ +
-
+ + +
@@ -29,7 +35,7 @@ + value="{{ tag0.id }}">{{ tag0.name }}
diff --git a/docs-web/src/main/webapp/src/partial/docs/tag.html b/docs-web/src/main/webapp/src/partial/docs/tag.html index 280daed3..8a915b26 100644 --- a/docs-web/src/main/webapp/src/partial/docs/tag.html +++ b/docs-web/src/main/webapp/src/partial/docs/tag.html @@ -29,11 +29,6 @@ - - - diff --git a/docs-web/src/test/java/com/sismics/docs/rest/TestTagResource.java b/docs-web/src/test/java/com/sismics/docs/rest/TestTagResource.java index c7d61e80..efd09d02 100644 --- a/docs-web/src/test/java/com/sismics/docs/rest/TestTagResource.java +++ b/docs-web/src/test/java/com/sismics/docs/rest/TestTagResource.java @@ -2,7 +2,6 @@ package com.sismics.docs.rest; import javax.json.JsonArray; import javax.json.JsonObject; -import javax.json.JsonValue; import javax.ws.rs.client.Entity; import javax.ws.rs.core.Form; import javax.ws.rs.core.Response; diff --git a/pom.xml b/pom.xml index 64c8b8e7..cbd0371d 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.sismics.docs docs-parent pom - 1.0-SNAPSHOT + 1.4-SNAPSHOT Docs Parent