Check first if the user is a ckan sysadmin (in this case he can edit/add without further checks), then if he is a editor/admin or simple member

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/gcube-ckan-datacatalog@129159 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-06-18 11:58:31 +00:00
parent 4490c079e5
commit 60b93329ec
1 changed files with 37 additions and 32 deletions

View File

@ -181,6 +181,16 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
try{
// first of all, check if the user is a sysadmin in the catalog (in this case he can do everything)
boolean isSysAdmin = instance.isSysAdmin(username, instance.getApiKeyFromUsername(username));
if(isSysAdmin){
logger.debug("The user is a sysadmin of the catalog -> he can edit/add");
return CkanRole.SYSADMIN;
}else{
// retrieve the liferay's roles for the user
UserManager userManager = new LiferayUserManager();
RoleManager roleManager = new LiferayRoleManager();
@ -195,12 +205,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
for (RoleModel role : roles) {
logger.debug("User " + username + " has role " + role.getRoleName() + " in " + currentScope);
if(role.getRoleName().contains(CkanRolesIntoLiferay.CATALOG_SYSADMIN.toString())){
mainRole = CkanRolesIntoLiferay.CATALOG_SYSADMIN;
correspondentRoleToCheck = RolesIntoOrganization.SYSADMIN;
break;
}else if(role.getRoleName().contains(CkanRolesIntoLiferay.CATALOG_ADMIN.toString())){
if(role.getRoleName().contains(CkanRolesIntoLiferay.CATALOG_ADMIN.toString())){
mainRole = CkanRolesIntoLiferay.CATALOG_ADMIN;
correspondentRoleToCheck = RolesIntoOrganization.ADMIN;
break;
@ -216,7 +221,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
if(res)
return reMapRole(mainRole);
}
}catch(Exception e){
logger.error("Unable to retrieve the role information for this user. Returning member role", e);
}