task_21363 #1

Closed
francesco.mangiacrapa wants to merge 53 commits from task_21363 into master
9 changed files with 303 additions and 100 deletions
Showing only changes of commit 12bca95bf8 - Show all commits

View File

@ -3,7 +3,9 @@ package org.gcube.portlets.widgets.ckancontentmoderator.client;
import java.util.List; import java.util.List;
import org.gcube.datacatalogue.utillibrary.shared.ItemStatus; import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
import org.gcube.portlets.widgets.ckancontentmoderator.shared.CMSUserRole;
import org.gcube.portlets.widgets.ckancontentmoderator.shared.CatalogueDataset; import org.gcube.portlets.widgets.ckancontentmoderator.shared.CatalogueDataset;
import org.gcube.portlets.widgets.ckancontentmoderator.shared.ModerationUserRole;
import org.gcube.portlets.widgets.ckancontentmoderator.shared.OperationReport; import org.gcube.portlets.widgets.ckancontentmoderator.shared.OperationReport;
import org.gcube.portlets.widgets.ckancontentmoderator.shared.SearchedData; import org.gcube.portlets.widgets.ckancontentmoderator.shared.SearchedData;
@ -28,13 +30,13 @@ public interface CkanContentModeratorService extends RemoteService {
public boolean isContentModeratorEnabled(); public boolean isContentModeratorEnabled();
/** /**
* Sets the status. * Sets the status. Currently, this only used to change the status from Rejected
* Currently, this only used to change the status from Rejected to Pending * to Pending
* *
* @param theStatus the the status * @param theStatus the the status
* @param itemNames the item names * @param itemNames the item names
* @return the operation report * @return the operation report
* @throws Exception * @throws Exception the exception
*/ */
public OperationReport setStatus(ItemStatus theStatus, List<String> itemNames) throws Exception; public OperationReport setStatus(ItemStatus theStatus, List<String> itemNames) throws Exception;
@ -79,6 +81,7 @@ public interface CkanContentModeratorService extends RemoteService {
* @param serverIndex the server index * @param serverIndex the server index
* @return the data for status * @return the data for status
* @throws Exception the exception * @throws Exception the exception
* @par@Override am lenght the lenght
*/ */
SearchedData getDataForStatus(ItemStatus status, int startIndex, int lenght, int serverIndex) throws Exception; SearchedData getDataForStatus(ItemStatus status, int startIndex, int lenght, int serverIndex) throws Exception;
@ -92,4 +95,11 @@ public interface CkanContentModeratorService extends RemoteService {
*/ */
OperationReport approveItem(List<String> itemNames, String moderatorMessage) throws Exception; OperationReport approveItem(List<String> itemNames, String moderatorMessage) throws Exception;
/**
* Gets the CMS roles for user in the context.
*
* @return the CMS roles for user in the context
* @throws Exception the exception
*/
ModerationUserRole getCMSRolesForUserInTheContext() throws Exception;
} }

View File

@ -4,6 +4,7 @@ import java.util.List;
import org.gcube.datacatalogue.utillibrary.shared.ItemStatus; import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
import org.gcube.portlets.widgets.ckancontentmoderator.shared.CatalogueDataset; import org.gcube.portlets.widgets.ckancontentmoderator.shared.CatalogueDataset;
import org.gcube.portlets.widgets.ckancontentmoderator.shared.ModerationUserRole;
import org.gcube.portlets.widgets.ckancontentmoderator.shared.OperationReport; import org.gcube.portlets.widgets.ckancontentmoderator.shared.OperationReport;
import org.gcube.portlets.widgets.ckancontentmoderator.shared.SearchedData; import org.gcube.portlets.widgets.ckancontentmoderator.shared.SearchedData;
@ -87,4 +88,12 @@ public interface CkanContentModeratorServiceAsync {
*/ */
void setStatus(ItemStatus theStatus, List<String> itemNames, AsyncCallback<OperationReport> callback); void setStatus(ItemStatus theStatus, List<String> itemNames, AsyncCallback<OperationReport> callback);
/**
* Gets the CMS roles for user in the context.
*
* @param callback the callback
* @return the CMS roles for user in the context
*/
void getCMSRolesForUserInTheContext(AsyncCallback<ModerationUserRole> callback);
} }

View File

@ -114,7 +114,7 @@ public class HomeView extends Composite {
} }
setStatusOptions(); setStatusOptions(status);
bindEvents(); bindEvents();
confirmPanel.add(confirmPanelContainer); confirmPanel.add(confirmPanelContainer);
@ -123,7 +123,7 @@ public class HomeView extends Composite {
/** /**
* Sets the status options according to item status selected * Sets the status options according to item status selected
*/ */
private void setStatusOptions() { private void setStatusOptions(ItemStatus selectedStatus) {
// Fired when user clicks on CMS action // Fired when user clicks on CMS action
for (final NavLink navLink : setStatusOptions) { for (final NavLink navLink : setStatusOptions) {
@ -132,6 +132,15 @@ public class HomeView extends Composite {
if (navLink.getText().trim().equals(displayingItemStatus.getLabel())) { if (navLink.getText().trim().equals(displayingItemStatus.getLabel())) {
navLink.setVisible(false); navLink.setVisible(false);
} }
//Hiding the changing REJECT -> APPROVED
//One item REJECT must be only updated to return to PENDING status
if(selectedStatus.equals(ItemStatus.REJECTED)) {
if (navLink.getText().trim().equals(ItemStatus.APPROVED.getLabel())) {
navLink.setVisible(false);
}
}
} }
} }
@ -366,7 +375,7 @@ public class HomeView extends Composite {
setCheckedCheckboxSelectAll(false); setCheckedCheckboxSelectAll(false);
setVisibleUpdateStatusAction(false); setVisibleUpdateStatusAction(false);
setVisiblePermanentlyDelete(false); setVisiblePermanentlyDelete(false);
setStatusOptions(); setStatusOptions(itemStatus);
confirmPanelContainer.clear(); confirmPanelContainer.clear();
if (itemStatus.equals(ItemStatus.REJECTED)) if (itemStatus.equals(ItemStatus.REJECTED))
setVisiblePermanentlyDelete(true); setVisiblePermanentlyDelete(true);

View File

@ -10,7 +10,9 @@ import org.gcube.datacatalogue.utillibrary.server.cms.CatalogueContentModeratorS
import org.gcube.datacatalogue.utillibrary.shared.ItemStatus; import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanDataset; import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanDataset;
import org.gcube.portlets.widgets.ckancontentmoderator.client.CkanContentModeratorService; import org.gcube.portlets.widgets.ckancontentmoderator.client.CkanContentModeratorService;
import org.gcube.portlets.widgets.ckancontentmoderator.shared.CMSUserRole;
import org.gcube.portlets.widgets.ckancontentmoderator.shared.CatalogueDataset; import org.gcube.portlets.widgets.ckancontentmoderator.shared.CatalogueDataset;
import org.gcube.portlets.widgets.ckancontentmoderator.shared.ModerationUserRole;
import org.gcube.portlets.widgets.ckancontentmoderator.shared.OperationReport; import org.gcube.portlets.widgets.ckancontentmoderator.shared.OperationReport;
import org.gcube.portlets.widgets.ckancontentmoderator.shared.SearchedData; import org.gcube.portlets.widgets.ckancontentmoderator.shared.SearchedData;
import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.gcube.vomanagement.usermanagement.model.GCubeUser;
@ -52,15 +54,34 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
return isContentModeratorEnabled; return isContentModeratorEnabled;
} }
/**
* Gets the CMS roles for user in the context.
*
* @return the CMS roles for user in the context
* @throws Exception the exception
*/
@Override
public ModerationUserRole getCMSRolesForUserInTheContext() throws Exception {
LOG.info("called getCMSRolesForUserInTheContext");
setContexts();
List<CMSUserRole> roles = GcubeContextUtil.getCMSRoleForUserInTheScope(getThreadLocalRequest());
GcubeContextUtil.getCurrentUser(getThreadLocalRequest());
ModerationUserRole userRole = new ModerationUserRole(getServletInfo(), roles);
LOG.info("return: "+userRole);
return userRole;
}
/** /**
* Sets the contexts. * Sets the contexts.
* *
* @return the scope operating in * @return the scope operating in
*/ */
private String setContexts() { private String setContexts() {
String scope = WsUtil.getCurrentScope(this.getThreadLocalRequest()); String scope = GcubeContextUtil.getCurrentScope(this.getThreadLocalRequest());
GCubeUser user = WsUtil.getCurrentUser(this.getThreadLocalRequest()); GCubeUser user = GcubeContextUtil.getCurrentUser(this.getThreadLocalRequest());
String token = WsUtil.getCurrentToken(scope, user.getUsername()); String token = GcubeContextUtil.getCurrentToken(scope, user.getUsername());
ScopeProvider.instance.set(scope); ScopeProvider.instance.set(scope);
SecurityTokenProvider.instance.set(token); SecurityTokenProvider.instance.set(token);
return scope; return scope;
@ -107,7 +128,6 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
LOG.info("returning " + datasetList.size() + " dataset"); LOG.info("returning " + datasetList.size() + " dataset");
return datasetList; return datasetList;
} }
/** /**
* Sets the status. * Sets the status.
@ -115,7 +135,7 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
* @param theStatus the the status * @param theStatus the the status
* @param itemNames the item names * @param itemNames the item names
* @return the operation report * @return the operation report
* @throws Exception * @throws Exception
*/ */
@Override @Override
public OperationReport setStatus(ItemStatus theStatus, List<String> itemNames) throws Exception { public OperationReport setStatus(ItemStatus theStatus, List<String> itemNames) throws Exception {
@ -125,26 +145,26 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
String scope = setContexts(); String scope = setContexts();
DataCatalogueImpl catalogueImpl = CatalogueCMSFactory.getFactory().getCatalogueImplPerScope(scope); DataCatalogueImpl catalogueImpl = CatalogueCMSFactory.getFactory().getCatalogueImplPerScope(scope);
List<String> errorListItems = new ArrayList<String>(); List<String> errorListItems = new ArrayList<String>();
List<String> approvedListItems = new ArrayList<String>(); List<String> changedStatusListItems = new ArrayList<String>();
for (String itemName : itemNames) { for (String itemName : itemNames) {
try { try {
catalogueImpl.refreshDataset(itemName); catalogueImpl.refreshDataset(itemName);
approvedListItems.add(itemName); changedStatusListItems.add(itemName);
} catch (Exception e) { } catch (Exception e) {
LOG.warn("Error when setting status (updating) the itemName: " + itemName, e); LOG.warn("Error when setting status (updating) the itemName: " + itemName, e);
errorListItems.add(itemName); errorListItems.add(itemName);
} }
} }
return new OperationReport(theStatus.getLabel(), errorListItems, approvedListItems); return new OperationReport(theStatus.getLabel(), errorListItems, changedStatusListItems);
} catch (Exception e) { } catch (Exception e) {
LOG.error(e.getMessage(), e); LOG.error(e.getMessage(), e);
throw new Exception("Error occurred on updating the status for item/s: " + itemNames + ". Caused by: " + e.getMessage()); throw new Exception("Error occurred on updating the status for item/s: " + itemNames + ". Caused by: "
+ e.getMessage());
} }
} }
/** /**
* Approve item. * Approve item.
* *

View File

@ -0,0 +1,163 @@
/**
*
*/
package org.gcube.portlets.widgets.ckancontentmoderator.server;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.gcube.common.portal.PortalContext;
import org.gcube.portlets.widgets.ckancontentmoderator.shared.CMSUserRole;
import org.gcube.vomanagement.usermanagement.RoleManager;
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
import org.gcube.vomanagement.usermanagement.model.GCubeRole;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.liferay.portal.service.UserLocalServiceUtil;
/**
* The Class GcubeContextUtil.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Feb 21, 2022
*/
public class GcubeContextUtil {
protected static Logger LOG = LoggerFactory.getLogger(GcubeContextUtil.class);
/**
* Checks if is within portal.
*
* @return true if you're running into the portal, false if in development
*/
public static boolean isWithinPortal() {
try {
UserLocalServiceUtil.getService();
return true;
} catch (Exception ex) {
LOG.trace("Development Mode ON");
return false;
}
}
/**
* Gets the current user.
*
* @param httpServletRequest the http servlet request
* @return the current user
*/
public static GCubeUser getCurrentUser(HttpServletRequest httpServletRequest) {
return PortalContext.getConfiguration().getCurrentUser(httpServletRequest);
}
/**
* Gets the current scope.
*
* @param httpServletRequest the http servlet request
* @return the current scope
*/
public static String getCurrentScope(HttpServletRequest httpServletRequest) {
return PortalContext.getConfiguration().getCurrentScope(httpServletRequest);
}
/**
* Gets the current token.
*
* @param scope the scope
* @param username the username
* @return the current token
*/
public static String getCurrentToken(String scope, String username) {
return PortalContext.getConfiguration().getCurrentUserToken(scope, username);
}
/**
* Gets the current group id.
*
* @param httpServletRequest the http servlet request
* @return the current group id
*/
public static long getCurrentGroupId(HttpServletRequest httpServletRequest) {
return PortalContext.getConfiguration().getCurrentGroupId(httpServletRequest);
}
/**
* Gets the CMS user role for the logged user (in the current context)
*
* @param httpServletRequest the http servlet request
* @return the scopes with user roles for logged user
* @throws Exception the exception
*/
public static List<CMSUserRole> getCMSRoleForUserInTheScope(HttpServletRequest httpServletRequest) throws Exception {
LOG.info("called getScopesWithThreddsRolesForLoggedUser");
// DEV MODE
if (!isWithinPortal()) {
CMSUserRole userRole = CMSUserRole.CATALOGUE_MODERATOR;
LOG.warn("\n\n\nDevelopment MODE is enabled, returning CMS user role: "+userRole);
return Arrays.asList(userRole);
}
GCubeUser user = null;
String scope = null;
Long groupId = null;
try {
user = getCurrentUser(httpServletRequest);
scope = getCurrentScope(httpServletRequest);
groupId = getCurrentGroupId(httpServletRequest);
List<CMSUserRole> cmsRoles = getCMSRoleForUserInTheGroupId(user, groupId);
LOG.info("in the context: " + scope + ", returning the role: " + cmsRoles + " for user "
+ user.getUsername());
return cmsRoles;
} catch (Exception e) {
String errorMsg = "An error occurred on checking user roles. Refresh the page and try again.";
LOG.error("An error occurred on checking user roles for user: " + user, e);
throw new Exception(errorMsg);
}
}
/**
* Gets the CMS role for user in the scope.
*
* @param user the user
* @param groupId the group id
* @return the CMS role for user in the scope
*/
private static List<CMSUserRole> getCMSRoleForUserInTheGroupId(GCubeUser user, Long groupId) {
if (user == null || groupId == null) {
LOG.warn("called getCMSRoleForUserInTheScope with invalid parameter user: " + user + ", in the groupId: "
+ groupId, ", returning null");
return null;
}
LOG.info("called getCMSRoleForUserInTheScope user: " + user.getUsername() + ", in the groupId: " + groupId);
try {
RoleManager roleManager = new LiferayRoleManager();
List<GCubeRole> roles = roleManager.listRolesByUserAndGroup(user.getUserId(), groupId);
List<CMSUserRole> toReturn = new ArrayList<CMSUserRole>();
if (roles != null) {
for (GCubeRole gCubeRole : roles) {
if (gCubeRole.getRoleName().equalsIgnoreCase(CMSUserRole.CATALOGUE_MODERATOR.getRoleName())) {
toReturn.add(CMSUserRole.CATALOGUE_MODERATOR);
}
}
}
LOG.info("For user: " + user.getUsername() + " in the groupId: " + groupId
+ " read and returing the role/s: " + toReturn);
return toReturn;
} catch (UserRetrievalFault | GroupRetrievalFault e) {
LOG.error("An error occurred during getVreRoleForUser: " + user, e);
return null;
}
}
}

View File

@ -1,75 +0,0 @@
/**
*
*/
package org.gcube.portlets.widgets.ckancontentmoderator.server;
import javax.servlet.http.HttpServletRequest;
import org.gcube.common.portal.PortalContext;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.liferay.portal.service.UserLocalServiceUtil;
// TODO: Auto-generated Javadoc
/**
* The Class WsUtil.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Jun 1, 2021
*/
public class WsUtil {
protected static Logger logger = LoggerFactory.getLogger(WsUtil.class);
/**
* Checks if is within portal.
*
* @return true if you're running into the portal, false if in development
*/
public static boolean isWithinPortal() {
try {
UserLocalServiceUtil.getService();
return true;
} catch (Exception ex) {
logger.trace("Development Mode ON");
return false;
}
}
/**
* Gets the current user.
*
* @param httpServletRequest the http servlet request
* @return the current user
*/
public static GCubeUser getCurrentUser(HttpServletRequest httpServletRequest){
return PortalContext.getConfiguration().getCurrentUser(httpServletRequest);
}
/**
* Gets the current scope.
*
* @param httpServletRequest the http servlet request
* @return the current scope
*/
public static String getCurrentScope(HttpServletRequest httpServletRequest){
return PortalContext.getConfiguration().getCurrentScope(httpServletRequest);
}
/**
* Gets the current token.
*
* @param scope the scope
* @param username the username
* @return the current token
*/
public static String getCurrentToken(String scope, String username){
return PortalContext.getConfiguration().getCurrentUserToken(scope,username);
}
}

View File

@ -0,0 +1,17 @@
package org.gcube.portlets.widgets.ckancontentmoderator.shared;
public enum CMSUserRole {
CATALOGUE_MODERATOR("Catalogue-Moderator");
private String name;
private CMSUserRole(String name) {
this.name = name;
}
public String getRoleName() {
return this.name;
}
}

View File

@ -0,0 +1,57 @@
package org.gcube.portlets.widgets.ckancontentmoderator.shared;
import java.io.Serializable;
import java.util.List;
/**
* The Class ModerationUserRole.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Feb 21, 2022
*/
public class ModerationUserRole implements Serializable {
/**
*
*/
private static final long serialVersionUID = 7002466635359684148L;
private String username;
private List<CMSUserRole> roles;
/**
* Instantiates a new moderation user role.
*/
public ModerationUserRole() {
}
public ModerationUserRole(String username, List<CMSUserRole> roles) {
super();
this.username = username;
this.roles = roles;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
public String getUsername() {
return username;
}
public List<CMSUserRole> getRoles() {
return roles;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ModerationUserRole [username=");
builder.append(username);
builder.append(", roles=");
builder.append(roles);
builder.append("]");
return builder.toString();
}
}

View File

@ -14,17 +14,10 @@ import org.slf4j.LoggerFactory;
public class CkanContentModeratorServiceTest { public class CkanContentModeratorServiceTest {
//devVRE
//private String scope = "/gcube/devsec/devVRE"; //private String scope = "/gcube/devsec/devVRE";
//Dorne
private String scope = "/pred4s/preprod/Dorne"; private String scope = "/pred4s/preprod/Dorne";
private String testUser = "francesco.mangiacrapa"; private String testUser = "francesco.mangiacrapa";
//devVRE
//private String authorizationToken = "8e74a17c-92f1-405a-b591-3a6090066248-98187548";
//Dorne
private String authorizationToken = ""; private String authorizationToken = "";
//debd432e-de72-4e1c-960c-fd2af916c5e8-980114272 Dorne
private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(CkanContentModeratorServiceTest.class); private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(CkanContentModeratorServiceTest.class);
@ -33,7 +26,7 @@ public class CkanContentModeratorServiceTest {
fail("Not yet implemented"); fail("Not yet implemented");
} }
@Test //@Test
public void loadItemsForStatus() { public void loadItemsForStatus() {
ScopeProvider.instance.set(scope); ScopeProvider.instance.set(scope);
SecurityTokenProvider.instance.set(authorizationToken); SecurityTokenProvider.instance.set(authorizationToken);