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; ...@@ -27,6 +27,9 @@ import org.genesys.catalog.persistence.dataset.DatasetRepository;
import org.genesys.catalog.service.DatasetService; import org.genesys.catalog.service.DatasetService;
import org.genesys.filerepository.model.ImageGallery; import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.model.RepositoryFolder; 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.ImageGalleryService;
import org.genesys.filerepository.service.RepositoryService; import org.genesys.filerepository.service.RepositoryService;
import org.genesys2.server.api.ApiBaseController; import org.genesys2.server.api.ApiBaseController;
...@@ -39,6 +42,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -39,6 +42,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.security.access.prepost.PreAuthorize; 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.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
...@@ -141,8 +145,9 @@ public class AdminController { ...@@ -141,8 +145,9 @@ public class AdminController {
} }
@PostMapping(value = "/institutes-acl") @PostMapping(value = "/acl", params = { "institutes" })
public void aclMakeInstitutesPublic() throws Exception { @Transactional
public void aclFixInstitutesAcl() throws Exception {
LOG.warn("Adding ACL for FaoInstitutes"); LOG.warn("Adding ACL for FaoInstitutes");
instituteRepository.findAll().forEach(institute -> { instituteRepository.findAll().forEach(institute -> {
...@@ -152,4 +157,34 @@ public class AdminController { ...@@ -152,4 +157,34 @@ public class AdminController {
LOG.warn("Added ACL to existing FaoInstitutes"); 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; ...@@ -37,6 +37,9 @@ import org.genesys.catalog.persistence.dataset.DatasetRepository;
import org.genesys.catalog.service.DatasetService; import org.genesys.catalog.service.DatasetService;
import org.genesys.filerepository.model.ImageGallery; import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.model.RepositoryFolder; 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.ImageGalleryService;
import org.genesys.filerepository.service.RepositoryService; import org.genesys.filerepository.service.RepositoryService;
import org.genesys.worldclim.WorldClimUtil; import org.genesys.worldclim.WorldClimUtil;
...@@ -74,6 +77,7 @@ import org.springframework.data.domain.Page; ...@@ -74,6 +77,7 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -499,8 +503,8 @@ public class AdminController { ...@@ -499,8 +503,8 @@ public class AdminController {
return "redirect:/admin/"; return "redirect:/admin/";
} }
@PostMapping(value = "/institutes-acl") @PostMapping(value = "/acl", params = { "institutes" })
public void aclMakeInstitutesPublic() throws Exception { public String aclMakeInstitutesPublic() throws Exception {
LOG.warn("Adding ACL for FaoInstitutes"); LOG.warn("Adding ACL for FaoInstitutes");
instituteRepository.findAll().forEach(institute -> { instituteRepository.findAll().forEach(institute -> {
...@@ -509,5 +513,37 @@ public class AdminController { ...@@ -509,5 +513,37 @@ public class AdminController {
}); });
LOG.warn("Added ACL to existing FaoInstitutes"); 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 @@ ...@@ -189,8 +189,9 @@
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" /> <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
</form> </form>
<form method="post" action="<c:url value="/admin/institutes-acl" />"> <form method="post" action="<c:url value="/admin/acl" />">
<input type="submit" class="btn btn-default" class="btn btn-default" value="Make FaoInstitutes 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 --> <!-- CSRF protection -->
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" /> <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
</form> </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