From b01f2238e559f363891f717ad7acb146c6f3ec60 Mon Sep 17 00:00:00 2001 From: Jay Hodgson Date: Thu, 19 Sep 2024 16:14:48 -0700 Subject: [PATCH] SWC-7081: pass the invitation token to One Sage --- .../client/place/users/RegisterAccount.java | 14 ++++----- .../presenter/EmailInvitationPresenter.java | 9 +++++- .../users/RegisterAccountPresenter.java | 31 +++++++++---------- .../EmailInvitationPresenterTest.java | 9 +++++- 4 files changed, 37 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/sagebionetworks/web/client/place/users/RegisterAccount.java b/src/main/java/org/sagebionetworks/web/client/place/users/RegisterAccount.java index a45fdc978e..a4eb870b24 100644 --- a/src/main/java/org/sagebionetworks/web/client/place/users/RegisterAccount.java +++ b/src/main/java/org/sagebionetworks/web/client/place/users/RegisterAccount.java @@ -1,19 +1,17 @@ package org.sagebionetworks.web.client.place.users; -import com.google.gwt.place.shared.Place; import com.google.gwt.place.shared.PlaceTokenizer; import com.google.gwt.place.shared.Prefix; +import org.sagebionetworks.web.client.place.ParameterizedPlace; -public class RegisterAccount extends Place { +public class RegisterAccount extends ParameterizedPlace { - private String token; + public static final String EMAIL_QUERY_PARAM = "email"; + public static final String MEMBERSHIP_INVTN_QUERY_PARAM = + "membershipInvtnSignedToken"; public RegisterAccount(String token) { - this.token = token; - } - - public String toToken() { - return token; + super(token); } @Prefix("RegisterAccount") diff --git a/src/main/java/org/sagebionetworks/web/client/presenter/EmailInvitationPresenter.java b/src/main/java/org/sagebionetworks/web/client/presenter/EmailInvitationPresenter.java index 04f5d2b096..d335588fa9 100644 --- a/src/main/java/org/sagebionetworks/web/client/presenter/EmailInvitationPresenter.java +++ b/src/main/java/org/sagebionetworks/web/client/presenter/EmailInvitationPresenter.java @@ -25,6 +25,7 @@ import org.sagebionetworks.web.client.jsinterop.ToastMessageOptions; import org.sagebionetworks.web.client.place.EmailInvitation; import org.sagebionetworks.web.client.place.LoginPlace; +import org.sagebionetworks.web.client.place.ParameterizedToken; import org.sagebionetworks.web.client.place.Profile; import org.sagebionetworks.web.client.place.Synapse.ProfileArea; import org.sagebionetworks.web.client.place.users.RegisterAccount; @@ -285,6 +286,12 @@ public void onLoginClick() { @Override public void onRegisterClick() { - placeChanger.goTo(new RegisterAccount(email)); + RegisterAccount place = new RegisterAccount(""); + place.putParam( + RegisterAccount.MEMBERSHIP_INVTN_QUERY_PARAM, + encodedMISignedToken + ); + place.putParam(RegisterAccount.EMAIL_QUERY_PARAM, email); + placeChanger.goTo(place); } } diff --git a/src/main/java/org/sagebionetworks/web/client/presenter/users/RegisterAccountPresenter.java b/src/main/java/org/sagebionetworks/web/client/presenter/users/RegisterAccountPresenter.java index 925d834b18..67ed9259b2 100644 --- a/src/main/java/org/sagebionetworks/web/client/presenter/users/RegisterAccountPresenter.java +++ b/src/main/java/org/sagebionetworks/web/client/presenter/users/RegisterAccountPresenter.java @@ -21,22 +21,21 @@ public void start(AcceptsOneWidget panel, EventBus eventBus) {} @Override public void setPlace(RegisterAccount place) { - String token = place.toToken(); - if (token != null && token.contains("@")) { - // is likely an email address - Window.Location.replace( - WebConstants.ONESAGE_PRODUCTION_URL + - "/register1?email=" + - token + - "&" + - WebConstants.ONESAGE_SYNAPSE_APPID_QUERY_PARAM - ); - } else { - Window.Location.replace( - WebConstants.ONESAGE_PRODUCTION_URL + - "/register1?" + - WebConstants.ONESAGE_SYNAPSE_APPID_QUERY_PARAM - ); + String emailInvitationToken = place.getParam( + RegisterAccount.MEMBERSHIP_INVTN_QUERY_PARAM + ); + String email = place.getParam(RegisterAccount.EMAIL_QUERY_PARAM); + StringBuilder targetUrl = new StringBuilder(); + targetUrl.append(WebConstants.ONESAGE_PRODUCTION_URL); + targetUrl.append("/register1?"); + targetUrl.append(WebConstants.ONESAGE_SYNAPSE_APPID_QUERY_PARAM); + + if (emailInvitationToken != null) { + targetUrl.append("&signedToken=" + emailInvitationToken); + } + if (email != null) { + targetUrl.append("&email=" + email); } + Window.Location.replace(targetUrl.toString()); } } diff --git a/src/test/java/org/sagebionetworks/web/unitclient/presenter/EmailInvitationPresenterTest.java b/src/test/java/org/sagebionetworks/web/unitclient/presenter/EmailInvitationPresenterTest.java index a8acd62510..dc971c12fd 100644 --- a/src/test/java/org/sagebionetworks/web/unitclient/presenter/EmailInvitationPresenterTest.java +++ b/src/test/java/org/sagebionetworks/web/unitclient/presenter/EmailInvitationPresenterTest.java @@ -280,7 +280,14 @@ public void testNotLoggedIn() { RegisterAccount.class ); verify(mockPlaceChanger).goTo(captor.capture()); - assertEquals("invitee@email.com", captor.getValue().toToken()); + assertEquals( + "invitee@email.com", + captor.getValue().getParam(RegisterAccount.EMAIL_QUERY_PARAM) + ); + assertEquals( + encodedMISignedToken, + captor.getValue().getParam(RegisterAccount.MEMBERSHIP_INVTN_QUERY_PARAM) + ); } @Test