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 a81ae36..c0eb6ae 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 @@ -11,6 +11,7 @@ import javax.servlet.http.HttpSession; import org.apache.commons.codec.binary.Base64; import org.gcube.common.authorization.client.exceptions.ObjectNotFound; import org.gcube.common.authorization.library.provider.UserInfo; +import org.gcube.common.portal.PortalContext; import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue; import org.gcube.datacatalogue.ckanutillibrary.DataCatalogueFactory; import org.gcube.datacatalogue.ckanutillibrary.utils.SessionCatalogueAttributes; @@ -27,6 +28,8 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.GroupBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean; import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; +import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager; +import org.gcube.vomanagement.usermanagement.model.GCubeRole; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -53,6 +56,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem public static String CKANCONNECTORCONTEXT = "CkanConnectorContext"; public static String CKANCONNECTORLOGOUT = "CkanConnectorLogout"; public static final String GRSF_UPDATER_SERVICE = "GRSFUpdaterEndPoint"; + private static final String GRSF_ADMIN_ROLE = "GRSF-Admin"; private static Logger logger = LoggerFactory.getLogger(GcubeCkanDataCatalogServiceImpl.class); /** @@ -511,16 +515,25 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem @Override public boolean isManageProductEnabled() { - logger.info("Checking if the manage product button needs to be shown or not"); - + logger.info("Checking if the manage product button needs to be shown or not for the current context/user"); String scopePerCurrentUrl = SessionUtil.getScopeFromClientUrl(getThreadLocalRequest()); DataCatalogue catalogue = getCatalogue(scopePerCurrentUrl); if(catalogue == null){ logger.warn("There is no catalogue instance here..., returning false"); return false; } - else - return catalogue.isManageProductEnabled(); + else{ + PortalContext pContext = PortalContext.getConfiguration(); + List userRoles = new LiferayRoleManager().listRolesByUserAndGroup(pContext.getCurrentUser(getThreadLocalRequest()).getUserId(), pContext.getCurrentGroupId(getThreadLocalRequest())); + boolean isGRSFAdminRoleSet = false; + for (GCubeRole gCubeRole : userRoles) { + if(gCubeRole.getRoleName().equals(GRSF_ADMIN_ROLE)){ + isGRSFAdminRoleSet = true; + break; + } + } + return catalogue.isManageProductEnabled() & isGRSFAdminRoleSet; + } }