user's role in organization is now checked via db (much faster)

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/catalogue-ws@150554 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2017-06-27 08:11:21 +00:00
parent 96d24bb334
commit 003a624f00
2 changed files with 5 additions and 7 deletions

View File

@ -1,7 +1,6 @@
package org.gcube.datacatalogue.catalogue.utils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@ -245,17 +244,16 @@ public class CatalogueUtils {
public static void checkRole(String username, String organization) throws Exception {
DataCatalogue catalogue = getCatalogue();
// check organization exists
CkanOrganization org = catalogue.getOrganizationByName(organization);
if(org == null)
throw new Exception("It seems that an organization with name " + organization + " doesn't exist!");
Map<String, List<RolesCkanGroupOrOrg>> rolesPerUser = catalogue.getOrganizationsAndRolesByUser(username,
Arrays.asList(RolesCkanGroupOrOrg.ADMIN, RolesCkanGroupOrOrg.EDITOR));
Map<String, Map<CkanOrganization, RolesCkanGroupOrOrg>> rolesPerOrganization = catalogue.getUserRoleByOrganization(username, catalogue.getApiKeyFromUsername(username));
if(!rolesPerUser.containsKey(organization))
if(rolesPerOrganization.get(org.getName()).values().contains(RolesCkanGroupOrOrg.MEMBER))
throw new Exception("It seems you are neither Catalogue-Admin nor Catalogue-Editor in organization " + organization + "!");
}

View File

@ -116,8 +116,8 @@ public class Validator {
ownerOrg.toLowerCase().replace(" ", "_").replace("-", "_") : null;
if(organization != null){
dataset.put(Constants.OWNER_ORG_KEY, organization);
CatalogueUtils.checkRole(username, organization);
dataset.put(Constants.OWNER_ORG_KEY, organization);
}
else
throw new Exception("You must specify the field owner_org in which the item should be published!");