ref 17169: Selection of users in the Sharing panel
https://support.d4science.org/issues/17169 Updated Set Adminastrators to support StorageHub calls git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-sharing-widget@181502 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
bb814fc3ea
commit
02e83870c3
|
@ -2,6 +2,7 @@ package org.gcube.portlets.widgets.workspacesharingwidget.client.rpc;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.portlets.widgets.workspacesharingwidget.shared.ACL_TYPE;
|
||||
import org.gcube.portlets.widgets.workspacesharingwidget.shared.AllowAccess;
|
||||
import org.gcube.portlets.widgets.workspacesharingwidget.shared.CredentialModel;
|
||||
import org.gcube.portlets.widgets.workspacesharingwidget.shared.ExtendedWorkspaceACL;
|
||||
|
@ -62,7 +63,7 @@ public interface WorkspaceSharingService extends RemoteService {
|
|||
|
||||
void setACLs(String folderId, List<String> listLogins, String aclType) throws Exception;
|
||||
|
||||
void updateACLForVREbyGroupName(String folderId, String aclType) throws Exception;
|
||||
void updateACLForVREbyGroupName(String folderId, ACL_TYPE aclType) throws Exception;
|
||||
|
||||
ReportAssignmentACL validateACLToUser(String folderId, List<String> listLogins, String aclType) throws Exception;
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.gcube.portlets.widgets.workspacesharingwidget.client.rpc;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.portlets.widgets.workspacesharingwidget.shared.ACL_TYPE;
|
||||
import org.gcube.portlets.widgets.workspacesharingwidget.shared.AllowAccess;
|
||||
import org.gcube.portlets.widgets.workspacesharingwidget.shared.CredentialModel;
|
||||
import org.gcube.portlets.widgets.workspacesharingwidget.shared.ExtendedWorkspaceACL;
|
||||
|
@ -61,7 +62,7 @@ public interface WorkspaceSharingServiceAsync {
|
|||
|
||||
void setACLs(String folderId, List<String> listLogins, String aclType, AsyncCallback<Void> callback);
|
||||
|
||||
void updateACLForVREbyGroupName(String folderId, String aclType, AsyncCallback<Void> callback);
|
||||
void updateACLForVREbyGroupName(String folderId, ACL_TYPE aclType, AsyncCallback<Void> callback);
|
||||
|
||||
void validateACLToUser(String folderId, List<String> listLogins, String aclType,
|
||||
AsyncCallback<ReportAssignmentACL> callback);
|
||||
|
|
|
@ -12,15 +12,7 @@ import java.util.Set;
|
|||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
|
||||
import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
||||
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder;
|
||||
import org.gcube.common.homelibrary.home.workspace.accessmanager.ACLType;
|
||||
import org.gcube.common.portal.PortalContext;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.storagehub.client.dsl.FileContainer;
|
||||
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
||||
import org.gcube.common.storagehub.client.dsl.ItemContainer;
|
||||
|
@ -44,6 +36,7 @@ import org.gcube.portlets.widgets.workspacesharingwidget.server.util.PortalConte
|
|||
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.ScopeUtility;
|
||||
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.UserUtil;
|
||||
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.WsUtil;
|
||||
import org.gcube.portlets.widgets.workspacesharingwidget.shared.ACL_TYPE;
|
||||
import org.gcube.portlets.widgets.workspacesharingwidget.shared.AllowAccess;
|
||||
import org.gcube.portlets.widgets.workspacesharingwidget.shared.CredentialModel;
|
||||
import org.gcube.portlets.widgets.workspacesharingwidget.shared.ExtendedWorkspaceACL;
|
||||
|
@ -106,20 +99,23 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
|
|||
return !WsUtil.isWithinPortal(); // IS NOT INTO PORTAL
|
||||
}
|
||||
|
||||
private Workspace getWorkspace(HttpServletRequest httpServletRequest)
|
||||
throws org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException,
|
||||
org.gcube.common.homelibrary.home.exceptions.InternalErrorException, HomeNotFoundException {
|
||||
|
||||
logger.trace("Get Workspace");
|
||||
PortalContextInfo info = WsUtil.getPortalContext(this.getThreadLocalRequest());
|
||||
logger.trace("PortalContextInfo: " + info);
|
||||
|
||||
ScopeProvider.instance.set(info.getCurrentScope());
|
||||
logger.trace("Scope provider instancied");
|
||||
|
||||
Workspace workspace = HomeLibrary.getUserWorkspace(info.getUsername());
|
||||
return workspace;
|
||||
}
|
||||
/*
|
||||
* private Workspace getWorkspace(HttpServletRequest httpServletRequest)
|
||||
* throws org.gcube.common.homelibrary.home.workspace.exceptions.
|
||||
* WorkspaceFolderNotFoundException,
|
||||
* org.gcube.common.homelibrary.home.exceptions.InternalErrorException,
|
||||
* HomeNotFoundException {
|
||||
*
|
||||
* logger.trace("Get Workspace"); PortalContextInfo info =
|
||||
* WsUtil.getPortalContext(this.getThreadLocalRequest());
|
||||
* logger.trace("PortalContextInfo: " + info);
|
||||
*
|
||||
* ScopeProvider.instance.set(info.getCurrentScope());
|
||||
* logger.trace("Scope provider instancied");
|
||||
*
|
||||
* Workspace workspace = HomeLibrary.getUserWorkspace(info.getUsername());
|
||||
* return workspace; }
|
||||
*/
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
|
@ -361,7 +357,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
|
|||
*/
|
||||
@Override
|
||||
public InfoContactModel getOwnerByItemId(String itemId) throws Exception {
|
||||
//TODO
|
||||
|
||||
LocalDateTime startTime = LocalDateTime.now();
|
||||
logger.info("Call getOwnerByItemId() Start Time: " + startTime.format(formatter));
|
||||
|
||||
|
@ -385,8 +381,9 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
|
|||
GCubeUser curr = um.getUserByUsername(item.getOwner());
|
||||
|
||||
if (curr != null) {
|
||||
InfoContactModel infoContactModel = new InfoContactModel(String.valueOf(curr.getUserId()), curr.getUsername(), curr.getFullname(),
|
||||
extractDomainFromEmail(curr.getEmail()), false);
|
||||
InfoContactModel infoContactModel = new InfoContactModel(String.valueOf(curr.getUserId()),
|
||||
curr.getUsername(), curr.getFullname(), extractDomainFromEmail(curr.getEmail()),
|
||||
false);
|
||||
logger.debug("Owner found: " + infoContactModel);
|
||||
return infoContactModel;
|
||||
}
|
||||
|
@ -810,7 +807,6 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
|
|||
try {
|
||||
logger.info("Call addAdministratorsByFolderId(): [itemId=" + itemId + ", listContactLogins"
|
||||
+ listContactLogins + "]");
|
||||
// logger.info("This function is not available in StorageHub!");
|
||||
if (itemId == null || listContactLogins == null || listContactLogins.size() == 0)
|
||||
return false;
|
||||
|
||||
|
@ -818,9 +814,47 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
|
|||
OpenResolver openResolverForItem = shc.open(itemId);
|
||||
FolderContainer folderContainer = openResolverForItem.asFolder();
|
||||
FolderItem folderItem = folderContainer.get();
|
||||
|
||||
if (folderItem.isShared()) {
|
||||
if (folderItem instanceof SharedFolder) {
|
||||
return addAdminstratorByWorkspace(folderItem.getId(), listContactLogins);
|
||||
logger.debug("Folder type: SharedFolder");
|
||||
String currentUser = getMyLogin();
|
||||
logger.debug("Current User: " + currentUser);
|
||||
|
||||
Set<String> alreadyAdministrators = new HashSet<>();
|
||||
|
||||
List<ACL> acls = folderContainer.getAcls();
|
||||
for (ACL acl : acls) {
|
||||
if (acl.getPricipal().compareTo(currentUser) != 0) {
|
||||
for (AccessType accessType : acl.getAccessTypes()) {
|
||||
if (AccessType.ADMINISTRATOR.compareTo(accessType) == 0) {
|
||||
alreadyAdministrators.add(acl.getPricipal());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("Update ACL for add Administrators");
|
||||
for (String user : listContactLogins) {
|
||||
if (currentUser.compareTo(user) != 0) {
|
||||
folderContainer = folderContainer.changeAcls(user, AccessType.ADMINISTRATOR);
|
||||
}
|
||||
}
|
||||
logger.debug("Update Administrators done");
|
||||
|
||||
if (!alreadyAdministrators.isEmpty()) {
|
||||
alreadyAdministrators.removeAll(listContactLogins);
|
||||
if (!alreadyAdministrators.isEmpty()) {
|
||||
logger.debug("Update to WriteOwner the users: " + alreadyAdministrators);
|
||||
for (String user : alreadyAdministrators) {
|
||||
folderContainer = folderContainer.changeAcls(user, AccessType.WRITE_OWNER);
|
||||
}
|
||||
logger.debug("Update to WriteOwner done");
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("Administrators Updated");
|
||||
return true;
|
||||
|
||||
} else {
|
||||
String error = "Attention, the set administrators operation can only be done on the root shared folder. "
|
||||
|
@ -842,67 +876,6 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
|
|||
|
||||
}
|
||||
|
||||
private boolean addAdminstratorByWorkspace(String itemId, List<String> listContactLogins) throws Exception {
|
||||
try {
|
||||
Workspace workspace = getWorkspace(this.getThreadLocalRequest());
|
||||
WorkspaceItem item = workspace.getItem(itemId);
|
||||
logger.info("Adding administator/s to folder: " + itemId);
|
||||
|
||||
if (item != null && item.getType().equals(WorkspaceItemType.SHARED_FOLDER)) {
|
||||
WorkspaceSharedFolder sharedFolder = (WorkspaceSharedFolder) item;
|
||||
|
||||
// retrieving old administrators list
|
||||
// GWTWorkspaceSharingBuilder builder = new
|
||||
// GWTWorkspaceSharingBuilder();
|
||||
// logger.info("Retrieving old administator/s..");
|
||||
// List<InfoContactModel> oldAdmins = builder
|
||||
// .buildGxtInfoContactsFromPortalLogins(sharedFolder.getAdministrators());
|
||||
// logger.info("Retrieving old administator/s are/is:" +
|
||||
// oldAdmins.size());
|
||||
|
||||
logger.info("Setting administators: " + listContactLogins);
|
||||
sharedFolder.setAdmins(listContactLogins);
|
||||
|
||||
/*
|
||||
* logger.info("Converting new administator/s..");
|
||||
* List<InfoContactModel> newAdmins =
|
||||
* builder.buildGxtInfoContactsFromPortalLogins(
|
||||
* listContactLogins); NotificationsProducer np =
|
||||
* getNotificationProducer();
|
||||
*
|
||||
* logger.
|
||||
* info("Sending notifications downgrade/upgrade administator/s.."
|
||||
* ); DifferenceBetweenInfoContactModel diff1 = new
|
||||
* DifferenceBetweenInfoContactModel(oldAdmins, newAdmins);
|
||||
* List<InfoContactModel> contactsDowngrade =
|
||||
* diff1.getDifferentsContacts();
|
||||
*
|
||||
* for (InfoContactModel infoContactModel : contactsDowngrade) {
|
||||
* np.notifyAdministratorDowngrade(infoContactModel,
|
||||
* sharedFolder); }
|
||||
*
|
||||
* DifferenceBetweenInfoContactModel diff2 = new
|
||||
* DifferenceBetweenInfoContactModel(newAdmins, oldAdmins);
|
||||
* List<InfoContactModel> contactsUpgrade =
|
||||
* diff2.getDifferentsContacts();
|
||||
*
|
||||
* for (InfoContactModel infoContactModel : contactsUpgrade) {
|
||||
* np.notifyAdministratorUpgrade(infoContactModel,
|
||||
* sharedFolder); }
|
||||
*/
|
||||
|
||||
return true;
|
||||
|
||||
} else
|
||||
throw new Exception("The item is null or not instanceof " + WorkspaceItemType.SHARED_FOLDER);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Error in addAdminstratorByWorkspace() : " + e.getLocalizedMessage(), e);
|
||||
throw new Exception("Error in set administrators operation for this item.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private List<InfoContactModel> retrieveAdminContactsFromACLs(FolderContainer folderContainer) throws Exception {
|
||||
if (folderContainer == null) {
|
||||
logger.debug("FolderContainer is null");
|
||||
|
@ -1740,37 +1713,86 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
|
|||
* the exception
|
||||
*/
|
||||
@Override
|
||||
public void updateACLForVREbyGroupName(String folderId, String aclType) throws Exception {
|
||||
public void updateACLForVREbyGroupName(String folderId, ACL_TYPE aclType) throws Exception {
|
||||
try {
|
||||
// TODO
|
||||
logger.debug("UpdateACLForVREbyGroupName()");
|
||||
logger.debug("folderId: " + folderId);
|
||||
logger.debug("ACL type is: " + aclType);
|
||||
|
||||
if (folderId == null)
|
||||
if (folderId == null || folderId.isEmpty()) {
|
||||
throw new Exception("Folder id is null");
|
||||
|
||||
logger.trace("Updating ACL to VRE FOLDER id: " + folderId);
|
||||
logger.trace("ACL type is: " + aclType);
|
||||
logger.trace("Get Workspace");
|
||||
PortalContextInfo info = WsUtil.getPortalContext(this.getThreadLocalRequest());
|
||||
|
||||
logger.trace("PortalContextInfo: " + info);
|
||||
|
||||
ScopeProvider.instance.set(info.getCurrentScope());
|
||||
logger.trace("Scope provider set: " + info.getCurrentScope());
|
||||
|
||||
Workspace workspace = HomeLibrary.getUserWorkspace(info.getUsername());
|
||||
WorkspaceItem wsItem = workspace.getItem(folderId);
|
||||
|
||||
if (wsItem.isShared() && wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER)) {
|
||||
WorkspaceSharedFolder ite = (WorkspaceSharedFolder) wsItem;
|
||||
// PATCH TODO TEMPORARY SOLUTION
|
||||
if (ite.isVreFolder()) {
|
||||
List<String> groupName = new ArrayList<String>();
|
||||
groupName.add(wsItem.getName());
|
||||
ite.setACL(groupName, ACLType.valueOf(aclType));
|
||||
}
|
||||
} else
|
||||
throw new Exception("Source item is not shared or shared folder");
|
||||
|
||||
logger.trace("Updating ACL completed, retuning");
|
||||
if (aclType == null) {
|
||||
throw new Exception("ACLType parameter is invalid");
|
||||
}
|
||||
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
OpenResolver openResolverForItem = shc.open(folderId);
|
||||
FolderContainer folderContainer = openResolverForItem.asFolder();
|
||||
FolderItem folderItem = folderContainer.get();
|
||||
|
||||
if (folderItem.isShared()) {
|
||||
if (folderItem instanceof SharedFolder) {
|
||||
logger.debug("Folder type: SharedFolder");
|
||||
SharedFolder sharedFolder = (SharedFolder) folderItem;
|
||||
if (sharedFolder.isVreFolder()) {
|
||||
logger.debug("The folder is a VreFolder");
|
||||
|
||||
String currentUser = getMyLogin();
|
||||
logger.debug("Current User: " + currentUser);
|
||||
|
||||
AccessType selectedAccessType = null;
|
||||
|
||||
switch (aclType) {
|
||||
case ADMINISTRATOR:
|
||||
selectedAccessType = AccessType.ADMINISTRATOR;
|
||||
break;
|
||||
case READ_ONLY:
|
||||
selectedAccessType = AccessType.READ_ONLY;
|
||||
break;
|
||||
case WRITE_ALL:
|
||||
selectedAccessType = AccessType.WRITE_ALL;
|
||||
break;
|
||||
case WRITE_OWNER:
|
||||
selectedAccessType = AccessType.WRITE_OWNER;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (selectedAccessType == null) {
|
||||
throw new Exception("ACLType parameter is invalid");
|
||||
}
|
||||
|
||||
List<ACL> acls = folderContainer.getAcls();
|
||||
for (ACL acl : acls) {
|
||||
if (acl.getPricipal().compareTo(currentUser) != 0) {
|
||||
folderContainer = folderContainer.changeAcls(acl.getPricipal(), selectedAccessType);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
String error = "Attention, the operation can only be done on the VRE folder. "
|
||||
+ "Please, select the VRE folder if you want to set the ACL.";
|
||||
logger.error(error);
|
||||
throw new Exception(error);
|
||||
}
|
||||
} else {
|
||||
String error = "Attention, the operation can only be done on the root VRE folder. "
|
||||
+ "Please, select the root VRE folder if you want to set the ACL.";
|
||||
logger.error(error);
|
||||
throw new Exception(error);
|
||||
|
||||
}
|
||||
} else {
|
||||
logger.error("The item requested is not a valid shared folder : [itemId=" + folderId + "]");
|
||||
throw new Exception("The item requested is not a valid shared folder. Impossible set the ACL.");
|
||||
}
|
||||
|
||||
logger.debug("ACL updated");
|
||||
} catch (Exception e) {
|
||||
logger.error("Error in set ACLs", e);
|
||||
String error = "Error updating the permissions. " + e.getMessage();
|
||||
|
|
Loading…
Reference in New Issue