removed catalogue information preloading operations. Publish on catalogue will be always available on directories, and permission check will performed on button click
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@141754 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
eb618e3dd3
commit
c766bfeeaa
|
@ -183,7 +183,6 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
private boolean selectRootItem;
|
private boolean selectRootItem;
|
||||||
public static String myLogin;
|
public static String myLogin;
|
||||||
public static String myLoginFirstName;
|
public static String myLoginFirstName;
|
||||||
public static Boolean ckanEditorOrAdmin;
|
|
||||||
//PRE-LOAD LIST OF USER FORM LIFERAY
|
//PRE-LOAD LIST OF USER FORM LIFERAY
|
||||||
private UserStore userStore = new UserStore();
|
private UserStore userStore = new UserStore();
|
||||||
private static AppControllerExplorer singleton;
|
private static AppControllerExplorer singleton;
|
||||||
|
@ -2299,7 +2298,6 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
GWT.log("My login is: "+user.getUsername());
|
GWT.log("My login is: "+user.getUsername());
|
||||||
myLogin = user.getUsername();
|
myLogin = user.getUsername();
|
||||||
myLoginFirstName = user.getFirstName();
|
myLoginFirstName = user.getFirstName();
|
||||||
ckanEditorOrAdmin = user.hasCataloguePermission();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,42 +127,42 @@ public class ContextMenuTree {
|
||||||
|
|
||||||
//Open Report Template
|
//Open Report Template
|
||||||
//TODO REMOVE
|
//TODO REMOVE
|
||||||
// MenuItem openReportTemplate = new MenuItem();
|
// MenuItem openReportTemplate = new MenuItem();
|
||||||
// openReportTemplate.setId(WorkspaceOperation.OPEN_REPORT_TEMPLATE.getId());
|
// openReportTemplate.setId(WorkspaceOperation.OPEN_REPORT_TEMPLATE.getId());
|
||||||
// openReportTemplate.setText(ConstantsExplorer.MESSAGE_OPEN_REPORT_TEMPLATE);
|
// openReportTemplate.setText(ConstantsExplorer.MESSAGE_OPEN_REPORT_TEMPLATE);
|
||||||
// openReportTemplate.setIcon(Resources.getIconShow());
|
// openReportTemplate.setIcon(Resources.getIconShow());
|
||||||
//
|
//
|
||||||
// openReportTemplate.addSelectionListener(new SelectionListener<MenuEvent>() {
|
// openReportTemplate.addSelectionListener(new SelectionListener<MenuEvent>() {
|
||||||
// public void componentSelected(MenuEvent ce) {
|
// public void componentSelected(MenuEvent ce) {
|
||||||
//
|
//
|
||||||
// FileModel selected = listSelectedItems.get(0);
|
// FileModel selected = listSelectedItems.get(0);
|
||||||
//
|
//
|
||||||
// if(selected!=null){
|
// if(selected!=null){
|
||||||
// eventBus.fireEvent(new OpenReportsEvent(selected));
|
// eventBus.fireEvent(new OpenReportsEvent(selected));
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
|
|
||||||
//contextMenu.add(openReportTemplate);
|
//contextMenu.add(openReportTemplate);
|
||||||
|
|
||||||
//Open Report Template
|
//Open Report Template
|
||||||
//TODO REMOVE
|
//TODO REMOVE
|
||||||
// MenuItem openReport = new MenuItem();
|
// MenuItem openReport = new MenuItem();
|
||||||
// openReport.setId(WorkspaceOperation.OPEN_REPORT.getId());
|
// openReport.setId(WorkspaceOperation.OPEN_REPORT.getId());
|
||||||
// openReport.setText(ConstantsExplorer.MESSAGE_OPEN_REPORT);
|
// openReport.setText(ConstantsExplorer.MESSAGE_OPEN_REPORT);
|
||||||
// openReport.setIcon(Resources.getIconShow());
|
// openReport.setIcon(Resources.getIconShow());
|
||||||
//
|
//
|
||||||
// openReport.addSelectionListener(new SelectionListener<MenuEvent>() {
|
// openReport.addSelectionListener(new SelectionListener<MenuEvent>() {
|
||||||
// public void componentSelected(MenuEvent ce) {
|
// public void componentSelected(MenuEvent ce) {
|
||||||
//
|
//
|
||||||
// FileModel selected = listSelectedItems.get(0);
|
// FileModel selected = listSelectedItems.get(0);
|
||||||
//
|
//
|
||||||
// if (selected != null){
|
// if (selected != null){
|
||||||
// eventBus.fireEvent(new OpenReportsEvent(selected));
|
// eventBus.fireEvent(new OpenReportsEvent(selected));
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
|
|
||||||
//contextMenu.add(openReport);
|
//contextMenu.add(openReport);
|
||||||
contextMenu.add(new SeparatorMenuItem());
|
contextMenu.add(new SeparatorMenuItem());
|
||||||
|
@ -879,9 +879,7 @@ public class ContextMenuTree {
|
||||||
|
|
||||||
//CASE DIRECTORY
|
//CASE DIRECTORY
|
||||||
if(selectedItem.isDirectory()){
|
if(selectedItem.isDirectory()){
|
||||||
if(AppControllerExplorer.ckanEditorOrAdmin)
|
contextMenu.getItemByItemId(WorkspaceOperation.PUBLISH_ON_DATA_CATALOGUE.getId()).setVisible(true);
|
||||||
contextMenu.getItemByItemId(WorkspaceOperation.PUBLISH_ON_DATA_CATALOGUE.getId()).setVisible(true);
|
|
||||||
|
|
||||||
contextMenu.getItemByItemId(WorkspaceOperation.SHARE.getId()).setVisible(true); //SHARE
|
contextMenu.getItemByItemId(WorkspaceOperation.SHARE.getId()).setVisible(true); //SHARE
|
||||||
contextMenu.getItemByItemId(WorkspaceOperation.SHOW.getId()).setVisible(false); //show
|
contextMenu.getItemByItemId(WorkspaceOperation.SHOW.getId()).setVisible(false); //show
|
||||||
contextMenu.getItemByItemId(WorkspaceOperation.REFRESH_FOLDER.getId()).setVisible(true); //refresh
|
contextMenu.getItemByItemId(WorkspaceOperation.REFRESH_FOLDER.getId()).setVisible(true); //refresh
|
||||||
|
|
|
@ -13,7 +13,6 @@ import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpSession;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.gcube.common.encryption.StringEncrypter;
|
import org.gcube.common.encryption.StringEncrypter;
|
||||||
|
@ -42,11 +41,6 @@ import org.gcube.common.homelibrary.home.workspace.search.SearchItem;
|
||||||
import org.gcube.common.homelibrary.home.workspace.trash.WorkspaceTrashFolder;
|
import org.gcube.common.homelibrary.home.workspace.trash.WorkspaceTrashFolder;
|
||||||
import org.gcube.common.homelibrary.home.workspace.trash.WorkspaceTrashItem;
|
import org.gcube.common.homelibrary.home.workspace.trash.WorkspaceTrashItem;
|
||||||
import org.gcube.common.portal.PortalContext;
|
import org.gcube.common.portal.PortalContext;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.ApplicationProfileScopePerUrlReader;
|
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue;
|
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.DataCatalogueFactory;
|
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.utils.SessionCatalogueAttributes;
|
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.utils.UtilMethods;
|
|
||||||
import org.gcube.portlets.user.urlshortener.UrlShortener;
|
import org.gcube.portlets.user.urlshortener.UrlShortener;
|
||||||
import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
|
import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
|
||||||
import org.gcube.portlets.user.workspace.client.interfaces.GXTCategorySmartFolder;
|
import org.gcube.portlets.user.workspace.client.interfaces.GXTCategorySmartFolder;
|
||||||
|
@ -89,8 +83,6 @@ import org.gcube.portlets.user.workspace.shared.WorkspaceTrashOperation;
|
||||||
import org.gcube.portlets.user.workspace.shared.WorkspaceUserQuote;
|
import org.gcube.portlets.user.workspace.shared.WorkspaceUserQuote;
|
||||||
import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingEntryType;
|
import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingEntryType;
|
||||||
import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingField;
|
import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingField;
|
||||||
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.GroupManager;
|
||||||
import org.gcube.vomanagement.usermanagement.UserManager;
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
||||||
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
||||||
|
@ -102,8 +94,6 @@ import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||||
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
||||||
import com.liferay.portal.service.UserLocalServiceUtil;
|
import com.liferay.portal.service.UserLocalServiceUtil;
|
||||||
|
|
||||||
import eu.trentorise.opendata.jackan.model.CkanGroup;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class GWTWorkspaceServiceImpl.
|
* The Class GWTWorkspaceServiceImpl.
|
||||||
|
@ -2628,7 +2618,6 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
||||||
String email = info.getUserEmail();
|
String email = info.getUserEmail();
|
||||||
String firstName = "Testing";
|
String firstName = "Testing";
|
||||||
String lastName = "User";
|
String lastName = "User";
|
||||||
boolean publishRights = false;
|
|
||||||
|
|
||||||
if (isWithinPortal() && username != null) {
|
if (isWithinPortal() && username != null) {
|
||||||
try {
|
try {
|
||||||
|
@ -2637,9 +2626,6 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
||||||
firstName = user.getFirstName();
|
firstName = user.getFirstName();
|
||||||
lastName = user.getLastName();
|
lastName = user.getLastName();
|
||||||
email = user.getEmail();
|
email = user.getEmail();
|
||||||
|
|
||||||
// check if he has catalogue role
|
|
||||||
publishRights = enablePublishOnCatalogue(currentPortletUrl);
|
|
||||||
}catch (UserManagementSystemException e) {
|
}catch (UserManagementSystemException e) {
|
||||||
workspaceLogger.error("UserManagementSystemException for username: "+username);
|
workspaceLogger.error("UserManagementSystemException for username: "+username);
|
||||||
}
|
}
|
||||||
|
@ -2652,7 +2638,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UserBean us = new UserBean(username, firstName, lastName, email, publishRights);
|
UserBean us = new UserBean(username, firstName, lastName, email);
|
||||||
workspaceLogger.info("Returning myLogin: "+us);
|
workspaceLogger.info("Returning myLogin: "+us);
|
||||||
|
|
||||||
return us;
|
return us;
|
||||||
|
@ -3398,130 +3384,6 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve an instance of the library for the scope.
|
|
||||||
*
|
|
||||||
* @param scope if it is null it is evaluated from the session
|
|
||||||
* @return the ckan utils obj
|
|
||||||
*/
|
|
||||||
public DataCatalogue getCatalogue(String scope){
|
|
||||||
PortalContextInfo info = WsUtil.getPortalContext(this.getThreadLocalRequest());
|
|
||||||
DataCatalogue instance = null;
|
|
||||||
try{
|
|
||||||
String scopeInWhichDiscover = scope != null && !scope.isEmpty() ? scope : info.getCurrentScope();
|
|
||||||
workspaceLogger.debug("Discovering ckan instance into scope " + scopeInWhichDiscover);
|
|
||||||
instance = DataCatalogueFactory.getFactory().getUtilsPerScope(scopeInWhichDiscover);
|
|
||||||
}catch(Exception e){
|
|
||||||
workspaceLogger.error("Unable to retrieve ckan utils", e);
|
|
||||||
}
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the current user has publish rights on the data catalogue
|
|
||||||
* @param currentPortletUrl
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private boolean enablePublishOnCatalogue(String currentPortletUrl) {
|
|
||||||
|
|
||||||
PortalContextInfo info = WsUtil.getPortalContext(this.getThreadLocalRequest());
|
|
||||||
String username = info.getUsername();
|
|
||||||
HttpSession httpSession = this.getThreadLocalRequest().getSession();
|
|
||||||
|
|
||||||
if(!isWithinPortal()){
|
|
||||||
workspaceLogger.warn("OUT FROM PORTAL DETECTED RETURNING TRUE");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(username == null){
|
|
||||||
workspaceLogger.warn("Session expired");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// retrieve scope per current portlet url
|
|
||||||
String scopePerCurrentUrl = ApplicationProfileScopePerUrlReader.getScopePerUrl(currentPortletUrl);
|
|
||||||
this.getThreadLocalRequest().getSession().setAttribute(currentPortletUrl, scopePerCurrentUrl);
|
|
||||||
|
|
||||||
// get key per scope
|
|
||||||
String keyPerScopeRole = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_PUBLISH_WORKSPACE, scopePerCurrentUrl);
|
|
||||||
String keyPerScopeOrganizations = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_ORGANIZATIONS_PUBLISH_KEY, scopePerCurrentUrl);
|
|
||||||
String keyPerScopeGroups = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_GROUPS_MEMBER, scopePerCurrentUrl);
|
|
||||||
|
|
||||||
// check if this information was already into the ASL Session (true means the user has at least in one org
|
|
||||||
// the role editor), false that he is just a member so he cannot publish
|
|
||||||
Boolean role = (Boolean) httpSession.getAttribute(keyPerScopeRole);
|
|
||||||
|
|
||||||
// if the attribute was already set..
|
|
||||||
if(role != null)
|
|
||||||
return role;
|
|
||||||
else{
|
|
||||||
|
|
||||||
try{
|
|
||||||
role = false;
|
|
||||||
|
|
||||||
GroupManager gm = new LiferayGroupManager();
|
|
||||||
String groupName = gm.getGroup(gm.getGroupIdFromInfrastructureScope(scopePerCurrentUrl)).getGroupName();
|
|
||||||
|
|
||||||
// we build up also a list that keeps track of the scopes (orgs) in which the user has role ADMIN/EDITOR
|
|
||||||
List<OrganizationBean> orgsInWhichAtLeastEditorRole = new ArrayList<OrganizationBean>();
|
|
||||||
role = UserUtil.getHighestRole(scopePerCurrentUrl, username, groupName, this, orgsInWhichAtLeastEditorRole);
|
|
||||||
|
|
||||||
// if he is an admin/editor preload:
|
|
||||||
// 1) organizations in which he can publish (the widget will find these info in session)
|
|
||||||
if(role){
|
|
||||||
httpSession.setAttribute(keyPerScopeOrganizations, orgsInWhichAtLeastEditorRole);
|
|
||||||
httpSession.setAttribute(keyPerScopeGroups, fetchUserGroups(scopePerCurrentUrl, username));
|
|
||||||
}
|
|
||||||
}catch(Exception e){
|
|
||||||
workspaceLogger.error("Unable to retrieve the role information for this user. Returning FALSE", e);
|
|
||||||
role = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// set role in session for this scope
|
|
||||||
httpSession.setAttribute(keyPerScopeRole, role);
|
|
||||||
|
|
||||||
workspaceLogger.info("Does the user have the right to publish on the catalogue? " + role);
|
|
||||||
|
|
||||||
// return false
|
|
||||||
return role;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch the list of ckan groups for which the user is member
|
|
||||||
* @param context
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private List<GroupBean> fetchUserGroups(String context, String username) {
|
|
||||||
|
|
||||||
List<GroupBean> toReturn = null;
|
|
||||||
workspaceLogger.info("Preloading user's groups");
|
|
||||||
|
|
||||||
try{
|
|
||||||
DataCatalogue catalogue = getCatalogue(context);
|
|
||||||
List<CkanGroup> ckanGroups = catalogue.getGroups();
|
|
||||||
String apiKey = catalogue.getApiKeyFromUsername(username);
|
|
||||||
toReturn = new ArrayList<GroupBean>();
|
|
||||||
|
|
||||||
// Members/Admin of the group
|
|
||||||
for (CkanGroup ckanGroup : ckanGroups) {
|
|
||||||
String role = catalogue.getRoleOfUserInGroup(username, ckanGroup.getName(), apiKey);
|
|
||||||
|
|
||||||
if(role == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
toReturn.add(new GroupBean(ckanGroup.getTitle(), ckanGroup.getName()));
|
|
||||||
}
|
|
||||||
workspaceLogger.debug("List of groups to return is " + toReturn);
|
|
||||||
|
|
||||||
}catch(Exception e){
|
|
||||||
workspaceLogger.error("Failed to preload user's groups");
|
|
||||||
}
|
|
||||||
|
|
||||||
return toReturn;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#markFolderAsPublicForFolderItemId(java.lang.String, boolean)
|
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#markFolderAsPublicForFolderItemId(java.lang.String, boolean)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -4,26 +4,12 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue;
|
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.models.RolesCkanGroupOrOrg;
|
|
||||||
import org.gcube.portlets.user.workspace.client.model.InfoContactModel;
|
import org.gcube.portlets.user.workspace.client.model.InfoContactModel;
|
||||||
import org.gcube.portlets.user.workspace.server.GWTWorkspaceServiceImpl;
|
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean;
|
|
||||||
import org.gcube.vomanagement.usermanagement.GroupManager;
|
|
||||||
import org.gcube.vomanagement.usermanagement.RoleManager;
|
|
||||||
import org.gcube.vomanagement.usermanagement.UserManager;
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
||||||
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
|
|
||||||
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
||||||
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
|
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
|
||||||
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
|
||||||
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
|
|
||||||
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
||||||
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
|
||||||
import org.gcube.vomanagement.usermanagement.model.GCubeRole;
|
|
||||||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||||
import org.gcube.vomanagement.usermanagement.model.GatewayRolesNames;
|
|
||||||
|
|
||||||
import eu.trentorise.opendata.jackan.model.CkanOrganization;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -161,169 +147,4 @@ public class UserUtil {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 the current scope
|
|
||||||
* @param username the current username
|
|
||||||
* @param groupName the current groupName
|
|
||||||
* @param workspaceInstance the workspace instance
|
|
||||||
* @param orgsInWhichAtLeastEditorRole the orgs in which admin/editor role
|
|
||||||
* @return true, if successful
|
|
||||||
*/
|
|
||||||
public static boolean getHighestRole(String currentScope, String username, String groupName, GWTWorkspaceServiceImpl workspaceInstance, List<OrganizationBean> orgsInWhichAtLeastEditorRole){
|
|
||||||
|
|
||||||
// base role as default value
|
|
||||||
boolean toReturn = false;
|
|
||||||
|
|
||||||
try{
|
|
||||||
|
|
||||||
UserManager userManager = new LiferayUserManager();
|
|
||||||
RoleManager roleManager = new LiferayRoleManager();
|
|
||||||
GroupManager groupManager = new LiferayGroupManager();
|
|
||||||
|
|
||||||
// user id
|
|
||||||
long userid = userManager.getUserId(username);
|
|
||||||
|
|
||||||
// retrieve current group id
|
|
||||||
long currentGroupId = groupManager.getGroupIdFromInfrastructureScope(currentScope);
|
|
||||||
|
|
||||||
logger.debug("Group id is " + currentGroupId + " and scope is " + currentScope);
|
|
||||||
|
|
||||||
// retrieve the flat list of organizations for the current user
|
|
||||||
List<GCubeGroup> groups = groupManager.listGroupsByUser(userid);
|
|
||||||
|
|
||||||
// root (so check into the root, the VOs and the VRES)
|
|
||||||
if(groupManager.isRootVO(currentGroupId)){
|
|
||||||
|
|
||||||
logger.info("The current scope is the Root Vo, so the list of organizations of the user " + username + " is " + groups);
|
|
||||||
|
|
||||||
for (GCubeGroup gCubeGroup : groups) {
|
|
||||||
|
|
||||||
// get the name of this group
|
|
||||||
String gCubeGroupName = gCubeGroup.getGroupName();
|
|
||||||
|
|
||||||
// get the role of the users in this group
|
|
||||||
List<GCubeRole> roles = roleManager.listRolesByUserAndGroup(userid, groupManager.getGroupId(gCubeGroupName));
|
|
||||||
|
|
||||||
// get highest role
|
|
||||||
RolesCkanGroupOrOrg correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles);
|
|
||||||
|
|
||||||
if(correspondentRoleToCheck.equals(RolesCkanGroupOrOrg.MEMBER))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
checkIfRoleIsSetInCkanInstance(username, gCubeGroupName, correspondentRoleToCheck, workspaceInstance,
|
|
||||||
groupManager, gCubeGroup.getGroupId(), orgsInWhichAtLeastEditorRole);
|
|
||||||
}
|
|
||||||
|
|
||||||
}else if(groupManager.isVO(currentGroupId)){
|
|
||||||
|
|
||||||
logger.debug("The list of organizations of the user " + username + " to scan is the one under the VO " + groupName);
|
|
||||||
|
|
||||||
for (GCubeGroup gCubeGroup : groups) {
|
|
||||||
|
|
||||||
// if the gCubeGroup is not under the VO or it is not the VO continue
|
|
||||||
if(currentGroupId != gCubeGroup.getParentGroupId() || currentGroupId != gCubeGroup.getGroupId())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
String gCubeGroupName = gCubeGroup.getGroupName();
|
|
||||||
|
|
||||||
List<GCubeRole> roles = roleManager.listRolesByUserAndGroup(userid, groupManager.getGroupId(gCubeGroupName));
|
|
||||||
|
|
||||||
// get highest role
|
|
||||||
RolesCkanGroupOrOrg correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles);
|
|
||||||
|
|
||||||
if(correspondentRoleToCheck.equals(RolesCkanGroupOrOrg.MEMBER))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
checkIfRoleIsSetInCkanInstance(username, gCubeGroupName, correspondentRoleToCheck, workspaceInstance,
|
|
||||||
groupManager, gCubeGroup.getGroupId(), orgsInWhichAtLeastEditorRole);
|
|
||||||
}
|
|
||||||
|
|
||||||
}else if(groupManager.isVRE(currentGroupId)){
|
|
||||||
List<GCubeRole> roles = roleManager.listRolesByUserAndGroup(userManager.getUserId(username), groupManager.getGroupId(groupName));
|
|
||||||
|
|
||||||
logger.debug("The current scope is the vre " + groupName);
|
|
||||||
|
|
||||||
// get highest role
|
|
||||||
RolesCkanGroupOrOrg correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles);
|
|
||||||
|
|
||||||
checkIfRoleIsSetInCkanInstance(username, groupName, correspondentRoleToCheck, workspaceInstance,
|
|
||||||
groupManager, currentGroupId, orgsInWhichAtLeastEditorRole);
|
|
||||||
}
|
|
||||||
}catch(Exception e){
|
|
||||||
logger.error("Unable to retrieve the role information for this user. Returning false", e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//ok, somewhere he is admin/editor
|
|
||||||
if(orgsInWhichAtLeastEditorRole.size() > 0)
|
|
||||||
toReturn = true;
|
|
||||||
|
|
||||||
// return the role
|
|
||||||
logger.debug("Returning role " + toReturn + " for user " + username);
|
|
||||||
return toReturn;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the role admin is set or must be set into the ckan instance at this scope.
|
|
||||||
*
|
|
||||||
* @param username the username
|
|
||||||
* @param gCubeGroupName the g cube group name
|
|
||||||
* @param correspondentRoleToCheck the correspondent role to check
|
|
||||||
* @param workspaceInstance the workspace instance
|
|
||||||
* @param groupManager the group manager
|
|
||||||
* @param groupId the group id
|
|
||||||
* @param orgsInWhichAdminRole the orgs in which admin role
|
|
||||||
* @throws UserManagementSystemException the user management system exception
|
|
||||||
* @throws GroupRetrievalFault the group retrieval fault
|
|
||||||
*/
|
|
||||||
private static void checkIfRoleIsSetInCkanInstance(String username,
|
|
||||||
String gCubeGroupName,
|
|
||||||
RolesCkanGroupOrOrg correspondentRoleToCheck,
|
|
||||||
GWTWorkspaceServiceImpl workspaceInstance,
|
|
||||||
GroupManager groupManager, long groupId, List<OrganizationBean> orgsInWhichAdminRole) throws UserManagementSystemException, GroupRetrievalFault {
|
|
||||||
|
|
||||||
// with this invocation, we check if the role is present in ckan and if it is not it will be added
|
|
||||||
DataCatalogue catalogue = workspaceInstance.getCatalogue(groupManager.getInfrastructureScope(groupId));
|
|
||||||
|
|
||||||
// if there is an instance of ckan in this scope..
|
|
||||||
if(catalogue != null){
|
|
||||||
boolean res = catalogue.checkRoleIntoOrganization(username, gCubeGroupName, correspondentRoleToCheck);
|
|
||||||
|
|
||||||
if(res && !correspondentRoleToCheck.equals(RolesCkanGroupOrOrg.MEMBER)){
|
|
||||||
// get the orgs of the user
|
|
||||||
List<CkanOrganization> ckanOrgs = catalogue.getOrganizationsByUser(username);
|
|
||||||
for (CkanOrganization ckanOrganization : ckanOrgs) {
|
|
||||||
if(ckanOrganization.getName().equals(gCubeGroupName.toLowerCase())){//|| ckanOrganization.getName().equals(CKanUtilsImpl.PRODUCTION_CKAN_ORGNAME_ROOT)){
|
|
||||||
orgsInWhichAdminRole.add(new OrganizationBean(ckanOrganization.getTitle(), ckanOrganization.getName()));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}else
|
|
||||||
logger.error("It seems there is no ckan instance into scope " + groupManager.getInfrastructureScope(groupId));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve the ckan role among a list of liferay roles
|
|
||||||
* @param roles
|
|
||||||
* @return MEMBER/EDITOR/ADMIN role
|
|
||||||
*/
|
|
||||||
private static RolesCkanGroupOrOrg getLiferayHighestRoleInOrg(
|
|
||||||
List<GCubeRole> roles) {
|
|
||||||
|
|
||||||
// NOTE: it is supposed that there is just one role for this person correspondent to the one in the catalog
|
|
||||||
for (GCubeRole gCubeRole : roles) {
|
|
||||||
if(gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesNames.CATALOGUE_ADMIN.getRoleName())){
|
|
||||||
return RolesCkanGroupOrOrg.ADMIN;
|
|
||||||
}
|
|
||||||
if(gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesNames.CATALOGUE_EDITOR.getRoleName())){
|
|
||||||
return RolesCkanGroupOrOrg.EDITOR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return RolesCkanGroupOrOrg.MEMBER;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,17 +13,15 @@ public class UserBean implements Serializable {
|
||||||
private String firstName;
|
private String firstName;
|
||||||
private String lastName;
|
private String lastName;
|
||||||
private String email;
|
private String email;
|
||||||
private Boolean cataloguePermission;
|
|
||||||
|
|
||||||
public UserBean() {
|
public UserBean() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserBean(String username, String firstName, String lastName, String email, Boolean cataloguePermission) {
|
public UserBean(String username, String firstName, String lastName, String email) {
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.firstName = firstName;
|
this.firstName = firstName;
|
||||||
this.lastName = lastName;
|
this.lastName = lastName;
|
||||||
this.email = email;
|
this.email = email;
|
||||||
this.cataloguePermission = cataloguePermission;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,15 +61,6 @@ public class UserBean implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the cataloguePermission
|
|
||||||
*/
|
|
||||||
public Boolean getCataloguePermission() {
|
|
||||||
|
|
||||||
return cataloguePermission;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param username the username to set
|
* @param username the username to set
|
||||||
*/
|
*/
|
||||||
|
@ -108,19 +97,6 @@ public class UserBean implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param cataloguePermission the cataloguePermission to set
|
|
||||||
*/
|
|
||||||
public void setCataloguePermission(Boolean cataloguePermission) {
|
|
||||||
|
|
||||||
this.cataloguePermission = cataloguePermission;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean hasCataloguePermission() {
|
|
||||||
return cataloguePermission;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see java.lang.Object#toString()
|
* @see java.lang.Object#toString()
|
||||||
*/
|
*/
|
||||||
|
@ -136,8 +112,6 @@ public class UserBean implements Serializable {
|
||||||
builder.append(lastName);
|
builder.append(lastName);
|
||||||
builder.append(", email=");
|
builder.append(", email=");
|
||||||
builder.append(email);
|
builder.append(email);
|
||||||
builder.append(", cataloguePermission=");
|
|
||||||
builder.append(cataloguePermission);
|
|
||||||
builder.append("]");
|
builder.append("]");
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue