feat: email filtering in `users.info` and `users.list` endpoints
Merged
NA
6mo ago+232+232+012345678901234567890123456789-42-42-01234567890123456789
Proposed changes (including videos or screenshots)
users.info- UsersInfoParamsGet.ts validation schema was extended so that
emailis accepted as query parameter. - getFullUserData.ts was modified to support email lookup only if the user is looking for their own info or if the user
view-full-other-user-infopermission they would be able to look for other users by email.
- UsersInfoParamsGet.ts validation schema was extended so that
users.list- UsersListParamsGET.ts was brought from this open PR, with the additional
emailproperty. - Implemented case-insensitive matching (
$regex+$options: 'i') to align with database collation andusers.infobehavior. - The new
emailfilter is intentionally injected into thenonEmptyQueryobject rather than creating a separate database query. This is done to maintain backward compatibility with the legacyqueryparameter. By merging them, both explicit parameters and legacy queries can work together seamlessly until the legacyqueryparameter is officially removed.
- UsersListParamsGET.ts was brought from this open PR, with the additional
- Added tests covering cases where
users.infoandusers.listare queried with email. - Removed obsolete test for the
namequery parameter on/api/v1/users.list. Manually verified that the endpoint completely ignores this parameter. Passing complex objects or regex operators (e.g.,?name[$regex]=...) returns the exact same full array as an empty request. Dropping this test removes dead code and prevents future confusion.
Issue(s)
CORE-1994 [Feature Request]: Add Email filter to users.info and users.list endpoints
Steps to test or reproduce
Using an API client and having two users: one with the view-full-other-user-info permission and the other one without it. We have to get the X-Auth-Token and X-User-Id values for each one and set them on the Headers section.
- For
users.info: Try fetching info of any user if the requester has theview-full-other-user-infopermission, or if the requester doesn't, then try to fetch their own info (same email), and they shouldn't be able to fetch others data.
Example URL:http://localhost:3000/api/v1/users.info?email=email@example.com - For
users.list: In this case, only the user with theview-full-other-user-infois able to fetch by email and they must be able to see theemailsproperty from each user in the response payload. Users without the permission, shouldn't be able to fetch by email (unauthorized) but they can callusers.listwithout any query parameter, with the exception that theemailsproperty isn't shown to them.
Example URL:http://localhost:3000/api/v1/users.list?email=test@rocket.chat
Further comments
Summary by CodeRabbit
-
New Features
- Email-based search support for user listing and user info endpoints; queries by email now available and subject to permission checks.
-
Tests
- Added end-to-end tests for email-based user queries covering success, not-found, and permission-denied cases.