Commit 2a51923b authored by Matija Obreza's avatar Matija Obreza Committed by Viacheslav Pavlov

PGRFA Networks: cleanup

- API 404s when not found
- Fix: PGRFANetwork permission checks, PGRFANetwork is not AclAware, don't check ACL

fixed liquibase changelog
parent d38c96e5
......@@ -75,7 +75,6 @@ public class NetworkController extends ApiBaseController {
@PostMapping(value = "", produces = { MediaType.APPLICATION_JSON_VALUE })
public PGRFANetwork updateNetwork(@RequestBody PGRFANetwork organizationJson) {
PGRFANetwork network = networkService.getNetwork(organizationJson.getSlug());
if (network == null) {
return networkService.create(organizationJson.getSlug(), organizationJson.getTitle());
}
......@@ -103,6 +102,9 @@ public class NetworkController extends ApiBaseController {
@GetMapping(value = "/{shortName}/details", produces = { MediaType.APPLICATION_JSON_VALUE })
public NetworkDetails getNetworkDetails(@PathVariable("shortName") String shortName, @RequestParam(value = "language", defaultValue = "en") String language) {
PGRFANetwork network = networkService.getNetwork(shortName);
if (network == null) {
throw new NotFoundElement("Network not found");
}
Page<FaoInstitute> members = networkService.getInstitutes(network, new PageRequest(0, 50));
Article blurb = networkService.getBlurb(network, new Locale(language));
......@@ -116,8 +118,11 @@ public class NetworkController extends ApiBaseController {
*/
@GetMapping(value = "/{shortName}/blurb/{language}", produces = { MediaType.APPLICATION_JSON_VALUE })
public Article getBlurb(@PathVariable("shortName") String shortName, @PathVariable("language") String language) {
PGRFANetwork org = networkService.getNetwork(shortName);
return networkService.getBlurb(org, new Locale(language));
PGRFANetwork network = networkService.getNetwork(shortName);
if (network == null) {
throw new NotFoundElement("Network not found");
}
return networkService.getBlurb(network, new Locale(language));
}
/**
......@@ -126,8 +131,11 @@ public class NetworkController extends ApiBaseController {
*/
@PutMapping(value = "/{shortName}/blurb", produces = { MediaType.APPLICATION_JSON_VALUE })
public Article updateBlurb(@PathVariable("shortName") String shortName, @RequestBody Article blurb) throws CRMException {
PGRFANetwork org = networkService.getNetwork(shortName);
return networkService.updateAbout(org, blurb.getBody(), blurb.getSummary(), blurb.getLang() == null ? Locale.ENGLISH : new Locale(blurb.getLang()));
PGRFANetwork network = networkService.getNetwork(shortName);
if (network == null) {
throw new NotFoundElement("Network not found");
}
return networkService.updateAbout(network, blurb.getBody(), blurb.getSummary(), blurb.getLang() == null ? Locale.ENGLISH : new Locale(blurb.getLang()));
}
/**
......
......@@ -91,7 +91,7 @@ public class PGRFANetworkServiceImpl implements PGRFANetworkService {
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') || hasPermission(network, 'write')")
@PreAuthorize("hasRole('ADMINISTRATOR')")
@Transactional(readOnly = false)
public Article updateAbout(@Valid PGRFANetwork network, String body, String summary, Locale locale) throws CRMException {
return contentService.updateArticle(network, ContentService.ENTITY_BLURB_SLUG, null, body, summary, locale);
......@@ -110,7 +110,7 @@ public class PGRFANetworkServiceImpl implements PGRFANetworkService {
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') || hasPermission(network, 'write')")
@PreAuthorize("hasRole('ADMINISTRATOR')")
@Transactional(readOnly = false)
public PGRFANetwork update(@Valid PGRFANetwork network) {
final PGRFANetwork toUpdate = networkRepository.findBySlug(network.getSlug());
......@@ -161,7 +161,7 @@ public class PGRFANetworkServiceImpl implements PGRFANetworkService {
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR') || hasPermission(org, 'write')")
@PreAuthorize("hasRole('ADMINISTRATOR')")
@CacheEvict(value = CACHE_ORGANIZATION_INSTITUTEORGS, allEntries = true)
public PGRFANetwork setInstitutes(@Valid PGRFANetwork org, List<String> instituteList) {
LOG.info("Setting institutes for network {}", org);
......@@ -213,7 +213,7 @@ public class PGRFANetworkServiceImpl implements PGRFANetworkService {
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR') || hasPermission(network, 'write')")
@PreAuthorize("hasRole('ADMINISTRATOR')")
@CacheEvict(value = CACHE_ORGANIZATION_INSTITUTEORGS, allEntries=true)
public PGRFANetwork addInstitutes(@Valid final PGRFANetwork network, final List<String> instituteList) {
LOG.info("Adding institutes to network {}", network);
......
......@@ -5779,7 +5779,7 @@ databaseChangeLog:
sql: update article set slug = 'blurb' where slug = 'blurp';
- sql:
comment: Organization renamed to PGRFANetwork
sql: delete from classPk where classname='org.genesys2.server.model.impl.PGRFANetwork';
sql: delete from classpk where classname='org.genesys2.server.model.impl.PGRFANetwork';
- sql:
comment: Organization renamed to PGRFANetwork
sql: update classPk set classname='org.genesys2.server.model.impl.PGRFANetwork', shortName='pgrfanetwork' where classname='org.genesys2.server.model.impl.Organization';
sql: update classpk set classname='org.genesys2.server.model.impl.PGRFANetwork', shortName='pgrfanetwork' where classname='org.genesys2.server.model.impl.Organization';
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