diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java index 2d95216..8cfa7d6 100644 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java @@ -181,48 +181,53 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem try{ - // retrieve the liferay's roles for the user - UserManager userManager = new LiferayUserManager(); - RoleManager roleManager = new LiferayRoleManager(); - GroupManager groupManager = new LiferayGroupManager(); - List roles = roleManager.listRolesByUserAndGroup(groupManager.getGroupId(groupName), userManager.getUserId(username)); + // 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)); - // the default one - CkanRolesIntoLiferay mainRole = CkanRolesIntoLiferay.CATALOG_MEMBER; - RolesIntoOrganization correspondentRoleToCheck = RolesIntoOrganization.MEMBER; + if(isSysAdmin){ - // NOTE: it is supposed that there is just one role for this person correspondent to the one in the catalog - for (RoleModel role : roles) { + logger.debug("The user is a sysadmin of the catalog -> he can edit/add"); + return CkanRole.SYSADMIN; - logger.debug("User " + username + " has role " + role.getRoleName() + " in " + currentScope); + }else{ - 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())){ - mainRole = CkanRolesIntoLiferay.CATALOG_ADMIN; - correspondentRoleToCheck = RolesIntoOrganization.ADMIN; - break; - }else if(role.getRoleName().contains(CkanRolesIntoLiferay.CATALOG_EDITOR.toString())){ - mainRole = CkanRolesIntoLiferay.CATALOG_EDITOR; - correspondentRoleToCheck = RolesIntoOrganization.EDITOR; - break; - } + // retrieve the liferay's roles for the user + UserManager userManager = new LiferayUserManager(); + RoleManager roleManager = new LiferayRoleManager(); + GroupManager groupManager = new LiferayGroupManager(); + List roles = roleManager.listRolesByUserAndGroup(groupManager.getGroupId(groupName), userManager.getUserId(username)); + + // the default one + CkanRolesIntoLiferay mainRole = CkanRolesIntoLiferay.CATALOG_MEMBER; + RolesIntoOrganization correspondentRoleToCheck = RolesIntoOrganization.MEMBER; + + // NOTE: it is supposed that there is just one role for this person correspondent to the one in the catalog + for (RoleModel role : roles) { + + logger.debug("User " + username + " has role " + role.getRoleName() + " in " + currentScope); + if(role.getRoleName().contains(CkanRolesIntoLiferay.CATALOG_ADMIN.toString())){ + mainRole = CkanRolesIntoLiferay.CATALOG_ADMIN; + correspondentRoleToCheck = RolesIntoOrganization.ADMIN; + break; + }else if(role.getRoleName().contains(CkanRolesIntoLiferay.CATALOG_EDITOR.toString())){ + mainRole = CkanRolesIntoLiferay.CATALOG_EDITOR; + correspondentRoleToCheck = RolesIntoOrganization.EDITOR; + break; + } + } + + // with this invocation, we check if the role is present in ckan and if it is not it will be added + boolean res = instance.checkRole(username, groupName, correspondentRoleToCheck); + + if(res) + return reMapRole(mainRole); } - - // with this invocation, we check if the role is present in ckan and if it is not it will be added - boolean res = instance.checkRole(username, groupName, correspondentRoleToCheck); - - if(res) - return reMapRole(mainRole); - }catch(Exception e){ logger.error("Unable to retrieve the role information for this user. Returning member role", e); } logger.debug("Unable to check the role into ckan organization, returning MEMBER as role"); - + // return the base role return CkanRole.MEMBER; }