From 6f89a50fe5eddeefaf681e5b6858310b4f5e323a Mon Sep 17 00:00:00 2001 From: jendib Date: Sun, 8 May 2016 23:20:58 +0200 Subject: [PATCH] Fix batch for ACLs on tags --- .../docs/rest/resource/AppResource.java | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) 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 80f8c02e..6e96ad94 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 @@ -335,28 +335,32 @@ public class AppResource extends BaseResource { // Get all tags TagDao tagDao = new TagDao(); + UserDao userDao = new UserDao(); List tagDtoList = tagDao.findByCriteria(new TagCriteria(), null); // Add READ and WRITE ACLs for (TagDto tagDto : tagDtoList) { + // Remove old ACLs AclDao aclDao = new AclDao(); List aclDtoList = aclDao.getBySourceId(tagDto.getId()); - - if (aclDtoList.size() == 0) { - // Create read ACL - Acl acl = new Acl(); - acl.setPerm(PermType.READ); - acl.setSourceId(tagDto.getId()); - acl.setTargetId(principal.getId()); - aclDao.create(acl, principal.getId()); - - // Create write ACL - acl = new Acl(); - acl.setPerm(PermType.WRITE); - acl.setSourceId(tagDto.getId()); - acl.setTargetId(principal.getId()); - aclDao.create(acl, principal.getId()); + String userId = userDao.getActiveByUsername(tagDto.getCreator()).getId(); + for (AclDto aclDto : aclDtoList) { + aclDao.delete(aclDto.getSourceId(), aclDto.getPerm(), aclDto.getTargetId(), 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