Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SWC-6712 #5316

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,21 @@ public void onSuccess(String teamIconUrl) {
}
}

private void setViewTeam(
public void setViewTeam(
Team team,
String description,
TeamMembershipStatus teamMembershipStatus,
String teamIconUrl
) {
view.setTeam(team, description, teamIconUrl);
boolean canSendEmail =
teamMembershipStatus != null && teamMembershipStatus.getCanSendEmail();
view.setTeamEmailAddress(getTeamEmail(team.getName(), canSendEmail));
teamMembershipStatus != null &&
teamMembershipStatus.getCanSendEmail() &&
authController.isLoggedIn();
view.setTeamEmailVisible(canSendEmail);
if (canSendEmail) {
view.setTeamEmailAddress(getTeamEmail(team.getName()));
}
}

public void configure(final String teamId) {
Expand Down Expand Up @@ -121,12 +126,8 @@ public void setHeight(String height) {
view.setHeight(height);
}

public String getTeamEmail(String teamName, boolean canSendEmail) {
if (authController.isLoggedIn() && canSendEmail) {
// strip out any non-word character. Not a (letter, number, underscore)
return teamName.replaceAll("\\W", "") + "@synapse.org";
} else {
return "";
}
public String getTeamEmail(String teamName) {
// strip out any non-word character. Not a (letter, number, underscore)
return teamName.replaceAll("\\W", "") + "@synapse.org";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ public interface BigTeamBadgeView extends IsWidget, SynapseView {

void setMemberCountWidget(IsWidget widget);

void setTeamEmailVisible(boolean visible);
void setTeamEmailAddress(String teamEmail);
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public interface Binder extends UiBinder<Widget, BigTeamBadgeViewImpl> {}
@UiField
TextBoxWithCopyToClipboardWidget synapseEmailField;

@UiField
Div emailUI;

GlobalApplicationState globalApplicationState;
IconsImageBundle iconsImageBundle;
Linkify linkify;
Expand Down Expand Up @@ -152,6 +155,11 @@ public void setMemberCountWidget(IsWidget widget) {
memberCountContainer.add(widget);
}

@Override
public void setTeamEmailVisible(boolean visible) {
emailUI.setVisible(visible);
}

@Override
public void setTeamEmailAddress(String teamEmail) {
synapseEmailField.setText(teamEmail);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,16 @@
<bh:Text>team members</bh:Text>
</bh:Div>
<bh:Div ui:field="descriptionContainer" marginTop="10" />
<w:TextBoxWithCopyToClipboardWidget
ui:field="synapseEmailField"
addStyleNames="margin-top-10"
/>
<bh:Div ui:field="emailUI">
<bh:Text>Team email list:</bh:Text>
<w:TextBoxWithCopyToClipboardWidget
ui:field="synapseEmailField"
addStyleNames="margin-top-10 margin-left-5 margin-right-5"
/>
<bh:Italic>
(note: all emails to this address sent to the entire team)
</bh:Italic>
</bh:Div>
</bh:Span>
</bh:Span>
</bh:Div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.sagebionetworks.repo.model.Team;
import org.sagebionetworks.repo.model.TeamMembershipStatus;
import org.sagebionetworks.web.client.SynapseJSNIUtils;
import org.sagebionetworks.web.client.SynapseJavascriptClient;
import org.sagebionetworks.web.client.security.AuthenticationController;
Expand All @@ -38,6 +39,9 @@ public class BigTeamBadgeTest {
@Mock
TeamMemberCountWidget mockTeamMemberCountWidget;

@Mock
TeamMembershipStatus mockTeamMembershipStatus;

BigTeamBadge presenter;

@Mock
Expand All @@ -48,22 +52,20 @@ public class BigTeamBadgeTest {

@Before
public void setUp() throws Exception {
presenter =
new BigTeamBadge(
mockView,
mockJsClient,
mockJsniUtils,
mockAuthenticationController,
mockTeamMemberCountWidget
);
presenter = new BigTeamBadge(
mockView,
mockJsClient,
mockJsniUtils,
mockAuthenticationController,
mockTeamMemberCountWidget
);
when(mockTeam.getName()).thenReturn("simpleteam");
when(mockTeam.getDescription()).thenReturn(TEAM_DESCRIPTION);
when(mockTeam.getIcon()).thenReturn("1111");
AsyncMockStubber
.callSuccessWith(TEAM_ICON_URL)
AsyncMockStubber.callSuccessWith(TEAM_ICON_URL)
.when(mockJsClient)
.getTeamPicturePreviewURL(anyString(), any(AsyncCallback.class));
AsyncMockStubber
.callSuccessWith(mockTeam)
AsyncMockStubber.callSuccessWith(mockTeam)
.when(mockJsClient)
.getTeam(anyString(), any(AsyncCallback.class));
}
Expand All @@ -77,8 +79,7 @@ public void testConfigure() {

@Test
public void testConfigureFailedToGetIcon() {
AsyncMockStubber
.callFailureWith(new Exception("failed"))
AsyncMockStubber.callFailureWith(new Exception("failed"))
.when(mockJsClient)
.getTeamPicturePreviewURL(anyString(), any(AsyncCallback.class));

Expand All @@ -89,33 +90,63 @@ public void testConfigureFailedToGetIcon() {

@Test
public void testGetTeamEmail() {
boolean canSendEmail = true;
when(mockAuthenticationController.isLoggedIn()).thenReturn(true);
assertEquals(
"[email protected]",
presenter.getTeamEmail("basic", canSendEmail)
);
assertEquals("[email protected]", presenter.getTeamEmail("basic"));
assertEquals(
"[email protected]",
presenter.getTeamEmail("Standard Case Here", canSendEmail)
presenter.getTeamEmail("Standard Case Here")
);
assertEquals(
"[email protected]",
presenter.getTeamEmail(" \n\r unlikely\t case ", canSendEmail)
presenter.getTeamEmail(" \n\r unlikely\t case ")
);
assertEquals(
"[email protected]",
presenter.getTeamEmail(
" %^$##* Another_Unlikely\t &*#$)(!!@~Case ",
canSendEmail
)
presenter.getTeamEmail(" %^$##* Another_Unlikely\t &*#$)(!!@~Case ")
);
}

@Test
public void testEmailVisible() {
when(mockAuthenticationController.isLoggedIn()).thenReturn(true);
when(mockTeamMembershipStatus.getCanSendEmail()).thenReturn(true);

presenter.setViewTeam(
mockTeam,
TEAM_DESCRIPTION,
mockTeamMembershipStatus,
TEAM_ICON_URL
);

canSendEmail = false;
assertEquals("", presenter.getTeamEmail("basic", canSendEmail));
verify(mockView).setTeamEmailVisible(true);
}

canSendEmail = true;
@Test
public void testEmailNotVisibleWhenAnonymous() {
when(mockAuthenticationController.isLoggedIn()).thenReturn(false);
assertEquals("", presenter.getTeamEmail("basic", canSendEmail));
when(mockTeamMembershipStatus.getCanSendEmail()).thenReturn(true);

presenter.setViewTeam(
mockTeam,
TEAM_DESCRIPTION,
mockTeamMembershipStatus,
TEAM_ICON_URL
);

verify(mockView).setTeamEmailVisible(false);
}

@Test
public void testEmailNotVisibleWhenUnauthorized() {
when(mockAuthenticationController.isLoggedIn()).thenReturn(true);
when(mockTeamMembershipStatus.getCanSendEmail()).thenReturn(false);

presenter.setViewTeam(
mockTeam,
TEAM_DESCRIPTION,
mockTeamMembershipStatus,
TEAM_ICON_URL
);

verify(mockView).setTeamEmailVisible(false);
}
}
Loading