Allow drafts to be created without requiring a collection (#4175)

* feat(server): allow document to be created without collectionId

* fix(server): policies for a draft doc without collection

* fix(app): hide share button for drafts

* feat(server): permissions around publishing a draft

* fix(server): return drafts without collection

* fix(server): handle draft deletion

* fix(server): show drafts in deleted docs

* fix(server): allow drafts without collection to be restored

* feat(server): return drafts in search results

* fix: use buildDraftDocument for drafts

* fix: remove isDraftWithoutCollection

* fix: do not return drafts for team

* fix: put invariants

* fix: query clause

* fix: check only for undefined

* fix: restore includeDrafts clause as it was before
This commit is contained in:
Apoorv Mishra
2022-10-25 18:01:57 +05:30
committed by GitHub
parent 6b74d43380
commit a89d30c735
14 changed files with 557 additions and 84 deletions

View File

@@ -1,3 +1,4 @@
import { isNull } from "lodash";
import { v4 as uuidv4 } from "uuid";
import { CollectionPermission } from "@shared/types";
import {
@@ -323,8 +324,22 @@ export async function buildGroupUser(
});
}
export async function buildDocument(
export async function buildDraftDocument(
overrides: Partial<Document> & { userId?: string } = {}
) {
return buildDocument({ ...overrides, collectionId: null });
}
export async function buildDocument(
// Omission first, addition later?
// This is actually a workaround to allow
// passing collectionId as null. Ideally, it
// should be updated in the Document model itself
// but that'd cascade and require further changes
// beyond the scope of what's required now
overrides: Omit<Partial<Document>, "collectionId"> & { userId?: string } & {
collectionId?: string | null;
} = {}
) {
if (!overrides.teamId) {
const team = await buildTeam();
@@ -336,7 +351,7 @@ export async function buildDocument(
overrides.userId = user.id;
}
if (!overrides.collectionId) {
if (overrides.collectionId === undefined) {
const collection = await buildCollection({
teamId: overrides.teamId,
userId: overrides.userId,
@@ -348,7 +363,7 @@ export async function buildDocument(
return Document.create({
title: `Document ${count}`,
text: "This is the text in an example document",
publishedAt: new Date(),
publishedAt: isNull(overrides.collectionId) ? null : new Date(),
lastModifiedById: overrides.userId,
createdById: overrides.userId,
...overrides,