[Customer Entity] Add filters, sort, and ServiceNow support to POST /users/search - #973
Conversation
…eld, UserSortOrder, SearchUsersFilters, UserSortBy, SNUser, SearchSNUsersResponse; restructure SearchUsersRequest to use nested filters and sortBy; update Pagination docs (default 10, max 50)
…d switch SearchUsers to use req.Filters.SearchQuery
…and emails; update searchQuery reference to req.Filters.SearchQuery
…th role and sortBy validation, sysid↔UUID conversion, and nil-safe roles slice
…ide existing postgres UserHandler
…ource is ServiceNow, postgres handler otherwise
…archUsersFilters (searchQuery, roles, userNames, emails, active), UserSortBy, UserPagination (default 10, max 50), SNUser schema, and SearchSNUsersResponse; replace flat searchQuery with nested filters structure
|
Warning Review limit reached
Next review available in: 40 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughExpands the ChangesServiceNow User Search Feature
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@entity-service/internal/service/interfaces.go`:
- Around line 37-43: Remove the redundant SNUserService interface from
interfaces.go, since the same interface is already declared in SNUserService in
sn_user_service.go and both live in package service. Keep only one definition of
SNUserService (prefer the existing one in sn_user_service.go) and update any
references in the service package to use that single interface so the package
compiles without redeclaration.
In `@entity-service/internal/service/sn_user_service.go`:
- Around line 114-138: The SearchSNUsers flow in sn_user_service.go accepts
sortBy.order even when sortBy.field is empty, but the snSortBy builder only uses
sorting when a field is provided, so the order becomes a no-op. Update the
validation in the SearchSNUsers method to reject any non-empty req.SortBy.Order
when req.SortBy.Field is empty, alongside the existing validUserSortField and
validUserSortOrder checks. Keep the behavior consistent with the snSortBy
construction so only meaningful field+order combinations are accepted.
In `@entity-service/openapi.yaml`:
- Around line 42-44: The `oneOf` in the search response is ambiguous because
`SearchUsersResponse` and `SearchSNUsersResponse` can both validate the same
payload. Update the referenced response schemas, especially the
`SearchUsersResponse`/`SearchSNUsersResponse` components and their item schemas
(`User` and `SNUser`), so each branch has distinct required fields or a
discriminator-like distinction that prevents overlap. Apply the same
disambiguation to the other `oneOf` block referenced in the spec so
`/users/search` and related responses validate unambiguously for generated
clients.
- Around line 24-28: The user search contract currently advertises
filters/sorting that the Postgres implementation does not honor, so update the
OpenAPI schema and the Postgres handling together. In the user search flow (the
shared request schema plus the Postgres path used by the search endpoint),
either implement support for roles, active, and sortBy in the Postgres query
logic or explicitly reject them there; if they remain ServiceNow-only, remove or
clearly scope them in the contract to match the actual behavior. Keep the
ServiceNow and Postgres request/response models aligned with the endpoint
documentation and the backend code that builds the Postgres query.
- Around line 1354-1369: The array filters for roles, userNames, and emails in
the OpenAPI schema are unbounded, which allows oversized request lists to flow
into SQL and external payload builders. Add explicit maxItems limits to these
schema fields in the OpenAPI definition and mirror the same bounds in the
service-side validation logic that handles these filters, using the existing
filter definitions for roles, userNames, and emails as the places to update.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: da8d4ce0-9c29-4098-a1a1-9598106eca59
📒 Files selected for processing (8)
entity-service/internal/domain/entity.goentity-service/internal/handler/user_handler.goentity-service/internal/repository/user_repo.goentity-service/internal/server/routes.goentity-service/internal/service/interfaces.goentity-service/internal/service/sn_user_service.goentity-service/internal/service/user_service.goentity-service/openapi.yaml
…nly filters in postgres, enforce sortBy.order requires field, add maxItems bounds, and disambiguate oneOf response schemas
Summary
POST /users/searchrequest from a flatsearchQueryfield to a nestedfiltersobject (searchQuery, roles, userNames, emails, active) with an optionalsortBy(field, order)DataSource == ServiceNow, the endpoint is backed by Choreo/users/searchand returnsSearchSNUsersResponsewithSNUseritems (name, timeZone, active, roles) instead of the postgresUsershapeuserNamesandemailsfilter support added to the repository layerChanges
UserRole,UserSortField,UserSortOrdertypes;SearchUsersFilters,UserSortBy;SNUser,SearchSNUsersResponsenormalizeUserPagination(default 10, max 50);SNUserServiceinterface;snUserServicebacked by ChoreoSearchUsersextended withuserNamesandemailsfiltersSNUserHandleradded alongside existing postgresUserHandlerPOST /users/searchconditionally routes to SN or postgres handler based onDataSourceSearchUsersRequest,UserPagination,SearchUsersFilters,UserSortBy,SNUser,SearchSNUsersResponseschemas added/updatedTest plan
POST /users/searchwith postgres data source returns existingUsershape withfirstName,lastName,userTypePOST /users/searchwith ServiceNow data source returnsSNUsershape withname,timeZone,active,rolesrolesfilter with an invalid value returns400sortBy.fieldwith an invalid value returns400pagination.limit > 50returns400userNamesandemailsfilters correctly narrow postgres resultsx-user-id-tokenheader on SN data source returns401Summary by CodeRabbit
New Features
Bug Fixes