Commit 70854840 authored by Matija Obreza's avatar Matija Obreza

Admin tools: Fix ACL for repository folders, files, galleries

parent 130d63f2
......@@ -27,6 +27,9 @@ import org.genesys.catalog.persistence.dataset.DatasetRepository;
import org.genesys.catalog.service.DatasetService;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.model.RepositoryFolder;
import org.genesys.filerepository.persistence.ImageGalleryPersistence;
import org.genesys.filerepository.persistence.RepositoryFilePersistence;
import org.genesys.filerepository.persistence.RepositoryFolderRepository;
import org.genesys.filerepository.service.ImageGalleryService;
import org.genesys.filerepository.service.RepositoryService;
import org.genesys2.server.api.ApiBaseController;
......@@ -39,6 +42,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -141,8 +145,9 @@ public class AdminController {
}
@PostMapping(value = "/institutes-acl")
public void aclMakeInstitutesPublic() throws Exception {
@PostMapping(value = "/acl", params = { "institutes" })
@Transactional
public void aclFixInstitutesAcl() throws Exception {
LOG.warn("Adding ACL for FaoInstitutes");
instituteRepository.findAll().forEach(institute -> {
......@@ -152,4 +157,34 @@ public class AdminController {
LOG.warn("Added ACL to existing FaoInstitutes");
}
@Autowired
private RepositoryFolderRepository folderRepository;
@Autowired
private RepositoryFilePersistence fileRepository;
@Autowired
private ImageGalleryPersistence imageGalleryRepository;
@PostMapping(value = "/acl", params = { "repository" })
@Transactional
public void aclFixRepositoryAcl() throws Exception {
LOG.warn("Adding ACL for Repository folders");
folderRepository.findAll().forEach(folder -> {
aclService.createOrUpdatePermissions(folder);
});
LOG.warn("Adding ACL for Repository files");
fileRepository.findAll().forEach(file -> {
aclService.createOrUpdatePermissions(file);
});
LOG.warn("Adding ACL for Image galleries");
imageGalleryRepository.findAll().forEach(gallery -> {
aclService.createOrUpdatePermissions(gallery);
});
}
}
......@@ -37,6 +37,9 @@ import org.genesys.catalog.persistence.dataset.DatasetRepository;
import org.genesys.catalog.service.DatasetService;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.model.RepositoryFolder;
import org.genesys.filerepository.persistence.ImageGalleryPersistence;
import org.genesys.filerepository.persistence.RepositoryFilePersistence;
import org.genesys.filerepository.persistence.RepositoryFolderRepository;
import org.genesys.filerepository.service.ImageGalleryService;
import org.genesys.filerepository.service.RepositoryService;
import org.genesys.worldclim.WorldClimUtil;
......@@ -74,6 +77,7 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -499,8 +503,8 @@ public class AdminController {
return "redirect:/admin/";
}
@PostMapping(value = "/institutes-acl")
public void aclMakeInstitutesPublic() throws Exception {
@PostMapping(value = "/acl", params = { "institutes" })
public String aclMakeInstitutesPublic() throws Exception {
LOG.warn("Adding ACL for FaoInstitutes");
instituteRepository.findAll().forEach(institute -> {
......@@ -509,5 +513,37 @@ public class AdminController {
});
LOG.warn("Added ACL to existing FaoInstitutes");
return "redirect:/admin/";
}
@Autowired
private RepositoryFolderRepository folderRepository;
@Autowired
private RepositoryFilePersistence fileRepository;
@Autowired
private ImageGalleryPersistence imageGalleryRepository;
@PostMapping(value = "/acl", params = { "repository" })
@Transactional
public String aclFixRepositoryAcl() throws Exception {
LOG.warn("Adding ACL for Repository folders");
folderRepository.findAll().forEach(folder -> {
aclService.createOrUpdatePermissions(folder);
});
LOG.warn("Adding ACL for Repository files");
fileRepository.findAll().forEach(file -> {
aclService.createOrUpdatePermissions(file);
});
LOG.warn("Adding ACL for Image galleries");
imageGalleryRepository.findAll().forEach(gallery -> {
aclService.createOrUpdatePermissions(gallery);
});
return "redirect:/admin/";
}
}
......@@ -189,8 +189,9 @@
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
</form>
<form method="post" action="<c:url value="/admin/institutes-acl" />">
<input type="submit" class="btn btn-default" class="btn btn-default" value="Make FaoInstitutes ACL" />
<form method="post" action="<c:url value="/admin/acl" />">
<button type="submit" class="btn btn-default" class="btn btn-default" name="institutes" value="fix">Fix FaoInstitutes ACL</button>
<button type="submit" class="btn btn-default" class="btn btn-default" name="repository" value="Fix">Repository ACL</button>
<!-- CSRF protection -->
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
</form>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment