Merge pull request #95 from sismics/master

Fix batch for ACLs on tags
This commit is contained in:
Benjamin Gamard 2016-05-08 23:21:36 +02:00
commit f2c4dde56e

View File

@ -335,28 +335,32 @@ public class AppResource extends BaseResource {
// Get all tags // Get all tags
TagDao tagDao = new TagDao(); TagDao tagDao = new TagDao();
UserDao userDao = new UserDao();
List<TagDto> tagDtoList = tagDao.findByCriteria(new TagCriteria(), null); List<TagDto> tagDtoList = tagDao.findByCriteria(new TagCriteria(), null);
// Add READ and WRITE ACLs // Add READ and WRITE ACLs
for (TagDto tagDto : tagDtoList) { for (TagDto tagDto : tagDtoList) {
// Remove old ACLs
AclDao aclDao = new AclDao(); AclDao aclDao = new AclDao();
List<AclDto> aclDtoList = aclDao.getBySourceId(tagDto.getId()); List<AclDto> aclDtoList = aclDao.getBySourceId(tagDto.getId());
String userId = userDao.getActiveByUsername(tagDto.getCreator()).getId();
if (aclDtoList.size() == 0) { for (AclDto aclDto : aclDtoList) {
// Create read ACL aclDao.delete(aclDto.getSourceId(), aclDto.getPerm(), aclDto.getTargetId(), userId);
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());
} }
// 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 // Always return OK