fix: Ensure collection withUser scope is not overriden (#9226)

This commit is contained in:
Hemachandar
2025-05-16 17:46:25 +05:30
committed by GitHub
parent d50f0986bb
commit 610721eed6
2 changed files with 15 additions and 6 deletions
@@ -37,9 +37,10 @@ export default class CollectionCreatedEmail extends BaseEmail<
}
protected async beforeSend(props: InputProps) {
const collection = await Collection.scope("withUser").findByPk(
props.collectionId
);
const collection = await Collection.findByPk(props.collectionId, {
includeOwner: true,
});
if (!collection) {
return false;
}
+11 -3
View File
@@ -14,6 +14,7 @@ import {
EmptyResultError,
type CreateOptions,
type UpdateOptions,
ScopeOptions,
} from "sequelize";
import {
Sequelize,
@@ -69,6 +70,7 @@ import NotContainsUrl from "./validators/NotContainsUrl";
type AdditionalFindOptions = {
userId?: string;
includeDocumentStructure?: boolean;
includeOwner?: boolean;
rejectOnEmpty?: boolean | Error;
};
@@ -509,14 +511,20 @@ class Collection extends ParanoidModel<
return null;
}
const { includeDocumentStructure, userId, ...rest } = options;
const { includeDocumentStructure, includeOwner, userId, ...rest } = options;
const scope = this.scope([
const scopes: (string | ScopeOptions)[] = [
includeDocumentStructure ? "withDocumentStructure" : "defaultScope",
{
method: ["withMembership", userId],
},
]);
];
if (includeOwner) {
scopes.push("withUser");
}
const scope = this.scope(scopes);
if (isUUID(id)) {
const collection = await scope.findOne({