mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-12 08:42:18 +00:00
fix(proxy): email only members holding the team admin role, not the legacy admins list
This commit is contained in:
parent
c0305a568d
commit
708d6fa859
2 changed files with 7 additions and 7 deletions
|
|
@ -69,11 +69,9 @@ async def get_all_team_member_emails(team_id: str | None = None) -> list:
|
|||
|
||||
|
||||
async def get_team_admin_emails(team: LiteLLM_TeamTable, prisma_client: object) -> tuple[str, ...]:
|
||||
"""Emails of the team's admins: the user record's email, else the inline one, plus the legacy admins list, deduped"""
|
||||
"""Emails of the members holding the admin role: the user record's email, else the inline one, deduped"""
|
||||
admins: Final = tuple(member for member in team.members_with_roles if member.role == "admin")
|
||||
admin_ids: Final = frozenset(
|
||||
(*(member.user_id for member in admins if member.user_id), *(user_id for user_id in team.admins if user_id))
|
||||
)
|
||||
admin_ids: Final = frozenset(member.user_id for member in admins if member.user_id)
|
||||
rows: Final = (
|
||||
await UserRepository(prisma_client).find_many(
|
||||
where={"user_id": {"in": sorted(admin_ids)}} # mutable-ok: prisma filter payloads are plain dict/list
|
||||
|
|
|
|||
|
|
@ -44,11 +44,13 @@ async def test_should_return_only_admin_emails():
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_should_include_legacy_admins_list():
|
||||
async def test_should_ignore_the_legacy_admins_list_the_proxy_does_not_authorize():
|
||||
prisma: Final = _prisma(USERS)
|
||||
team: Final = LiteLLM_TeamTable(
|
||||
team_id="t1", admins=["u-legacy"], members_with_roles=[Member(user_id="u-admin", role="admin")]
|
||||
)
|
||||
assert sorted(await get_team_admin_emails(team, _prisma(USERS))) == ["admin@example.com", "legacy@example.com"]
|
||||
assert await get_team_admin_emails(team, prisma) == ("admin@example.com",)
|
||||
assert prisma.db.litellm_usertable.queries == [{"user_id": {"in": ["u-admin"]}}]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
@ -79,9 +81,9 @@ async def test_should_include_email_only_admins_and_dedupe_ids_and_emails():
|
|||
)
|
||||
team: Final = LiteLLM_TeamTable(
|
||||
team_id="t1",
|
||||
admins=["", "u-legacy", "u-admin"],
|
||||
members_with_roles=[
|
||||
Member(user_id="u-admin", role="admin"),
|
||||
Member(user_id="u-legacy", role="admin"),
|
||||
Member(user_email="mail-only@example.com", role="admin"),
|
||||
],
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue