mirror of
https://github.com/outline/outline.git
synced 2026-11-30 00:50:41 +03:00
* wip * Route document list queries through findAllWithCtx Add findAllWithCtx and countWithCtx on Document and Template, unsafe* methods for system reads, and a lint rule that bans direct list queries. Remove the cached membership list, accessibleSql and findByIds in favour of one gate. * Remove test * Include drafts when loading starred documents * Scope the access gate to the user's team, move whereToSql to QueryHelper * Move collection access to Collection.findAllWithCtx Collection.accessibleIds keeps the cached id list inside the collection gate, and user.collectionIds() is a shortcut to it. List queries use findAllWithCtx and countWithCtx, system reads use the shared unsafe methods, and the admin listing in collections.list is explicit. * Check permanentDelete for each document in empty_trash
62 lines
1.4 KiB
TypeScript
62 lines
1.4 KiB
TypeScript
import { Op } from "sequelize";
|
|
import documentMover from "@server/commands/documentMover";
|
|
import { Collection, Document, User } from "@server/models";
|
|
import { sequelize } from "@server/storage/database";
|
|
import { BaseTask } from "./base/BaseTask";
|
|
import { createContext } from "@server/context";
|
|
|
|
type Props = {
|
|
collectionId: string;
|
|
actorId: string;
|
|
ip: string | null;
|
|
};
|
|
|
|
export default class DetachDraftsFromCollectionTask extends BaseTask<Props> {
|
|
protected jobId({ collectionId }: Props) {
|
|
return `detach-drafts:${collectionId}`;
|
|
}
|
|
|
|
async perform(props: Props) {
|
|
const [collection, actor] = await Promise.all([
|
|
Collection.findByPk(props.collectionId, {
|
|
paranoid: false,
|
|
}),
|
|
User.findByPk(props.actorId),
|
|
]);
|
|
|
|
if (
|
|
!actor ||
|
|
!collection ||
|
|
!(collection.deletedAt || collection.archivedAt)
|
|
) {
|
|
return;
|
|
}
|
|
|
|
const documents = await Document.unsafeFindAll({
|
|
scope: "withDrafts",
|
|
where: {
|
|
collectionId: props.collectionId,
|
|
publishedAt: {
|
|
[Op.is]: null,
|
|
},
|
|
},
|
|
paranoid: false,
|
|
});
|
|
|
|
return sequelize.transaction(async (transaction) => {
|
|
const ctx = createContext({
|
|
user: actor,
|
|
ip: props.ip,
|
|
transaction,
|
|
});
|
|
|
|
for (const document of documents) {
|
|
await documentMover(ctx, {
|
|
document,
|
|
collectionId: null,
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|