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:
parent
96d24bb334
commit
003a624f00
|
@ -1,7 +1,6 @@
|
||||||
package org.gcube.datacatalogue.catalogue.utils;
|
package org.gcube.datacatalogue.catalogue.utils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -245,17 +244,16 @@ public class CatalogueUtils {
|
||||||
public static void checkRole(String username, String organization) throws Exception {
|
public static void checkRole(String username, String organization) throws Exception {
|
||||||
|
|
||||||
DataCatalogue catalogue = getCatalogue();
|
DataCatalogue catalogue = getCatalogue();
|
||||||
|
|
||||||
// check organization exists
|
// check organization exists
|
||||||
CkanOrganization org = catalogue.getOrganizationByName(organization);
|
CkanOrganization org = catalogue.getOrganizationByName(organization);
|
||||||
|
|
||||||
if(org == null)
|
if(org == null)
|
||||||
throw new Exception("It seems that an organization with name " + organization + " doesn't exist!");
|
throw new Exception("It seems that an organization with name " + organization + " doesn't exist!");
|
||||||
|
|
||||||
Map<String, List<RolesCkanGroupOrOrg>> rolesPerUser = catalogue.getOrganizationsAndRolesByUser(username,
|
Map<String, Map<CkanOrganization, RolesCkanGroupOrOrg>> rolesPerOrganization = catalogue.getUserRoleByOrganization(username, catalogue.getApiKeyFromUsername(username));
|
||||||
Arrays.asList(RolesCkanGroupOrOrg.ADMIN, RolesCkanGroupOrOrg.EDITOR));
|
|
||||||
|
|
||||||
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 + "!");
|
throw new Exception("It seems you are neither Catalogue-Admin nor Catalogue-Editor in organization " + organization + "!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,8 +116,8 @@ public class Validator {
|
||||||
ownerOrg.toLowerCase().replace(" ", "_").replace("-", "_") : null;
|
ownerOrg.toLowerCase().replace(" ", "_").replace("-", "_") : null;
|
||||||
|
|
||||||
if(organization != null){
|
if(organization != null){
|
||||||
dataset.put(Constants.OWNER_ORG_KEY, organization);
|
|
||||||
CatalogueUtils.checkRole(username, organization);
|
CatalogueUtils.checkRole(username, organization);
|
||||||
|
dataset.put(Constants.OWNER_ORG_KEY, organization);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw new Exception("You must specify the field owner_org in which the item should be published!");
|
throw new Exception("You must specify the field owner_org in which the item should be published!");
|
||||||
|
|
Reference in New Issue