Commit 7d08ba5
authored
fix(search): token-scope team results for admins in unified search (#5668)
* fix(search): token-scope team results for admins in unified search
Complements the non-admin team-scope fix: the admin branch of
admin_search_teams returns all teams (the admin management view) and ignored
token scope, so an admin using a token explicitly narrowed to a team subset
still saw every team through /v1/search, /admin/search, and /admin/teams/search.
Honor explicit token_teams even for admins (Layer 1 constrains visibility
independently of admin status): None means full admin bypass (unchanged), while
an explicit list narrows the result. The caller's own personal team stays
visible. Admin UI session tokens and unscoped admin API tokens resolve to None
and are unaffected.
Add real-data tests through /v1/search: an unscoped admin sees all teams
(including one they do not belong to), while a token scoped to one team narrows
to it. Verified empirically by disabling the filter and observing the scoped
admin token still see every team.
Signed-off-by: Pratik Gandhi <gandhipratik203@gmail.com>
* fix(search): apply admin team scope in the query before pagination
The admin branch of admin_search_teams fetched list_teams(page=1,
per_page=limit) and then filtered by token scope, so a scoped-admin token whose
allowed team sorted past the first `limit` matches returned empty/incomplete
results even though that team was visible.
Add an optional team_ids filter to TeamManagementService.list_teams (applied to
the query before pagination; an empty list matches nothing) and pass the
normalized token scope from the admin branch. Scope is now enforced in the DB
query rather than on an already-limited page. As a consequence an explicit
scope (including [] = public-only) no longer surfaces the personal team, which
aligns the admin branch with the token model; the non-admin branch carve-out is
addressed separately.
Verified empirically: an admin scoped to a team that sorts last among 12 teams
with limit=8 now returns that team instead of an empty page.
Signed-off-by: Pratik Gandhi <gandhipratik203@gmail.com>
* fix(search): drop personal-team carve-out; cover public-only and past-page scope
Finding 1 (non-admin branch): remove the getattr(is_personal) carve-out so an
explicit token scope (including [] = public-only) no longer surfaces the
caller's personal team. An unscoped caller's memberships already include their
personal team via _get_user_team_ids, so the common case is unchanged; this
matches normalize_token_teams()/get_team_from_token(), which define [] as
public-only with no personal fallback. (The admin branch was already aligned by
pushing scope into the query.)
Add the two regression cases the review flagged:
- public-only admin token (token_teams=[]) sees no teams, not a bypass view.
- an admin scoped to a team that sorts past the per-page limit still gets it
(proves scope is applied in the query before pagination).
Verified empirically: disabling the list_teams team_ids filter makes all three
scope-dependent admin tests fail (narrowing leaks, public-only non-empty,
past-page team dropped).
Signed-off-by: Pratik Gandhi <gandhipratik203@gmail.com>
* fix(search): rename admin-branch team-id var to avoid mypy type collision
The admin branch declared scoped_team_ids: Optional[list[str]] while the
non-admin branch reused the same name for a set[str], which strict mypy flagged
as an incompatible reassignment (harmless at runtime since the branches are
mutually exclusive). Rename the admin-branch variable to admin_scoped_team_ids.
Signed-off-by: Pratik Gandhi <gandhipratik203@gmail.com>
* test(search): add unit coverage for admin scope extraction and list_teams team_ids
CI diff-cover flagged two changed lines as uncovered because they are only
exercised by the integration suite (gated behind --with-integration):
- admin.py: the admin-branch token-scope extraction
- team_management_service.py: the list_teams team_ids where-clause
Add unit tests that run in the standard pytest job:
- admin_search_teams with a scoped admin token (mixed str/dict token_teams)
forwards the normalized team_ids to list_teams.
- list_teams(team_ids=[...]) restricts results in the query; None = no filter.
Signed-off-by: Pratik Gandhi <gandhipratik203@gmail.com>
---------
Signed-off-by: Pratik Gandhi <gandhipratik203@gmail.com>1 parent 4ed6b01 commit 7d08ba5
5 files changed
Lines changed: 163 additions & 13 deletions
File tree
- mcpgateway
- services
- tests
- integration
- unit/mcpgateway
- services
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5581 | 5581 | | |
5582 | 5582 | | |
5583 | 5583 | | |
5584 | | - | |
| 5584 | + | |
| 5585 | + | |
| 5586 | + | |
| 5587 | + | |
| 5588 | + | |
| 5589 | + | |
| 5590 | + | |
| 5591 | + | |
| 5592 | + | |
| 5593 | + | |
5585 | 5594 | | |
5586 | | - | |
| 5595 | + | |
| 5596 | + | |
| 5597 | + | |
| 5598 | + | |
| 5599 | + | |
| 5600 | + | |
| 5601 | + | |
| 5602 | + | |
5587 | 5603 | | |
5588 | 5604 | | |
5589 | 5605 | | |
| |||
5595 | 5611 | | |
5596 | 5612 | | |
5597 | 5613 | | |
5598 | | - | |
| 5614 | + | |
| 5615 | + | |
| 5616 | + | |
5599 | 5617 | | |
5600 | 5618 | | |
5601 | 5619 | | |
5602 | 5620 | | |
5603 | | - | |
| 5621 | + | |
5604 | 5622 | | |
5605 | 5623 | | |
5606 | 5624 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1856 | 1856 | | |
1857 | 1857 | | |
1858 | 1858 | | |
| 1859 | + | |
1859 | 1860 | | |
1860 | 1861 | | |
1861 | 1862 | | |
| |||
1871 | 1872 | | |
1872 | 1873 | | |
1873 | 1874 | | |
| 1875 | + | |
1874 | 1876 | | |
1875 | 1877 | | |
1876 | 1878 | | |
| |||
1887 | 1889 | | |
1888 | 1890 | | |
1889 | 1891 | | |
| 1892 | + | |
| 1893 | + | |
| 1894 | + | |
| 1895 | + | |
| 1896 | + | |
1890 | 1897 | | |
1891 | 1898 | | |
1892 | 1899 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
| 290 | + | |
290 | 291 | | |
291 | 292 | | |
292 | 293 | | |
293 | 294 | | |
294 | 295 | | |
| 296 | + | |
295 | 297 | | |
296 | 298 | | |
297 | | - | |
298 | | - | |
| 299 | + | |
| 300 | + | |
299 | 301 | | |
300 | 302 | | |
301 | 303 | | |
| |||
316 | 318 | | |
317 | 319 | | |
318 | 320 | | |
319 | | - | |
| 321 | + | |
320 | 322 | | |
321 | 323 | | |
322 | 324 | | |
323 | 325 | | |
| 326 | + | |
324 | 327 | | |
325 | 328 | | |
326 | 329 | | |
327 | 330 | | |
328 | | - | |
329 | | - | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
330 | 334 | | |
331 | 335 | | |
332 | 336 | | |
333 | 337 | | |
334 | 338 | | |
335 | 339 | | |
336 | 340 | | |
| 341 | + | |
337 | 342 | | |
338 | 343 | | |
339 | 344 | | |
| |||
353 | 358 | | |
354 | 359 | | |
355 | 360 | | |
| 361 | + | |
356 | 362 | | |
| 363 | + | |
357 | 364 | | |
358 | 365 | | |
359 | 366 | | |
| |||
368 | 375 | | |
369 | 376 | | |
370 | 377 | | |
371 | | - | |
372 | | - | |
| 378 | + | |
| 379 | + | |
373 | 380 | | |
374 | 381 | | |
375 | 382 | | |
376 | 383 | | |
377 | 384 | | |
378 | 385 | | |
379 | 386 | | |
380 | | - | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
381 | 390 | | |
382 | 391 | | |
383 | 392 | | |
384 | 393 | | |
385 | 394 | | |
386 | | - | |
| 395 | + | |
387 | 396 | | |
388 | 397 | | |
389 | 398 | | |
| |||
503 | 512 | | |
504 | 513 | | |
505 | 514 | | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
Lines changed: 28 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1063 | 1063 | | |
1064 | 1064 | | |
1065 | 1065 | | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
1066 | 1094 | | |
1067 | 1095 | | |
1068 | 1096 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19846 | 19846 | | |
19847 | 19847 | | |
19848 | 19848 | | |
| 19849 | + | |
| 19850 | + | |
| 19851 | + | |
| 19852 | + | |
| 19853 | + | |
| 19854 | + | |
| 19855 | + | |
| 19856 | + | |
| 19857 | + | |
| 19858 | + | |
| 19859 | + | |
| 19860 | + | |
| 19861 | + | |
| 19862 | + | |
| 19863 | + | |
| 19864 | + | |
| 19865 | + | |
| 19866 | + | |
| 19867 | + | |
| 19868 | + | |
| 19869 | + | |
| 19870 | + | |
| 19871 | + | |
| 19872 | + | |
| 19873 | + | |
19849 | 19874 | | |
19850 | 19875 | | |
19851 | 19876 | | |
| |||
0 commit comments