fix: Deleted unpublished drafts in trash
This commit is contained in:
@@ -2,7 +2,13 @@ import crypto from "crypto";
|
||||
import { addHours, addMinutes, subMinutes } from "date-fns";
|
||||
import JWT from "jsonwebtoken";
|
||||
import { Context } from "koa";
|
||||
import { Transaction, QueryTypes, SaveOptions, Op } from "sequelize";
|
||||
import {
|
||||
Transaction,
|
||||
QueryTypes,
|
||||
SaveOptions,
|
||||
Op,
|
||||
FindOptions,
|
||||
} from "sequelize";
|
||||
import {
|
||||
Table,
|
||||
Column,
|
||||
@@ -361,7 +367,7 @@ class User extends ParanoidModel {
|
||||
UserPreferenceDefaults[preference] ??
|
||||
false;
|
||||
|
||||
collectionIds = async (options = {}) => {
|
||||
collectionIds = async (options: FindOptions<Collection> = {}) => {
|
||||
const collectionStubs = await Collection.scope({
|
||||
method: ["withMembership", this.id],
|
||||
}).findAll({
|
||||
|
||||
@@ -1841,8 +1841,9 @@ describe("#documents.deleted", () => {
|
||||
expect(body.data.length).toEqual(1);
|
||||
});
|
||||
|
||||
it("should return deleted documents, including drafts without collection", async () => {
|
||||
it("should return deleted documents, including users drafts without collection", async () => {
|
||||
const user = await buildUser();
|
||||
const user2 = await buildUser();
|
||||
const document = await buildDocument({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
@@ -1850,10 +1851,17 @@ describe("#documents.deleted", () => {
|
||||
const draftDocument = await buildDraftDocument({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
collectionId: null,
|
||||
});
|
||||
const otherUserDraft = await buildDraftDocument({
|
||||
userId: user2.id,
|
||||
teamId: user.teamId,
|
||||
collectionId: null,
|
||||
});
|
||||
await Promise.all([
|
||||
document.delete(user.id),
|
||||
draftDocument.delete(user.id),
|
||||
otherUserDraft.delete(user2.id),
|
||||
]);
|
||||
const res = await server.post("/api/documents.deleted", {
|
||||
body: {
|
||||
|
||||
@@ -243,28 +243,27 @@ router.post(
|
||||
const documents = await Document.scope([
|
||||
collectionScope,
|
||||
viewScope,
|
||||
"withDrafts",
|
||||
]).findAll({
|
||||
where: {
|
||||
teamId: user.teamId,
|
||||
collectionId: {
|
||||
[Op.or]: [{ [Op.in]: collectionIds }, { [Op.is]: null }],
|
||||
},
|
||||
deletedAt: {
|
||||
[Op.ne]: null,
|
||||
},
|
||||
[Op.or]: [
|
||||
{
|
||||
collectionId: {
|
||||
[Op.in]: collectionIds,
|
||||
},
|
||||
},
|
||||
{
|
||||
createdById: user.id,
|
||||
collectionId: {
|
||||
[Op.is]: null,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: User,
|
||||
as: "createdBy",
|
||||
paranoid: false,
|
||||
},
|
||||
{
|
||||
model: User,
|
||||
as: "updatedBy",
|
||||
paranoid: false,
|
||||
},
|
||||
],
|
||||
paranoid: false,
|
||||
order: [[sort, direction]],
|
||||
offset: ctx.state.pagination.offset,
|
||||
|
||||
Reference in New Issue
Block a user