Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'on_user_search' callback to third_party_rules callback #18156

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

awesome-michael
Copy link
Contributor

Add 'on_user_search' callback to the third_party_rules section of the module API.
This allows to write modules that can trigger on search requests on the user directory and alter the results.
Possible use cases:

  • Filter or group user search results
  • Exclude MxIDs from the user search results
  • Include MxIDs in the user search results even if they do not match the search criteria (e.g. a helper Bot)

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
    • Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry.
  • Code style is correct
    (run the linters)

Change-Id: Ieeb68956a043048c496f17ba56b75b8b068d5389
Signed-off-by: Michael Albert <[email protected]>
@awesome-michael awesome-michael requested a review from a team as a code owner February 12, 2025 13:29
@CLAassistant
Copy link

CLAassistant commented Feb 12, 2025

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot deployed to PR Documentation Preview February 12, 2025 13:31 Active
Change-Id: Ifaea3c0d303710c17b94ca074aa3f3ffd8b2b17f
@github-actions github-actions bot deployed to PR Documentation Preview February 12, 2025 13:32 Active
Change-Id: Ib19a0e297d3f2150a864655610ce3956ad6b8815
@github-actions github-actions bot deployed to PR Documentation Preview February 12, 2025 13:39 Active
@github-actions github-actions bot deployed to PR Documentation Preview February 12, 2025 13:51 Active
@github-actions github-actions bot deployed to PR Documentation Preview February 13, 2025 09:00 Active
@github-actions github-actions bot deployed to PR Documentation Preview February 14, 2025 14:54 Active
Comment on lines +89 to +91
# Let the third party rules modify the result list if needed, or abort
# the search entirely with an exception.
await self._third_party_event_rules.on_user_search(requester, results)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would probably make more sense to do this at the handler level (

async def search_users(
self, user_id: str, search_term: str, limit: int
) -> SearchResult:
"""Searches for users in directory
Returns:
dict of the form::
{
"limited": <bool>, # whether there were more results or not
"results": [ # Ordered by best match first
{
"user_id": <user_id>,
"display_name": <display_name>,
"avatar_url": <avatar_url>
}
]
}
"""
results = await self.store.search_user_dir(
user_id, search_term, limit, self.show_locked_users
)
# Remove any spammy users from the results.
non_spammy_users = []
for user in results["results"]:
if not await self._spam_checker_module_callbacks.check_username_for_spam(
user, user_id
):
non_spammy_users.append(user)
results["results"] = non_spammy_users
return results
) so that it also applies to the admin API?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants