This commit is contained in:
Benjamin Gamard 2018-02-01 18:26:33 +01:00
parent 2b4ddfa072
commit 6e6f892cb0
2 changed files with 30 additions and 23 deletions

View File

@ -1,6 +1,7 @@
package com.sismics.docs.core.dao.jpa; package com.sismics.docs.core.dao.jpa;
import com.sismics.docs.core.constant.AclTargetType; 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.AuditLogType;
import com.sismics.docs.core.constant.PermType; import com.sismics.docs.core.constant.PermType;
import com.sismics.docs.core.dao.jpa.dto.AclDto; import com.sismics.docs.core.dao.jpa.dto.AclDto;
@ -64,7 +65,7 @@ public class AclDao {
* @return ACL DTO list * @return ACL DTO list
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public List<AclDto> getBySourceId(String sourceId) { public List<AclDto> getBySourceId(String sourceId, AclType type) {
EntityManager em = ThreadLocalContext.get().getEntityManager(); EntityManager em = ThreadLocalContext.get().getEntityManager();
StringBuilder sb = new StringBuilder("select a.ACL_ID_C, a.ACL_PERM_C, a.ACL_TARGETID_C, "); 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 "); sb.append(" u.USE_USERNAME_C, s.SHA_ID_C, s.SHA_NAME_C, g.GRP_NAME_C ");
@ -72,11 +73,12 @@ public class AclDao {
sb.append(" left join T_USER u on u.USE_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_SHARE s on s.SHA_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(" 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 // Perform the query
Query q = em.createNativeQuery(sb.toString()); Query q = em.createNativeQuery(sb.toString());
q.setParameter("sourceId", sourceId); q.setParameter("sourceId", sourceId);
q.setParameter("type", type.name());
List<Object[]> l = q.getResultList(); List<Object[]> l = q.getResultList();
// Assemble results // Assemble results
@ -140,26 +142,29 @@ public class AclDao {
* @param perm Permission * @param perm Permission
* @param targetId Target ID * @param targetId Target ID
* @param userId User ID * @param userId User ID
* @param type Type
*/ */
@SuppressWarnings("unchecked") @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(); EntityManager em = ThreadLocalContext.get().getEntityManager();
// Create audit log // 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("sourceId", sourceId);
q.setParameter("perm", perm); q.setParameter("perm", perm);
q.setParameter("targetId", targetId); q.setParameter("targetId", targetId);
q.setParameter("type", type);
List<Acl> aclList = q.getResultList(); List<Acl> aclList = q.getResultList();
for (Acl acl : aclList) { for (Acl acl : aclList) {
AuditLogUtil.create(acl, AuditLogType.DELETE, userId); AuditLogUtil.create(acl, AuditLogType.DELETE, userId);
} }
// Soft delete the ACLs // 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("sourceId", sourceId);
q.setParameter("perm", perm); q.setParameter("perm", perm);
q.setParameter("targetId", targetId); q.setParameter("targetId", targetId);
q.setParameter("type", type);
q.setParameter("dateNow", new Date()); q.setParameter("dateNow", new Date());
q.executeUpdate(); q.executeUpdate();
} }

View File

@ -2,6 +2,7 @@ package com.sismics.docs.rest.resource;
import com.sismics.docs.core.constant.AclTargetType; 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.constant.PermType;
import com.sismics.docs.core.dao.jpa.AclDao; import com.sismics.docs.core.dao.jpa.AclDao;
import com.sismics.docs.core.dao.jpa.ShareDao; import com.sismics.docs.core.dao.jpa.ShareDao;
@ -76,6 +77,7 @@ public class ShareResource extends BaseResource {
Acl acl = new Acl(); Acl acl = new Acl();
acl.setSourceId(documentId); acl.setSourceId(documentId);
acl.setPerm(PermType.READ); acl.setPerm(PermType.READ);
acl.setType(AclType.USER);
acl.setTargetId(share.getId()); acl.setTargetId(share.getId());
aclDao.create(acl, principal.getId()); aclDao.create(acl, principal.getId());