Feature #16461, Invite member ... prevent the system from inviting people having an already registered email in VRE

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/invite-friends-widget@178904 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2019-04-08 13:10:13 +00:00
parent fc88d1fe4e
commit 45f17e1153
5 changed files with 76 additions and 19 deletions

View File

@ -14,7 +14,7 @@
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>invite-friends-widget</artifactId>
<packaging>jar</packaging>
<version>1.5.0-SNAPSHOT</version>
<version>1.6.0-SNAPSHOT</version>
<name>gCube Invites widget</name>
<description>
gCube Invites widget Widget is a GWT Widget that can be used to automatically send invites to VRE users

View File

@ -10,5 +10,6 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
*/
@RemoteServiceRelativePath("greet")
public interface InviteService extends RemoteService {
Boolean accountExistInVRE(String email);
InviteOperationResult sendInvite(String name, String lastName, String email) throws IllegalArgumentException;
}

View File

@ -8,5 +8,5 @@ public interface InviteServiceAsync {
void sendInvite(String name, String lastName, String email,
AsyncCallback<InviteOperationResult> callback);
void accountExistInVRE(String email, AsyncCallback<Boolean> callback);
}

View File

@ -26,6 +26,7 @@ import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
@ -64,47 +65,62 @@ public class FormViewImpl extends Composite implements FormView, Editor<FormView
ControlGroup nameGroup;
@UiField
ControlGroup feedbackGroup;
public FormViewImpl(Delegate delegate) {
super();
this.delegate = delegate;
initWidget(uiBinder.createAndBindUi(this));
driver.initialize(this);
driver.edit(new UserDetails());
email.addKeyDownHandler(new KeyDownHandler() {
@Override
public void onKeyDown(KeyDownEvent event) {
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER)
openModal.click();
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER)
openModal.click();
}
});
name.addKeyDownHandler(new KeyDownHandler() {
@Override
public void onKeyDown(KeyDownEvent event) {
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER)
sendInvite.click();
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER)
sendInvite.click();
}
});
sendInvite.setEnabled(true);
}
@UiHandler("openModal")
void onUserClick(ClickEvent event) {
if (!delegate.onSendClick()) {
sendInvite.setEnabled(true);
feedback.setText("This gateway will send the invitation email to: "+email.getText() + " and put you in cc. It will never email your contacts without your consent.");
name.setText("");
modalWindow.show();
Timer t = new Timer() {
service.accountExistInVRE(email.getText(), new AsyncCallback<Boolean>() {
@Override
public void run() {
name.setFocus(true);
public void onFailure(Throwable caught) {
Window.alert("Ops, There were problems communicating with the server, please retry later or report this issue to http://support.d4science.org");
}
};
t.schedule(1000);
@Override
public void onSuccess(Boolean userAccountExists) {
if (userAccountExists) {
Window.alert("A user with the same email already exists in this VRE, the invite cannot be sent.");
} else {
sendInvite.setEnabled(true);
feedback.setText("This gateway will send the invitation email to: "+email.getText() + " and put you in cc. It will never email your contacts without your consent.");
name.setText("");
modalWindow.show();
Timer t = new Timer() {
@Override
public void run() {
name.setFocus(true);
}
};
t.schedule(1000);
}
}
});
}
}

View File

@ -1,11 +1,20 @@
package org.gcube.portlets.widgets.inviteswidget.server;
import java.util.List;
import org.gcube.common.portal.PortalContext;
import org.gcube.portal.databook.shared.InviteOperationResult;
import org.gcube.portal.invites.InvitesManager;
import org.gcube.portlets.widgets.inviteswidget.client.InviteService;
import org.gcube.vomanagement.usermanagement.GroupManager;
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.UserRetrievalFault;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -15,6 +24,8 @@ import com.google.gwt.user.server.rpc.RemoteServiceServlet;
public class InviteServiceImpl extends RemoteServiceServlet implements InviteService {
private final static Logger _log = LoggerFactory.getLogger(InviteServiceImpl.class);
private final static GroupManager GM = new LiferayGroupManager();
private final static UserManager UM = new LiferayUserManager();
/**
*
*/
@ -36,4 +47,33 @@ public class InviteServiceImpl extends RemoteServiceServlet implements InviteSer
return InvitesManager.getInstance().sendInvite(this.getThreadLocalRequest(), portalSenderEmail, portalUrl, name, lastName, lowercaseEmail, vreDescription);
}
@Override
public Boolean accountExistInVRE(String email) {
long groupId = PortalContext.getConfiguration().getCurrentGroupId(getThreadLocalRequest());
try {
if (!GM.isVRE(groupId)) {
return false; //if deployed not in a VRE the check is not performed
}
else {
try {
GCubeUser theUser2Check = UM.getUserByEmail(email);
List<GCubeUser> theVREUsers = UM.listUsersByGroup(groupId, false);
for (GCubeUser vreUser : theVREUsers) {
if (vreUser.getUserId() == theUser2Check.getUserId()) {
_log.debug("User exists in this VRE, should not send the invite in VRE having id: " + groupId + " to " + theUser2Check.toString());
return true;
}
}
} catch (UserRetrievalFault e) {
_log.debug("User does not exist in this VRE, invite can be sent");
return false;
}
}
} catch (UserManagementSystemException | GroupRetrievalFault e) {
e.printStackTrace();
return false;
}
return false;
}
}