Skip to content

Commit

Permalink
Merge pull request #5507 from jay-hodgson/SWC-7047
Browse files Browse the repository at this point in the history
  • Loading branch information
jay-hodgson authored Aug 29, 2024
2 parents f36f0a2 + 4a636e3 commit 4f86274
Show file tree
Hide file tree
Showing 10 changed files with 328 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.sagebionetworks.web.client.presenter.TeamPresenter;
import org.sagebionetworks.web.client.presenter.TeamSearchPresenter;
import org.sagebionetworks.web.client.presenter.TrashPresenter;
import org.sagebionetworks.web.client.presenter.TrustCenterPresenter;
import org.sagebionetworks.web.client.presenter.TwoFactorAuthPresenter;
import org.sagebionetworks.web.client.presenter.WikiDiffPresenter;
import org.sagebionetworks.web.client.presenter.users.PasswordResetPresenter;
Expand Down Expand Up @@ -91,8 +92,28 @@
import org.sagebionetworks.web.client.widget.docker.modal.AddExternalRepoModal;
import org.sagebionetworks.web.client.widget.doi.CreateOrUpdateDoiModal;
import org.sagebionetworks.web.client.widget.doi.DoiWidgetV2;
import org.sagebionetworks.web.client.widget.entity.*;
import org.sagebionetworks.web.client.widget.entity.ChallengeBadge;
import org.sagebionetworks.web.client.widget.entity.EditFileMetadataModalWidget;
import org.sagebionetworks.web.client.widget.entity.EditProjectMetadataModalWidget;
import org.sagebionetworks.web.client.widget.entity.EntityListRowBadge;
import org.sagebionetworks.web.client.widget.entity.EntityMetadata;
import org.sagebionetworks.web.client.widget.entity.EntityTreeItem;
import org.sagebionetworks.web.client.widget.entity.MarkdownWidget;
import org.sagebionetworks.web.client.widget.entity.ModifiedCreatedByWidget;
import org.sagebionetworks.web.client.widget.entity.MoreTreeItem;
import org.sagebionetworks.web.client.widget.entity.PreviewWidget;
import org.sagebionetworks.web.client.widget.entity.ProjectBadge;
import org.sagebionetworks.web.client.widget.entity.PromptForValuesModalView;
import org.sagebionetworks.web.client.widget.entity.RegisterTeamDialog;
import org.sagebionetworks.web.client.widget.entity.RenameEntityModalWidget;
import org.sagebionetworks.web.client.widget.entity.SqlDefinedEditorModalWidget;
import org.sagebionetworks.web.client.widget.entity.TutorialWizard;
import org.sagebionetworks.web.client.widget.entity.VersionHistoryRowView;
import org.sagebionetworks.web.client.widget.entity.VersionHistoryWidget;
import org.sagebionetworks.web.client.widget.entity.WikiMarkdownEditor;
import org.sagebionetworks.web.client.widget.entity.WikiPageDeleteConfirmationDialog;
import org.sagebionetworks.web.client.widget.entity.WikiPageWidget;
import org.sagebionetworks.web.client.widget.entity.WikiVersionAnchorListItem;
import org.sagebionetworks.web.client.widget.entity.act.ApproveUserAccessModal;
import org.sagebionetworks.web.client.widget.entity.act.RejectReasonWidget;
import org.sagebionetworks.web.client.widget.entity.act.UserBadgeItem;
Expand Down Expand Up @@ -194,7 +215,6 @@
import org.sagebionetworks.web.client.widget.sharing.AccessControlListModalWidget;
import org.sagebionetworks.web.client.widget.sharing.AclAddPeoplePanel;
import org.sagebionetworks.web.client.widget.sharing.EntityAccessControlListModalWidget;
import org.sagebionetworks.web.client.widget.sharing.EntityAccessControlListModalWidgetImpl;
import org.sagebionetworks.web.client.widget.sharing.SharingPermissionsGrid;
import org.sagebionetworks.web.client.widget.statistics.StatisticsPlotWidget;
import org.sagebionetworks.web.client.widget.table.TableEntityListGroupItem;
Expand Down Expand Up @@ -874,4 +894,6 @@ public interface PortalGinInjector extends Ginjector {
EntityTypeIcon getEntityTypeIcon();

FeatureFlagConfig getFeatureFlagConfig();

TrustCenterPresenter getTrustCenterPresenter();
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.sagebionetworks.web.client.place.Team;
import org.sagebionetworks.web.client.place.TeamSearch;
import org.sagebionetworks.web.client.place.Trash;
import org.sagebionetworks.web.client.place.TrustCenterPlace;
import org.sagebionetworks.web.client.place.Wiki;
import org.sagebionetworks.web.client.place.users.PasswordReset;
import org.sagebionetworks.web.client.place.users.RegisterAccount;
Expand Down Expand Up @@ -101,6 +102,7 @@ public AppActivityMapper(
openAccessPlaces.add(EmailInvitation.class);
openAccessPlaces.add(AccessRequirementsPlace.class);
openAccessPlaces.add(AccessRequirementPlace.class);
openAccessPlaces.add(TrustCenterPlace.class);

excludeFromLastPlace = new ArrayList<Class>();
excludeFromLastPlace.add(Home.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.sagebionetworks.web.client.place.Team;
import org.sagebionetworks.web.client.place.TeamSearch;
import org.sagebionetworks.web.client.place.Trash;
import org.sagebionetworks.web.client.place.TrustCenterPlace;
import org.sagebionetworks.web.client.place.TwoFactorAuthPlace;
import org.sagebionetworks.web.client.place.Wiki;
import org.sagebionetworks.web.client.place.WikiDiff;
Expand Down Expand Up @@ -96,6 +97,7 @@
OAuthClientEditorPlace.Tokenizer.class,
TwoFactorAuthPlace.Tokenizer.class,
FollowingPlace.Tokenizer.class,
TrustCenterPlace.Tokenizer.class,
}
)
public interface AppPlaceHistoryMapper extends PlaceHistoryMapper {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.sagebionetworks.web.client.place;

import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceTokenizer;
import com.google.gwt.place.shared.Prefix;

public class TrustCenterPlace extends Place {

public static final String SUBPROCESSORS_KEY = "Subprocessors";
public static final String COOKIES_KEY = "Cookies";
public static final String PRIVACY_POLICY_KEY = "PrivacyPolicy";
public static final String TERMS_OF_SERVICE_KEY = "TermsOfService";

private String documentKey;

public TrustCenterPlace(String token) {
this.documentKey = token;
}

public String toToken() {
return documentKey;
}

public String getDocumentKey() {
return documentKey;
}

@Prefix("TrustCenter")
public static class Tokenizer implements PlaceTokenizer<TrustCenterPlace> {

@Override
public String getToken(TrustCenterPlace place) {
return place.toToken();
}

@Override
public TrustCenterPlace getPlace(String token) {
return new TrustCenterPlace(token);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.sagebionetworks.web.client.place.Team;
import org.sagebionetworks.web.client.place.TeamSearch;
import org.sagebionetworks.web.client.place.Trash;
import org.sagebionetworks.web.client.place.TrustCenterPlace;
import org.sagebionetworks.web.client.place.TwoFactorAuthPlace;
import org.sagebionetworks.web.client.place.Wiki;
import org.sagebionetworks.web.client.place.WikiDiff;
Expand Down Expand Up @@ -864,6 +865,24 @@ public void onSuccess() {
presenter.start(panel, eventBus);
}

@Override
public void onFailure(Throwable caught) {
loadError(caught);
}
}
);
} else if (place instanceof TrustCenterPlace) {
GWT.runAsync(
TrustCenterPlace.class,
new RunAsyncCallback() {
@Override
public void onSuccess() {
TrustCenterPresenter presenter =
ginjector.getTrustCenterPresenter();
presenter.setPlace((TrustCenterPlace) place);
presenter.start(panel, eventBus);
}

@Override
public void onFailure(Throwable caught) {
loadError(caught);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package org.sagebionetworks.web.client.presenter;

import com.google.gwt.activity.shared.AbstractActivity;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.Response;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.inject.Inject;
import java.util.HashMap;
import java.util.Map;
import org.sagebionetworks.web.client.RequestBuilderWrapper;
import org.sagebionetworks.web.client.place.TrustCenterPlace;
import org.sagebionetworks.web.client.view.MapView;
import org.sagebionetworks.web.client.view.SynapseStandaloneWikiView;
import org.sagebionetworks.web.client.widget.entity.controller.SynapseAlert;
import org.sagebionetworks.web.shared.WebConstants;

public class TrustCenterPresenter
extends AbstractActivity
implements
Presenter<org.sagebionetworks.web.client.place.TrustCenterPlace>,
MapView.Presenter {

SynapseStandaloneWikiView view;
RequestBuilderWrapper requestBuilder;
SynapseAlert synAlert;

private static Map<String, String> documentKeyToGithubUrl = new HashMap<>();

static {
documentKeyToGithubUrl.put(
TrustCenterPlace.TERMS_OF_SERVICE_KEY,
"https://raw.githubusercontent.com/Sage-Bionetworks/Sage-Governance-Documents/main/Terms.md"
);
documentKeyToGithubUrl.put(
TrustCenterPlace.PRIVACY_POLICY_KEY,
"https://raw.githubusercontent.com/Sage-Bionetworks/Sage-Governance-Documents/main/privacy.md"
);
documentKeyToGithubUrl.put(
TrustCenterPlace.COOKIES_KEY,
"https://raw.githubusercontent.com/Sage-Bionetworks/Sage-Governance-Documents/main/cookies.md"
);
documentKeyToGithubUrl.put(
TrustCenterPlace.SUBPROCESSORS_KEY,
"https://raw.githubusercontent.com/Sage-Bionetworks/Sage-Governance-Documents/main/subprocessors.md"
);
}

@Inject
public TrustCenterPresenter(
SynapseStandaloneWikiView view,
RequestBuilderWrapper requestBuilder,
SynapseAlert synAlert
) {
this.view = view;
this.requestBuilder = requestBuilder;
this.synAlert = synAlert;
view.setSynAlert(synAlert);
}

@Override
public void start(AcceptsOneWidget panel, EventBus eventBus) {
panel.setWidget(view.asWidget());
}

@Override
public void setPlace(
org.sagebionetworks.web.client.place.TrustCenterPlace place
) {
synAlert.clear();
String documentKey = place.getDocumentKey();
String documentUrl = documentKeyToGithubUrl.get(documentKey);
if (documentUrl == null) {
synAlert.showError("Unrecognized document key: " + documentKey);
} else {
showFileContent(documentUrl);
}
}

public void showFileContent(String url) {
requestBuilder.configure(RequestBuilder.GET, url);
requestBuilder.setHeader(
WebConstants.CONTENT_TYPE,
WebConstants.TEXT_PLAIN_CHARSET_UTF8
);
try {
requestBuilder.sendRequest(
null,
new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response) {
int statusCode = response.getStatusCode();
if (statusCode == Response.SC_OK) {
String md = response.getText();
view.configure(md);
} else {
onError(
null,
new IllegalArgumentException(
"Unable to retrieve file content " +
url +
". Reason: " +
response.getStatusText()
)
);
}
}

@Override
public void onError(Request request, Throwable exception) {
synAlert.handleException(exception);
}
}
);
} catch (final Exception e) {
synAlert.handleException(e);
}
}

@Override
public String mayStop() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

public interface SynapseStandaloneWikiView extends IsWidget {
void configure(String markdown, WikiPageKey wikiKey);

void configure(String markdown);
void setSynAlert(IsWidget w);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public void configure(String markdown, WikiPageKey wikiKey) {
Window.scrollTo(0, 0); // scroll user to top of page
}

@Override
public void configure(String markdown) {
configure(markdown, null);
}

@Override
public void setSynAlert(IsWidget w) {
synAlertContainer.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
type='org.sagebionetworks.web.client.SageImageBundle'
/>

<bh:Div>
<bh:Div addStyleNames="margin-top-60 margin-bottom-40">
<b:Container>
<b:Container fluid="true">
<b:Row>
<b:Column size="XS_12">
<bh:Div ui:field="synAlertContainer" />
<bh:Div
ui:field="markdownContainer"
addStyleNames="min-height-400"
/>
<bh:Div ui:field="synAlertContainer" />
</b:Column>
</b:Row>
</b:Container>
Expand Down
Loading

0 comments on commit 4f86274

Please sign in to comment.