Skip to content

Add get_persons_by_nickname with pagination to TahrirDatabase#263

Open
Daniel-1600 wants to merge 1 commit intofedora-infra:developfrom
Daniel-1600:refactor/user-search-pagination
Open

Add get_persons_by_nickname with pagination to TahrirDatabase#263
Daniel-1600 wants to merge 1 commit intofedora-infra:developfrom
Daniel-1600:refactor/user-search-pagination

Conversation

@Daniel-1600
Copy link
Copy Markdown

Add get_persons_by_nickname method to TahrirDatabase to support paginated user search by nickname.

This moves the user search and pagination logic from the tahrir frontend into the API layer where it belongs. The method accepts a search string, begin offset, and limit, and returns a dict with the matching users, total count, and pagination info.

@gridhead gridhead self-requested a review April 3, 2026 07:18
@gridhead gridhead self-assigned this Apr 3, 2026
@gridhead gridhead added cle Community Linux Engineering enhancement labels Apr 3, 2026
Copy link
Copy Markdown
Contributor

@sdglitched sdglitched left a comment

Choose a reason for hiding this comment

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

Thank you for working on this.

Please make the requested changes, along with signing the commit and following the 50-character rule for commit messages.

Also, specify the AI usage as per ACP and explain what your thought process was during the development as per the latest decision.

:type limit: int
:param limit: Max results per page, capped at 100 (default 100).
"""
safe_limit = min(limit, 100)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good job fixing the highest limit 👍

Comment on lines +553 to +556
"id": person.id,
"nickname": person.nickname,
"avatar": person.avatar,
"rank": person.rank,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why are only these particular fields fetched and not the other ones?

Please check the current implementation in https://github.com/fedora-infra/tahrir/blob/d9a22d25e6d47ced5b4225bfff833ab02b8cd6c7/tahrir/endpoints/users.py#L33-L41 and add the rest of the fields.

Comment on lines +678 to +717

def test_get_persons_by_nickname(api):
api.add_person("alice@test.com", nickname="alice_wonder")
api.add_person("bob@test.com", nickname="bob_builder")
api.add_person("charlie@test.com", nickname="charlie_choc")

result = api.get_persons_by_nickname("alice")
assert result["total"] == 1
assert result["users"][0]["nickname"] == "alice_wonder"

def test_get_persons_by_nickname_partial_match(api):
api.add_person("dave@test.com", nickname="dave_test")
api.add_person("diana@test.com", nickname="diana_test")
api.add_person("evan@test.com", nickname="evan_other")

result = api.get_persons_by_nickname("test")
assert result["total"] == 2

def test_get_persons_by_nickname_pagination(api):
for i in range(5):
api.add_person(f"user{i}@test.com", nickname=f"user_{i}")

result = api.get_persons_by_nickname("user", begin=0, limit=2)
assert len(result["users"]) == 2
assert result["total"] == 5
assert result["begin"] == 0
assert result["limit"] == 2

def test_get_persons_by_nickname_no_match(api):
api.add_person("test@test.com", nickname="test_user")

result = api.get_persons_by_nickname("zzznomatch")
assert result["total"] == 0
assert result["users"] == []

def test_get_persons_by_nickname_case_insensitive(api):
api.add_person("upper@test.com", nickname="UpperCase")

result = api.get_persons_by_nickname("uppercase")
assert result["total"] == 1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add the test cases in a new commit.

@sdglitched
Copy link
Copy Markdown
Contributor

Also, make sure the test runs successfully.

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

Labels

cle Community Linux Engineering enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants