From 6e6f892cb00cfbebf2cd28ce2bf0ed1222173939 Mon Sep 17 00:00:00 2001 From: Benjamin Gamard Date: Thu, 1 Feb 2018 18:26:33 +0100 Subject: [PATCH] fix --- .../com/sismics/docs/core/dao/jpa/AclDao.java | 51 ++++++++++--------- .../docs/rest/resource/ShareResource.java | 2 + 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/AclDao.java b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/AclDao.java index 8d32d2e9..48d66c02 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/AclDao.java +++ b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/AclDao.java @@ -1,6 +1,7 @@ package com.sismics.docs.core.dao.jpa; import com.sismics.docs.core.constant.AclTargetType; +import com.sismics.docs.core.constant.AclType; import com.sismics.docs.core.constant.AuditLogType; import com.sismics.docs.core.constant.PermType; import com.sismics.docs.core.dao.jpa.dto.AclDto; @@ -17,13 +18,13 @@ import java.util.UUID; /** * ACL DAO. - * + * * @author bgamard */ public class AclDao { /** * Creates a new ACL. - * + * * @param acl ACL * @param userId User ID * @return New ID @@ -31,20 +32,20 @@ public class AclDao { public String create(Acl acl, String userId) { // Create the UUID acl.setId(UUID.randomUUID().toString()); - + // Create the ACL EntityManager em = ThreadLocalContext.get().getEntityManager(); em.persist(acl); - + // Create audit log AuditLogUtil.create(acl, AuditLogType.CREATE, userId); - + return acl.getId(); } - + /** * Search ACLs by target ID. - * + * * @param targetId Target ID * @return ACL list */ @@ -56,15 +57,15 @@ public class AclDao { return q.getResultList(); } - + /** * Search ACLs by source ID. - * + * * @param sourceId Source ID * @return ACL DTO list - */ + */ @SuppressWarnings("unchecked") - public List getBySourceId(String sourceId) { + public List getBySourceId(String sourceId, AclType type) { EntityManager em = ThreadLocalContext.get().getEntityManager(); StringBuilder sb = new StringBuilder("select a.ACL_ID_C, a.ACL_PERM_C, a.ACL_TARGETID_C, "); sb.append(" u.USE_USERNAME_C, s.SHA_ID_C, s.SHA_NAME_C, g.GRP_NAME_C "); @@ -72,13 +73,14 @@ public class AclDao { sb.append(" left join T_USER u on u.USE_ID_C = a.ACL_TARGETID_C "); sb.append(" left join T_SHARE s on s.SHA_ID_C = a.ACL_TARGETID_C "); sb.append(" left join T_GROUP g on g.GRP_ID_C = a.ACL_TARGETID_C "); - sb.append(" where a.ACL_DELETEDATE_D is null and a.ACL_SOURCEID_C = :sourceId "); - + sb.append(" where a.ACL_DELETEDATE_D is null and a.ACL_SOURCEID_C = :sourceId and a.ACL_TYPE_C = :type "); + // Perform the query Query q = em.createNativeQuery(sb.toString()); q.setParameter("sourceId", sourceId); + q.setParameter("type", type.name()); List l = q.getResultList(); - + // Assemble results List aclDtoList = new ArrayList<>(); for (Object[] o : l) { @@ -107,10 +109,10 @@ public class AclDao { } return aclDtoList; } - + /** * Check if a source is accessible to a target. - * + * * @param sourceId ACL source entity ID * @param perm Necessary permission * @param targetIdList List of targets @@ -135,32 +137,35 @@ public class AclDao { /** * Delete an ACL. - * + * * @param sourceId Source ID * @param perm Permission * @param targetId Target ID * @param userId User ID + * @param type Type */ @SuppressWarnings("unchecked") - public void delete(String sourceId, PermType perm, String targetId, String userId) { + public void delete(String sourceId, PermType perm, String targetId, String userId, AclType type) { EntityManager em = ThreadLocalContext.get().getEntityManager(); - + // Create audit log - Query q = em.createQuery("from Acl a where a.sourceId = :sourceId and a.perm = :perm and a.targetId = :targetId"); + Query q = em.createQuery("from Acl a where a.sourceId = :sourceId and a.perm = :perm and a.targetId = :targetId and a.type = :type"); q.setParameter("sourceId", sourceId); q.setParameter("perm", perm); q.setParameter("targetId", targetId); + q.setParameter("type", type); List aclList = q.getResultList(); for (Acl acl : aclList) { AuditLogUtil.create(acl, AuditLogType.DELETE, userId); } - + // Soft delete the ACLs - q = em.createQuery("update Acl a set a.deleteDate = :dateNow where a.sourceId = :sourceId and a.perm = :perm and a.targetId = :targetId"); + q = em.createQuery("update Acl a set a.deleteDate = :dateNow where a.sourceId = :sourceId and a.perm = :perm and a.targetId = :targetId and a.type = :type"); q.setParameter("sourceId", sourceId); q.setParameter("perm", perm); q.setParameter("targetId", targetId); + q.setParameter("type", type); q.setParameter("dateNow", new Date()); q.executeUpdate(); } -} +} \ No newline at end of file diff --git a/docs-web/src/main/java/com/sismics/docs/rest/resource/ShareResource.java b/docs-web/src/main/java/com/sismics/docs/rest/resource/ShareResource.java index f52c6968..ea38e25d 100644 --- a/docs-web/src/main/java/com/sismics/docs/rest/resource/ShareResource.java +++ b/docs-web/src/main/java/com/sismics/docs/rest/resource/ShareResource.java @@ -2,6 +2,7 @@ package com.sismics.docs.rest.resource; import com.sismics.docs.core.constant.AclTargetType; +import com.sismics.docs.core.constant.AclType; import com.sismics.docs.core.constant.PermType; import com.sismics.docs.core.dao.jpa.AclDao; import com.sismics.docs.core.dao.jpa.ShareDao; @@ -76,6 +77,7 @@ public class ShareResource extends BaseResource { Acl acl = new Acl(); acl.setSourceId(documentId); acl.setPerm(PermType.READ); + acl.setType(AclType.USER); acl.setTargetId(share.getId()); aclDao.create(acl, principal.getId());