payload icon indicating copy to clipboard operation
payload copied to clipboard

fix: add beforeOperation hook in findVersions collections operations

Open imsidkg opened this issue 1 month ago • 2 comments

What?

Fixes the beforeOperation collection hook being called when using the findVersions operation, just as it is for the standard find operation.

Why?

Previously, the beforeOperation hook was only triggered for standard find operations, but not for findVersions. This led to inconsistent behavior, as custom logic (such as access control, logging, or argument modification) defined in beforeOperation would not run when querying document versions. This PR brings parity and predictability to hook execution across both operations.

How?

The logic for invoking the beforeOperation hook (as seen in find.ts) was added to findVersions.ts. Now, when findVersions is called, all registered beforeOperation hooks are executed with the correct arguments before the main operation logic runs.

Fixes https://github.com/payloadcms/payload/issues/14726

imsidkg avatar Nov 26 '25 12:11 imsidkg

Hi @imsidkg, thanks for creating this PR to the issue I opened!

During a discussion with r1tsuu in the Discord, he noticed that the afterOperation hook is also not called for find operations. Could you maybe extend this PR to also call that?

jhb-dev avatar Nov 28 '25 15:11 jhb-dev

sure @jhb-dev i will work on it.

imsidkg avatar Nov 28 '25 17:11 imsidkg

Thanks @imsidkg, but I guess you can close this PR in favour of https://github.com/payloadcms/payload/pull/14778, which also calls the beforeOperation and afterOperation hooks in even more operations where it was missing.

jhb-dev avatar Dec 03 '25 22:12 jhb-dev