feat: Allow unpublishing documents (#1467)

* Allow unpublishing documents

* add block unpublish files that has children

* add api tests to new route
This commit is contained in:
Guilherme DIniz
2020-09-01 00:03:05 -03:00
committed by GitHub
parent de59147418
commit 0aa338cccc
7 changed files with 159 additions and 12 deletions

View File

@ -1,10 +1,9 @@
// @flow
import removeMarkdown from "@tommoor/remove-markdown";
import { map, find, compact, uniq } from "lodash";
import { compact, find, map, uniq } from "lodash";
import randomstring from "randomstring";
import Sequelize, { type Transaction } from "sequelize";
import Sequelize, { Transaction } from "sequelize";
import MarkdownSerializer from "slate-md-serializer";
import isUUID from "validator/lib/isUUID";
import parseTitle from "../../shared/utils/parseTitle";
import unescape from "../../shared/utils/unescape";
@ -556,6 +555,18 @@ Document.prototype.publish = async function (options) {
return this;
};
Document.prototype.unpublish = async function (options) {
if (!this.publishedAt) return this;
const collection = await this.getCollection();
await collection.removeDocumentInStructure(this);
this.publishedAt = null;
await this.save(options);
return this;
};
// Moves a document from being visible to the team within a collection
// to the archived area, where it can be subsequently restored.
Document.prototype.archive = async function (userId) {