updated `getLiferayHighestRoleInOrg`, see #27467
This commit is contained in:
parent
c295cdc794
commit
5cfa4ff5bf
|
@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||||
**Bug fixes**
|
**Bug fixes**
|
||||||
|
|
||||||
- Incident Catalogue edit is leading to duplicate fields [#27455]
|
- Incident Catalogue edit is leading to duplicate fields [#27455]
|
||||||
|
- The Catalogue should read the (Liferay) Highest Role in the VRE (i.e. the Organization) [#27467]
|
||||||
|
|
||||||
## [v2.2.1] - 2024-03-19
|
## [v2.2.1] - 2024-03-19
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.gcube.datacatalogue.utillibrary.server.DataCatalogue;
|
import org.gcube.datacatalogue.utillibrary.server.DataCatalogue;
|
||||||
|
@ -23,8 +24,6 @@ import org.gcube.vomanagement.usermanagement.model.GatewayRolesNames;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Facilities to check roles into the catalogue.
|
* Facilities to check roles into the catalogue.
|
||||||
*/
|
*/
|
||||||
|
@ -33,7 +32,10 @@ public class CatalogueRoleManager {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(CatalogueRoleManager.class);
|
private static final Logger logger = LoggerFactory.getLogger(CatalogueRoleManager.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the highest ckan role the user has and also retrieve the list of organizations (scopes) in which the user has the ckan-admin or ckan-editor role
|
* Retrieve the highest ckan role the user has and also retrieve the list of
|
||||||
|
* organizations (scopes) in which the user has the ckan-admin or ckan-editor
|
||||||
|
* role
|
||||||
|
*
|
||||||
* @param currentScope
|
* @param currentScope
|
||||||
* @param username
|
* @param username
|
||||||
* @param groupName
|
* @param groupName
|
||||||
|
@ -41,7 +43,9 @@ public class CatalogueRoleManager {
|
||||||
* @param orgsInWhichAtLeastEditorRole
|
* @param orgsInWhichAtLeastEditorRole
|
||||||
* @return the highest among the roles
|
* @return the highest among the roles
|
||||||
*/
|
*/
|
||||||
public static RolesCkanGroupOrOrg getHighestRole(String currentScope, String username, String groupName, CKANPublisherServicesImpl gcubeCkanDataCatalogServiceImpl, List<OrganizationBean> orgsInWhichAtLeastEditorRole, String gatewayHostname){
|
public static RolesCkanGroupOrOrg getHighestRole(String currentScope, String username, String groupName,
|
||||||
|
CKANPublisherServicesImpl gcubeCkanDataCatalogServiceImpl,
|
||||||
|
List<OrganizationBean> orgsInWhichAtLeastEditorRole, String gatewayHostname) {
|
||||||
|
|
||||||
// base role as default value
|
// base role as default value
|
||||||
RolesCkanGroupOrOrg toReturn = RolesCkanGroupOrOrg.MEMBER;
|
RolesCkanGroupOrOrg toReturn = RolesCkanGroupOrOrg.MEMBER;
|
||||||
|
@ -58,7 +62,8 @@ public class CatalogueRoleManager {
|
||||||
// retrieve current group id
|
// retrieve current group id
|
||||||
long currentGroupId = groupManager.getGroupIdFromInfrastructureScope(currentScope);
|
long currentGroupId = groupManager.getGroupIdFromInfrastructureScope(currentScope);
|
||||||
|
|
||||||
logger.debug("Group id is " + currentGroupId + " and scope is " + currentScope + "and gateway is "+gatewayHostname);
|
logger.debug("Group id is " + currentGroupId + " and scope is " + currentScope + "and gateway is "
|
||||||
|
+ gatewayHostname);
|
||||||
|
|
||||||
Set<GCubeGroup> groups;
|
Set<GCubeGroup> groups;
|
||||||
// Updated by Francesco see Task #12480
|
// Updated by Francesco see Task #12480
|
||||||
|
@ -66,7 +71,8 @@ public class CatalogueRoleManager {
|
||||||
// retrieve the list of organizations for the current user filtered for gateway
|
// retrieve the list of organizations for the current user filtered for gateway
|
||||||
groups = groupManager.listGroupsByUserAndSite(userid, gatewayHostname);
|
groups = groupManager.listGroupsByUserAndSite(userid, gatewayHostname);
|
||||||
for (GCubeGroup gCubeGroup : groups) {
|
for (GCubeGroup gCubeGroup : groups) {
|
||||||
logger.info("Found group (alias VRE) belonging to "+gatewayHostname+": "+gCubeGroup.getGroupName());
|
logger.info("Found group (alias VRE) belonging to " + gatewayHostname + ": "
|
||||||
|
+ gCubeGroup.getGroupName());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// retrieve the flat list of organizations for the current user
|
// retrieve the flat list of organizations for the current user
|
||||||
|
@ -78,7 +84,8 @@ public class CatalogueRoleManager {
|
||||||
// root (so check into the root, the VOs and the VRES)
|
// root (so check into the root, the VOs and the VRES)
|
||||||
if (groupManager.isRootVO(currentGroupId)) {
|
if (groupManager.isRootVO(currentGroupId)) {
|
||||||
|
|
||||||
logger.info("The current scope is the Root Vo, so the list of organizations of the user " + username + " has " + groups.size() + " group/s");
|
logger.info("The current scope is the Root Vo, so the list of organizations of the user " + username
|
||||||
|
+ " has " + groups.size() + " group/s");
|
||||||
|
|
||||||
for (GCubeGroup gCubeGroup : groups) {
|
for (GCubeGroup gCubeGroup : groups) {
|
||||||
|
|
||||||
|
@ -91,14 +98,16 @@ public class CatalogueRoleManager {
|
||||||
logger.info("Cheking role of the user " + username + " in the VRE " + gCubeGroupName);
|
logger.info("Cheking role of the user " + username + " in the VRE " + gCubeGroupName);
|
||||||
|
|
||||||
// get the role of the users in this group
|
// get the role of the users in this group
|
||||||
List<GCubeRole> roles = roleManager.listRolesByUserAndGroup(userid, groupManager.getGroupId(gCubeGroupName));
|
List<GCubeRole> roles = roleManager.listRolesByUserAndGroup(userid,
|
||||||
|
groupManager.getGroupId(gCubeGroupName));
|
||||||
|
|
||||||
// get highest role
|
// get highest role
|
||||||
RolesCkanGroupOrOrg correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles);
|
RolesCkanGroupOrOrg correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles);
|
||||||
|
|
||||||
// be sure it is so
|
// be sure it is so
|
||||||
checkIfRoleIsSetInCkanInstance(username, gCubeGroupName, gCubeGroup.getGroupId(),
|
checkIfRoleIsSetInCkanInstance(username, gCubeGroupName, gCubeGroup.getGroupId(),
|
||||||
correspondentRoleToCheck, groupManager, gcubeCkanDataCatalogServiceImpl, orgsInWhichAtLeastEditorRole);
|
correspondentRoleToCheck, groupManager, gcubeCkanDataCatalogServiceImpl,
|
||||||
|
orgsInWhichAtLeastEditorRole);
|
||||||
|
|
||||||
toReturn = RolesCkanGroupOrOrg.getHigher(toReturn, correspondentRoleToCheck);
|
toReturn = RolesCkanGroupOrOrg.getHigher(toReturn, correspondentRoleToCheck);
|
||||||
|
|
||||||
|
@ -108,7 +117,8 @@ public class CatalogueRoleManager {
|
||||||
|
|
||||||
} else if (groupManager.isVO(currentGroupId)) {
|
} else if (groupManager.isVO(currentGroupId)) {
|
||||||
|
|
||||||
logger.debug("The list of organizations of the user " + username + " to scan is the one under the VO " + groupName);
|
logger.debug("The list of organizations of the user " + username + " to scan is the one under the VO "
|
||||||
|
+ groupName);
|
||||||
|
|
||||||
for (GCubeGroup gCubeGroup : groups) {
|
for (GCubeGroup gCubeGroup : groups) {
|
||||||
|
|
||||||
|
@ -118,20 +128,23 @@ public class CatalogueRoleManager {
|
||||||
|
|
||||||
String gCubeGroupName = gCubeGroup.getGroupName();
|
String gCubeGroupName = gCubeGroup.getGroupName();
|
||||||
|
|
||||||
List<GCubeRole> roles = roleManager.listRolesByUserAndGroup(userid, groupManager.getGroupId(gCubeGroupName));
|
List<GCubeRole> roles = roleManager.listRolesByUserAndGroup(userid,
|
||||||
|
groupManager.getGroupId(gCubeGroupName));
|
||||||
|
|
||||||
// get highest role
|
// get highest role
|
||||||
RolesCkanGroupOrOrg correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles);
|
RolesCkanGroupOrOrg correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles);
|
||||||
|
|
||||||
// be sure it is so
|
// be sure it is so
|
||||||
checkIfRoleIsSetInCkanInstance(username, gCubeGroupName, gCubeGroup.getGroupId(),
|
checkIfRoleIsSetInCkanInstance(username, gCubeGroupName, gCubeGroup.getGroupId(),
|
||||||
correspondentRoleToCheck, groupManager, gcubeCkanDataCatalogServiceImpl, orgsInWhichAtLeastEditorRole);
|
correspondentRoleToCheck, groupManager, gcubeCkanDataCatalogServiceImpl,
|
||||||
|
orgsInWhichAtLeastEditorRole);
|
||||||
|
|
||||||
toReturn = RolesCkanGroupOrOrg.getHigher(toReturn, correspondentRoleToCheck);
|
toReturn = RolesCkanGroupOrOrg.getHigher(toReturn, correspondentRoleToCheck);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (groupManager.isVRE(currentGroupId)) {
|
} else if (groupManager.isVRE(currentGroupId)) {
|
||||||
List<GCubeRole> roles = roleManager.listRolesByUserAndGroup(userManager.getUserId(username), groupManager.getGroupId(groupName));
|
List<GCubeRole> roles = roleManager.listRolesByUserAndGroup(userManager.getUserId(username),
|
||||||
|
groupManager.getGroupId(groupName));
|
||||||
|
|
||||||
logger.debug("The current scope is the vre " + groupName);
|
logger.debug("The current scope is the vre " + groupName);
|
||||||
|
|
||||||
|
@ -139,8 +152,8 @@ public class CatalogueRoleManager {
|
||||||
RolesCkanGroupOrOrg correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles);
|
RolesCkanGroupOrOrg correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles);
|
||||||
|
|
||||||
// be sure it is so
|
// be sure it is so
|
||||||
checkIfRoleIsSetInCkanInstance(username, groupName, currentGroupId,
|
checkIfRoleIsSetInCkanInstance(username, groupName, currentGroupId, correspondentRoleToCheck,
|
||||||
correspondentRoleToCheck, groupManager, gcubeCkanDataCatalogServiceImpl, orgsInWhichAtLeastEditorRole);
|
groupManager, gcubeCkanDataCatalogServiceImpl, orgsInWhichAtLeastEditorRole);
|
||||||
|
|
||||||
toReturn = correspondentRoleToCheck;
|
toReturn = correspondentRoleToCheck;
|
||||||
|
|
||||||
|
@ -156,7 +169,9 @@ public class CatalogueRoleManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the role admin is set or must be set into the ckan instance at this scope
|
* Check if the role admin is set or must be set into the ckan instance at this
|
||||||
|
* scope
|
||||||
|
*
|
||||||
* @param username
|
* @param username
|
||||||
* @param gCubeGroupName
|
* @param gCubeGroupName
|
||||||
* @param groupId
|
* @param groupId
|
||||||
|
@ -167,12 +182,13 @@ public class CatalogueRoleManager {
|
||||||
* @throws UserManagementSystemException
|
* @throws UserManagementSystemException
|
||||||
* @throws GroupRetrievalFault
|
* @throws GroupRetrievalFault
|
||||||
*/
|
*/
|
||||||
private static void checkIfRoleIsSetInCkanInstance(String username,
|
private static void checkIfRoleIsSetInCkanInstance(String username, String gCubeGroupName, long groupId,
|
||||||
String gCubeGroupName, long groupId,
|
RolesCkanGroupOrOrg correspondentRoleToCheck, GroupManager groupManager,
|
||||||
RolesCkanGroupOrOrg correspondentRoleToCheck,
|
CKANPublisherServicesImpl ckanPublisherServicesImpl, List<OrganizationBean> orgs)
|
||||||
GroupManager groupManager, CKANPublisherServicesImpl ckanPublisherServicesImpl, List<OrganizationBean> orgs) throws UserManagementSystemException, GroupRetrievalFault {
|
throws UserManagementSystemException, GroupRetrievalFault {
|
||||||
|
|
||||||
// with this invocation, we check if the role is present in ckan and if it is not it will be added
|
// with this invocation, we check if the role is present in ckan and if it is
|
||||||
|
// not it will be added
|
||||||
DataCatalogue catalogue = ckanPublisherServicesImpl.getCatalogue(groupManager.getInfrastructureScope(groupId));
|
DataCatalogue catalogue = ckanPublisherServicesImpl.getCatalogue(groupManager.getInfrastructureScope(groupId));
|
||||||
|
|
||||||
// if there is an instance of ckan in this scope..
|
// if there is an instance of ckan in this scope..
|
||||||
|
@ -184,26 +200,35 @@ public class CatalogueRoleManager {
|
||||||
orgs.add(new OrganizationBean(organization.getTitle(), organization.getName(), true));
|
orgs.add(new OrganizationBean(organization.getTitle(), organization.getName(), true));
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
logger.warn("It seems there is no ckan instance into scope " + groupManager.getInfrastructureScope(groupId));
|
logger.warn(
|
||||||
|
"It seems there is no ckan instance into scope " + groupManager.getInfrastructureScope(groupId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the ckan roles among a list of liferay roles
|
* Retrieve the highest ckan role among a list of liferay roles
|
||||||
|
*
|
||||||
* @param roles
|
* @param roles
|
||||||
* @return
|
* @return Updated by Francesco M. see #27467
|
||||||
*/
|
*/
|
||||||
private static RolesCkanGroupOrOrg getLiferayHighestRoleInOrg(
|
private static RolesCkanGroupOrOrg getLiferayHighestRoleInOrg(List<GCubeRole> roles) {
|
||||||
List<GCubeRole> roles) {
|
|
||||||
// NOTE: it is supposed that there is just one role for this person correspondent to the one in the catalog
|
if (roles == null || roles.isEmpty())
|
||||||
for (GCubeRole gCubeRole : roles) {
|
return RolesCkanGroupOrOrg.MEMBER;
|
||||||
if(gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesNames.CATALOGUE_ADMIN.getRoleName())){
|
|
||||||
|
Optional<GCubeRole> admin = roles.stream()
|
||||||
|
.filter(r -> r.getRoleName().equalsIgnoreCase(GatewayRolesNames.CATALOGUE_ADMIN.getRoleName()))
|
||||||
|
.findFirst();
|
||||||
|
|
||||||
|
if (admin.isPresent())
|
||||||
return RolesCkanGroupOrOrg.ADMIN;
|
return RolesCkanGroupOrOrg.ADMIN;
|
||||||
}
|
|
||||||
if(gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesNames.CATALOGUE_EDITOR.getRoleName())){
|
Optional<GCubeRole> editor = roles.stream()
|
||||||
|
.filter(r -> r.getRoleName().equalsIgnoreCase(GatewayRolesNames.CATALOGUE_EDITOR.getRoleName()))
|
||||||
|
.findFirst();
|
||||||
|
|
||||||
|
if (editor.isPresent())
|
||||||
return RolesCkanGroupOrOrg.EDITOR;
|
return RolesCkanGroupOrOrg.EDITOR;
|
||||||
}
|
|
||||||
}
|
|
||||||
return RolesCkanGroupOrOrg.MEMBER;
|
return RolesCkanGroupOrOrg.MEMBER;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue