Skip to content

Associated records / Align related records API filtering with associated records - #9437

Open
juanluisrp wants to merge 2 commits into
mainfrom
fix/related-records-view-filter-main
Open

Associated records / Align related records API filtering with associated records#9437
juanluisrp wants to merge 2 commits into
mainfrom
fix/related-records-view-filter-main

Conversation

@juanluisrp

@juanluisrp juanluisrp commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Related records are retrieved through MetadataUtils.getRelated. This aligns that code path with the getAssociated implementation and the main search by building its Elasticsearch queries with the shared EsFilterBuilder filtering.

The ServiceContext is threaded through the private search / calculateResults helpers, and the portal filter is combined with the standard search filter, so related-records results are built the same way as the rest of the catalog search. Administrators are unaffected (the filter resolves to *:*).

Affected endpoints:

  • GET /api/records/{uuid}/related
  • GET /api/related

Changes

  • MetadataUtils.search(...) and MetadataUtils.calculateResults(...) now receive the ServiceContext and reuse the shared search filter, combined with the portal filter when present.
  • All call sites in getRelated(...) updated to pass the context.
  • New RelatedApiIntegrationTest.

How to test

Requires a running Elasticsearch instance (see es/docker-compose.yml).

mvn -pl services -Dit.test=RelatedApiIntegrationTest -DfailIfNoTests=false \
    failsafe:integration-test failsafe:verify -Pit

Manual check: relate two records with different privileges, then request the related resources. The listing reflects the current user's view privileges (an administrator sees all; an anonymous user sees only the ones they are allowed to view).

…ted records

Related records are retrieved through MetadataUtils.getRelated. Align this
code path with the getAssociated implementation and the main search by
building its Elasticsearch queries with the shared EsFilterBuilder
filtering: thread the ServiceContext through the private search and
calculateResults helpers and combine the portal filter with the standard
search filter. Administrators are unaffected as the filter resolves to
`*:*`.

Add RelatedApiIntegrationTest covering anonymous and administrator access.
@juanluisrp
juanluisrp force-pushed the fix/related-records-view-filter-main branch from 58f4134 to 3ad12e1 Compare July 21, 2026 08:04
@juanluisrp juanluisrp changed the title Associated records / Apply view privilege filter to related records API Associated records / Align related records API filtering with associated records Jul 21, 2026
@juanluisrp juanluisrp self-assigned this Jul 21, 2026
@juanluisrp juanluisrp modified the milestones: 4.2.18, 4.4.13 Jul 21, 2026
…ted records

- Avoid redundant filter computation.
- Escape portal filter.
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

💡 Need a hand with PR review? Try Gitar by Sonar!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants