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:
parent
4490c079e5
commit
60b93329ec
|
@ -181,48 +181,53 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
|
||||||
// retrieve the liferay's roles for the user
|
// first of all, check if the user is a sysadmin in the catalog (in this case he can do everything)
|
||||||
UserManager userManager = new LiferayUserManager();
|
boolean isSysAdmin = instance.isSysAdmin(username, instance.getApiKeyFromUsername(username));
|
||||||
RoleManager roleManager = new LiferayRoleManager();
|
|
||||||
GroupManager groupManager = new LiferayGroupManager();
|
|
||||||
List<RoleModel> roles = roleManager.listRolesByUserAndGroup(groupManager.getGroupId(groupName), userManager.getUserId(username));
|
|
||||||
|
|
||||||
// the default one
|
if(isSysAdmin){
|
||||||
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
|
logger.debug("The user is a sysadmin of the catalog -> he can edit/add");
|
||||||
for (RoleModel role : roles) {
|
return CkanRole.SYSADMIN;
|
||||||
|
|
||||||
logger.debug("User " + username + " has role " + role.getRoleName() + " in " + currentScope);
|
}else{
|
||||||
|
|
||||||
if(role.getRoleName().contains(CkanRolesIntoLiferay.CATALOG_SYSADMIN.toString())){
|
// retrieve the liferay's roles for the user
|
||||||
mainRole = CkanRolesIntoLiferay.CATALOG_SYSADMIN;
|
UserManager userManager = new LiferayUserManager();
|
||||||
correspondentRoleToCheck = RolesIntoOrganization.SYSADMIN;
|
RoleManager roleManager = new LiferayRoleManager();
|
||||||
break;
|
GroupManager groupManager = new LiferayGroupManager();
|
||||||
}else if(role.getRoleName().contains(CkanRolesIntoLiferay.CATALOG_ADMIN.toString())){
|
List<RoleModel> roles = roleManager.listRolesByUserAndGroup(groupManager.getGroupId(groupName), userManager.getUserId(username));
|
||||||
mainRole = CkanRolesIntoLiferay.CATALOG_ADMIN;
|
|
||||||
correspondentRoleToCheck = RolesIntoOrganization.ADMIN;
|
// the default one
|
||||||
break;
|
CkanRolesIntoLiferay mainRole = CkanRolesIntoLiferay.CATALOG_MEMBER;
|
||||||
}else if(role.getRoleName().contains(CkanRolesIntoLiferay.CATALOG_EDITOR.toString())){
|
RolesIntoOrganization correspondentRoleToCheck = RolesIntoOrganization.MEMBER;
|
||||||
mainRole = CkanRolesIntoLiferay.CATALOG_EDITOR;
|
|
||||||
correspondentRoleToCheck = RolesIntoOrganization.EDITOR;
|
// NOTE: it is supposed that there is just one role for this person correspondent to the one in the catalog
|
||||||
break;
|
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){
|
}catch(Exception e){
|
||||||
logger.error("Unable to retrieve the role information for this user. Returning member role", 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");
|
logger.debug("Unable to check the role into ckan organization, returning MEMBER as role");
|
||||||
|
|
||||||
// return the base role
|
// return the base role
|
||||||
return CkanRole.MEMBER;
|
return CkanRole.MEMBER;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue