feat: Nested document sharing (#2075)

* migration

* frontend routing, api permissioning

* feat: apiVersion=2

* feat: re-writing document links to point to share

* poc nested documents on share links

* fix: nested shareId permissions

* ui and language tweaks, comments

* breadcrumbs

* Add icons to reference list items

* refactor: Breadcrumb component

* tweaks

* Add shared parent note
This commit is contained in:
Tom Moor
2021-05-22 19:34:05 -07:00
committed by GitHub
parent dc4b5588b7
commit 44920a25f4
31 changed files with 1134 additions and 282 deletions

View File

@@ -10,7 +10,12 @@ import BaseStore from "stores/BaseStore";
import RootStore from "stores/RootStore";
import Document from "models/Document";
import env from "env";
import type { FetchOptions, PaginationParams, SearchResult } from "types";
import type {
NavigationNode,
FetchOptions,
PaginationParams,
SearchResult,
} from "types";
import { client } from "utils/ApiClient";
type ImportOptions = {
@@ -447,30 +452,30 @@ export default class DocumentsStore extends BaseStore<Document> {
fetch = async (
id: string,
options: FetchOptions = {}
): Promise<?Document> => {
): Promise<{ document: ?Document, sharedTree?: NavigationNode }> => {
if (!options.prefetch) this.isFetching = true;
try {
const doc: ?Document = this.data.get(id) || this.getByUrl(id);
const policy = doc ? this.rootStore.policies.get(doc.id) : undefined;
if (doc && policy && !options.force) {
return doc;
return { document: doc };
}
const res = await client.post("/documents.info", {
id,
shareId: options.shareId,
apiVersion: 2,
});
invariant(res && res.data, "Document not available");
this.addPolicies(res.policies);
this.add(res.data);
this.add(res.data.document);
runInAction("DocumentsStore#fetch", () => {
this.isLoaded = true;
});
return this.data.get(res.data.id);
return {
document: this.data.get(res.data.document.id),
sharedTree: res.data.sharedTree,
};
} finally {
this.isFetching = false;
}

View File

@@ -46,19 +46,42 @@ export default class SharesStore extends BaseStore<Share> {
this.isFetching = true;
try {
const res = await client.post(`/${this.modelName}s.info`, { documentId });
const res = await client.post(`/${this.modelName}s.info`, {
documentId,
apiVersion: 2,
});
if (isUndefined(res)) return;
invariant(res && res.data, "Data should be available");
this.addPolicies(res.policies);
return this.add(res.data);
return res.data.shares.map(this.add);
} finally {
this.isFetching = false;
}
}
getByDocumentId = (documentId): ?Share => {
getByDocumentParents = (documentId: string): ?Share => {
const document = this.rootStore.documents.get(documentId);
if (!document) return;
const collection = this.rootStore.collections.get(document.collectionId);
if (!collection) return;
const parentIds = collection
.pathToDocument(documentId)
.slice(0, -1)
.map((p) => p.id);
for (const parentId of parentIds) {
const share = this.getByDocumentId(parentId);
if (share && share.includeChildDocuments && share.published) {
return share;
}
}
};
getByDocumentId = (documentId: string): ?Share => {
return find(this.orderedData, (share) => share.documentId === documentId);
};
}