Skip to content

[CHORE][REFACTOR]: Reduce code duplication in team management UI and cursor pagination #2091

@crivetimihai

Description

@crivetimihai

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:21
  • mcpgateway/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 (existing cursor_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

  • refactor
  • tech-debt
  • maintainability

Metadata

Metadata

Assignees

Labels

COULDP3: Nice-to-have features with minimal impact if left out; included if time permitschoreLinting, formatting, dependency hygiene, or project maintenance choresfrontendFrontend development (HTML, CSS, JavaScript)uiUser Interface

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions