fix: Unnecessary shares.info request when loading public share (#1453)

closes #1450
This commit is contained in:
Tom Moor
2020-08-13 16:48:03 -07:00
committed by GitHub
parent 9ef4e2b437
commit 174acfac32

View File

@ -64,12 +64,6 @@ class DataLoader extends React.Component<Props> {
}
}
goToDocumentCanonical = () => {
if (this.document) {
this.props.history.push(this.document.url);
}
};
get isEditing() {
return this.props.match.path === matchDocumentEdit;
}
@ -125,17 +119,28 @@ class DataLoader extends React.Component<Props> {
const document = this.document;
if (document) {
const can = this.props.policies.abilities(document.id);
// sets the document as active in the sidebar, ideally in the future this
// will be route driven.
this.props.ui.setActiveDocument(document);
if (document.isArchived && this.isEditing) {
return this.goToDocumentCanonical();
// If we're attempting to update an archived, deleted, or otherwise
// uneditable document then forward to the canonical read url.
if (!can.update && this.isEditing) {
this.props.history.push(this.document.url);
return;
}
// Prevents unauthorized request to load share information for the document
// when viewing a public share link
if (can.read) {
this.props.shares.fetch(document.id).catch((err) => {
if (!(err instanceof NotFoundError)) {
throw err;
}
});
}
const isMove = this.props.location.pathname.match(/move$/);
const canRedirect = !revisionId && !isMove && !shareId;