fix: enforce get_query filter and permissions on pasted/manual values in Link fields #34440
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes #34363
This PR addresses the issue where Link fields with
get_queryfilters or permission restrictions don't validate manually pasted or typed values, allowing users to save invalid links that bypass the configured filters.Changes Made
Frontend Changes
Link Control (
frappe/public/js/frappe/form/controls/link.js)validate_link_and_fetch()to pass filters, query, reference_doctype, and ignore_user_permissions to serverBase Control (
frappe/public/js/frappe/form/controls/base_control.js)validate_and_set_in_model()to store pending validation promisesForm Save (
frappe/public/js/frappe/form/save.js)wait_for_pending_validations()to collect all pending field validation promisesBackend Changes
frappe/client.py)validate_link()to acceptfilters,query,reference_doctype, andignore_user_permissionsparametersget_list()to ensure entered docname satisfies provided filtersTests
frappe/tests/test_client.py)test_validate_link_with_filters_rejects_mismatch()to verify server-side filter validationvalidate_link()correctly rejects values that don't match provided filtersHow It Works
get_queryfilters/query to servervalidate_link()methodget_list()with permissionsTesting
Manual Testing Steps:
get_queryfilter (e.g.,{filters: {enabled: 1}})Automated Testing:
Edge Cases Covered
get_list()permissionsBreaking Changes
None. This is a backward-compatible enhancement that only adds validation where it was previously missing.
Checklist