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