fix: Documents in deleted collection should appear in trash (#1362)

* fix: Documents from deleted collection should show in trash

* improve messaging

* test: Add documents.move tests
feat: Add ability to restore trashed documents from deleted collection

* update store

* fix

* ui

* lint

* fix: Improve breadcrumb
This commit is contained in:
Tom Moor
2020-09-07 11:51:09 -07:00
committed by GitHub
parent c5de2da115
commit 4de3f69474
12 changed files with 258 additions and 50 deletions

View File

@@ -210,7 +210,7 @@ router.post("documents.deleted", auth(), pagination(), async (ctx) => {
if (direction !== "ASC") direction = "DESC";
const user = ctx.state.user;
const collectionIds = await user.collectionIds();
const collectionIds = await user.collectionIds({ paranoid: false });
const collectionScope = { method: ["withCollection", user.id] };
const documents = await Document.scope(collectionScope).findAll({
@@ -444,7 +444,7 @@ router.post("documents.export", auth({ required: false }), async (ctx) => {
});
router.post("documents.restore", auth(), async (ctx) => {
const { id, revisionId } = ctx.body;
const { id, collectionId, revisionId } = ctx.body;
ctx.assertPresent(id, "id is required");
const user = ctx.state.user;
@@ -453,6 +453,16 @@ router.post("documents.restore", auth(), async (ctx) => {
paranoid: false,
});
if (collectionId) {
ctx.assertUuid(collectionId, "collectionId must be a uuid");
authorize(user, "restore", document);
const collection = await Collection.findByPk(collectionId);
authorize(user, "update", collection);
document.collectionId = collectionId;
}
if (document.deletedAt) {
authorize(user, "restore", document);
@@ -938,6 +948,9 @@ router.post("documents.move", auth(), async (ctx) => {
const document = await Document.findByPk(id, { userId: user.id });
authorize(user, "move", document);
const collection = await Collection.findByPk(collectionId);
authorize(user, "update", collection);
if (parentDocumentId) {
const parent = await Document.findByPk(parentDocumentId, {
userId: user.id,