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:
@ -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) {
|
||||
|
Reference in New Issue
Block a user