ref 13226:StorageHub - Update workspace-sharing-widget to SH

https://support.d4science.org/issues/13226

Fixed share folder with multiple users

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-sharing-widget@179300 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2019-05-07 13:02:53 +00:00
parent a869b7aa14
commit 22fcb1a056
1 changed files with 52 additions and 37 deletions

View File

@ -492,7 +492,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
logger.debug("Folder is not shared"); logger.debug("Folder is not shared");
Set<String> logins = new HashSet<>(listLogin); Set<String> logins = new HashSet<>(listLogin);
logger.debug("Share logins: " + logins); logger.debug("Share logins: " + logins);
folderContainer=folderContainer.share(logins, getAccessType(acl)); folderContainer = folderContainer.share(logins, getAccessType(acl));
logger.debug("Shared done"); logger.debug("Shared done");
created = true; created = true;
NotificationsProducer np = getNotificationProducer(this.getThreadLocalRequest()); NotificationsProducer np = getNotificationProducer(this.getThreadLocalRequest());
@ -717,24 +717,31 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
} }
private List<InfoContactModel> retrieveAdminContactsFromACLs(FolderContainer folderContainer) throws Exception { private List<InfoContactModel> retrieveAdminContactsFromACLs(FolderContainer folderContainer) throws Exception {
List<ACL> acls = folderContainer.getAcls(); if (folderContainer == null) {
logger.debug("Retrieved acls: " + acls); logger.debug("FolderContainer is null");
List<String> admins = new ArrayList<>(); return new ArrayList<InfoContactModel>();
for (ACL acl : acls) { } else {
boolean isAdmin = false; logger.debug("Retrieve Admins for: " + folderContainer.get());
for (AccessType accesstype : acl.getAccessTypes()) { List<String> admins = new ArrayList<>();
if (accesstype != null && accesstype == AccessType.ADMINISTRATOR) {
isAdmin = true; List<ACL> acls = folderContainer.getAcls();
break; logger.debug("Retrieved acls: " + acls);
for (ACL acl : acls) {
boolean isAdmin = false;
for (AccessType accesstype : acl.getAccessTypes()) {
if (accesstype != null && accesstype == AccessType.ADMINISTRATOR) {
isAdmin = true;
break;
}
}
if (isAdmin) {
admins.add(acl.getPricipal());
} }
} }
if (isAdmin) { logger.debug("Retrieved admins list: " + admins);
admins.add(acl.getPricipal()); GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder();
} return builder.buildGxtInfoContactsFromPortalLogins(admins);
} }
logger.debug("Retrieved admins list: " + admins);
GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder();
return builder.buildGxtInfoContactsFromPortalLogins(admins);
} }
// /** // /**
@ -1088,18 +1095,24 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder(); GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder();
List<InfoContactModel> listContactsModel = builder.buildGXTListContactsModelFromUserModel(info); List<InfoContactModel> listContactsModel = builder.buildGXTListContactsModelFromUserModel(info);
boolean ownerFound = false;
for (InfoContactModel icm : listContactsModel) { for (InfoContactModel icm : listContactsModel) {
if (icm.getLogin().compareTo(folderItem.getOwner()) == 0) { if (icm.getLogin().compareTo(folderItem.getOwner()) == 0) {
logger.debug("Retrieved: " + icm); logger.debug("Owner Retrieved: " + icm);
owner = icm; owner = icm;
ownerFound = true;
break;
} }
} }
logger.debug("Owner not found from user model!"); if (!ownerFound) {
owner = new InfoContactModel(folderItem.getOwner(), folderItem.getOwner(), folderItem.getOwner(), logger.debug("Owner not found from user model!");
false); owner = new InfoContactModel(folderItem.getOwner(), folderItem.getOwner(),
folderItem.getOwner(), false);
}
} else { } else {
logger.debug("Owner not found from item"); logger.debug("Owner not found from item");
owner = new InfoContactModel(); owner = null;
} }
String username = info.getUsername(); String username = info.getUsername();
@ -1108,22 +1121,20 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
return new AllowAccess(itemId, true, "The folder is already public. Access granted to " + username, return new AllowAccess(itemId, true, "The folder is already public. Access granted to " + username,
null); null);
} }
logger.info("owner of: " + folderItem.getName() + " is: " + owner); logger.info("The owner of: " + folderItem.getName() + " is: " + owner);
logger.info("current context user: " + username); logger.info("The current context user: " + username);
if (owner.getLogin().compareToIgnoreCase(username) == 0) { if (owner != null && owner.getLogin().compareToIgnoreCase(username) == 0) {
logger.info("Access to Folder Link " + folderItem.getName() + " granted, " + username logger.info("Access to Folder Link " + folderItem.getName() + " granted, " + username
+ " is the owner of: " + itemId); + " is the owner of: " + itemId);
return new AllowAccess(itemId, true, return new AllowAccess(itemId, true,
info.getUserFullName() + " is the owner of: " + folderItem.getName(), null); info.getUserFullName() + " is the owner of: " + folderItem.getName(), null);
} }
try { try {
List<InfoContactModel> admins = null; List<InfoContactModel> admins = null;
if (folderItem.isShared()) { if (folderItem.isShared()) {
if (folderItem instanceof SharedFolder) { if (folderItem instanceof SharedFolder) {
admins = retrieveAdminContactsFromACLs(folderContainer); admins = retrieveAdminContactsFromACLs(folderContainer);
} else { } else {
FolderContainer rootSharedFolderContainer = folderContainer.getRootSharedFolder(); FolderContainer rootSharedFolderContainer = folderContainer.getRootSharedFolder();
FolderItem rootSharedFolder = rootSharedFolderContainer.get(); FolderItem rootSharedFolder = rootSharedFolderContainer.get();
@ -1142,13 +1153,19 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
"The item requested is not a valid shared folder : [itemId=" + itemId + "]"); "The item requested is not a valid shared folder : [itemId=" + itemId + "]");
} }
for (InfoContactModel infoContactModel : admins) { if (admins != null) {
if (infoContactModel.getLogin().compareToIgnoreCase(username) == 0) { for (InfoContactModel infoContactModel : admins) {
logger.info("Access to Folder Link " + logger.getName() + " granted, " + username if (infoContactModel.getLogin().compareToIgnoreCase(username) == 0) {
+ " is the admin of: " + itemId); logger.info("Access to Folder Link " + logger.getName() + " granted, " + username
return new AllowAccess(itemId, true, + " is the admin of: " + itemId);
info.getUserFullName() + " is the admin of: " + folderItem.getName(), null); return new AllowAccess(itemId, true,
info.getUserFullName() + " is the admin of: " + folderItem.getName(), null);
}
} }
} else {
return new AllowAccess(itemId, false,
"You have not permission to get Folder Link, you must be owner or administrator to the folder", "Permission not found");
} }
} catch (Exception e) { } catch (Exception e) {
return new AllowAccess(itemId, false, return new AllowAccess(itemId, false,
@ -1163,9 +1180,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
return new AllowAccess(itemId, false, "The item is not a folder", null); return new AllowAccess(itemId, false, "The item is not a folder", null);
} }
} catch ( } catch (Exception e) {
Exception e) {
logger.error("Error in server FormattedGcubeItemProperties: " + e.getLocalizedMessage(), e); logger.error("Error in server FormattedGcubeItemProperties: " + e.getLocalizedMessage(), e);
String error = "Error when reading access policy to Folder Link: " + itemId + ", Refresh and try again"; String error = "Error when reading access policy to Folder Link: " + itemId + ", Refresh and try again";
throw new Exception(error, e); throw new Exception(error, e);