-
Notifications
You must be signed in to change notification settings - Fork 615
[CHORE][REFACTOR]: Reduce code duplication in team management UI and cursor pagination #2091
Description
Summary
During the review of PR #2067 (team management pagination), two areas of code duplication were identified that should be addressed in a follow-up refactor.
1. Frontend HTML duplication in server-side search
Location:
mcpgateway/static/admin.js:30487(JavaScript HTML strings)mcpgateway/templates/team_users_selector.html:21mcpgateway/templates/team_members_selector.html:8
Problem: The JavaScript serverSideUserSearch function builds member/non-member HTML strings that mirror the markup in the Jinja templates. Any template changes (badges, layout, data attributes) require manual JS updates and can easily drift.
Proposed fix: Return server-rendered HTML fragments for search results (e.g., a new /admin/users/search/partial endpoint that renders the same templates) and replace the container with the returned HTML, or use a shared client-side template source instead of hardcoded strings.
2. Cursor pagination logic duplicated across services
Location:
mcpgateway/services/team_management_service.py:848(team members cursor)mcpgateway/services/email_auth_service.py:824(EmailUser cursor)mcpgateway/utils/pagination.py:384(existingcursor_paginate)
Problem: Both service files implement custom base64 decode + keyset filtering logic, while pagination.py already provides cursor_paginate. This increases maintenance burden and risk of inconsistency.
Proposed fix: Extend cursor_paginate to allow custom cursor fields (e.g., joined_at for team members, email for EmailUser instead of id) and reuse it in both services to remove duplication.
Labels
refactortech-debtmaintainability