mirror of
https://github.com/outline/outline.git
synced 2026-08-03 13:27:25 +03:00
fix: Recalculate memberships in the same transaction when moving doc (#13182)
closes #13181
This commit is contained in:
@@ -38,8 +38,8 @@ export default class DocumentMovedProcessor extends BaseProcessor {
|
||||
: [],
|
||||
]);
|
||||
|
||||
await this.destroyUserMemberships(document.id);
|
||||
await this.destroyGroupMemberships(document.id);
|
||||
await this.destroyUserMemberships(document, transaction);
|
||||
await this.destroyGroupMemberships(document, transaction);
|
||||
|
||||
await this.recalculateUserMemberships(
|
||||
parentDocumentUserMemberships,
|
||||
@@ -54,27 +54,37 @@ export default class DocumentMovedProcessor extends BaseProcessor {
|
||||
});
|
||||
}
|
||||
|
||||
private async destroyUserMemberships(documentId: string) {
|
||||
const document = await Document.findByPk(documentId);
|
||||
const childDocumentIds = await document.findAllChildDocumentIds();
|
||||
private async destroyUserMemberships(
|
||||
document: Document,
|
||||
transaction: Transaction
|
||||
) {
|
||||
const childDocumentIds = await document.findAllChildDocumentIds(undefined, {
|
||||
transaction,
|
||||
});
|
||||
|
||||
await UserMembership.destroy({
|
||||
where: {
|
||||
sourceId: { [Op.ne]: null },
|
||||
documentId: [...childDocumentIds, documentId],
|
||||
documentId: [...childDocumentIds, document.id],
|
||||
},
|
||||
transaction,
|
||||
});
|
||||
}
|
||||
|
||||
private async destroyGroupMemberships(documentId: string) {
|
||||
const document = await Document.findByPk(documentId);
|
||||
const childDocumentIds = await document.findAllChildDocumentIds();
|
||||
private async destroyGroupMemberships(
|
||||
document: Document,
|
||||
transaction: Transaction
|
||||
) {
|
||||
const childDocumentIds = await document.findAllChildDocumentIds(undefined, {
|
||||
transaction,
|
||||
});
|
||||
|
||||
await GroupMembership.destroy({
|
||||
where: {
|
||||
sourceId: { [Op.ne]: null },
|
||||
documentId: [...childDocumentIds, documentId],
|
||||
documentId: [...childDocumentIds, document.id],
|
||||
},
|
||||
transaction,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user