Skip to content

Commit 041b00d

Browse files
committed
feat: Re-apply ACL/CLP systematically when beforeFind returns objects
1 parent 3da7ffb commit 041b00d

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/rest.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,39 @@ async function runFindTriggers(
5151
if (result?.objects) {
5252
const objectsFromBeforeFind = result.objects;
5353

54+
let objectsForAfterFind = objectsFromBeforeFind;
55+
56+
if (!auth?.isMaster && !auth?.isMaintenance) {
57+
const ids = (Array.isArray(objectsFromBeforeFind) ? objectsFromBeforeFind : [objectsFromBeforeFind])
58+
.map(o => (o && (o.id || o.objectId)) || null)
59+
.filter(Boolean);
60+
61+
if (ids.length > 0) {
62+
const refilterWhere = isGet ? { objectId: ids[0] } : { objectId: { $in: ids } };
63+
64+
const refilterQuery = await RestQuery({
65+
method: isGet ? RestQuery.Method.get : RestQuery.Method.find,
66+
config,
67+
auth,
68+
className,
69+
restWhere: refilterWhere,
70+
restOptions,
71+
clientSDK,
72+
context,
73+
runBeforeFind: false,
74+
runAfterFind: false,
75+
});
76+
77+
const refiltered = await refilterQuery.execute();
78+
objectsForAfterFind = (refiltered && refiltered.results) || [];
79+
}
80+
}
81+
5482
const afterFindProcessedObjects = await triggers.maybeRunAfterFindTrigger(
5583
triggers.Types.afterFind,
5684
auth,
5785
className,
58-
objectsFromBeforeFind,
86+
objectsForAfterFind,
5987
config,
6088
new Parse.Query(className).withJSON({ where: restWhere, ...restOptions }),
6189
context,

src/triggers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ export function maybeRunAfterFindTrigger(
470470
if (query.where) {
471471
parseQueryInstance.withJSON(query);
472472
} else {
473-
parseQueryInstance.withJSON({ where: query });
473+
parseQueryInstance.withJSON({ where: {}, ...query });
474474
}
475475
request.query = parseQueryInstance;
476476
} else {

0 commit comments

Comments
 (0)