mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-10 22:41:41 +00:00
fix(slack_alerting.py): allow basic email branding without enterprise license (Fixes #19860)
This commit is contained in:
parent
93e71f67b9
commit
fdec10633e
2 changed files with 67 additions and 5 deletions
|
|
@ -1171,11 +1171,8 @@ Model Info:
|
|||
):
|
||||
from litellm.proxy.proxy_server import CommonProxyErrors, premium_user
|
||||
|
||||
if premium_user is not True:
|
||||
if email_logo_url is not None or email_support_contact is not None:
|
||||
raise ValueError(
|
||||
f"Trying to Customize Email Alerting\n {CommonProxyErrors.not_premium_user.value}"
|
||||
)
|
||||
# Allow basic branding (logo, support contact) for all users
|
||||
# This was a regression in behavior reported in #19860
|
||||
return
|
||||
|
||||
async def send_key_created_or_user_invited_email(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,65 @@
|
|||
import pytest
|
||||
import os
|
||||
import asyncio
|
||||
from unittest.mock import AsyncMock, patch
|
||||
from litellm.integrations.SlackAlerting.slack_alerting import SlackAlerting
|
||||
import sys
|
||||
from litellm.proxy._types import WebhookEvent
|
||||
import litellm.proxy.proxy_server # Ensure module is loaded for patching
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_invite_email_without_license():
|
||||
"""
|
||||
Test that sending an invite email with EMAIL_LOGO_URL set
|
||||
does not fail with a license error when user is not premium.
|
||||
|
||||
Reproduction for Issue #19860
|
||||
"""
|
||||
# Setup
|
||||
alerting_args = AsyncMock()
|
||||
slack_alerting = SlackAlerting(alerting_args)
|
||||
slack_alerting.alerting = ["email"]
|
||||
|
||||
webhook_event = WebhookEvent(
|
||||
event="internal_user_created",
|
||||
event_message="User Invited",
|
||||
event_group="team",
|
||||
user_email="test@example.com",
|
||||
user_id="test_user",
|
||||
token="test_token",
|
||||
spend=0.0,
|
||||
)
|
||||
|
||||
# Mock dependencies
|
||||
with patch.dict(os.environ, {"EMAIL_LOGO_URL": "https://example.com/logo.png"}), \
|
||||
patch("litellm.proxy.proxy_server.premium_user", False), \
|
||||
patch("litellm.proxy.utils.send_email", new_callable=AsyncMock) as mock_send_email:
|
||||
|
||||
# Action
|
||||
try:
|
||||
success = await slack_alerting.send_key_created_or_user_invited_email(webhook_event)
|
||||
except Exception as e:
|
||||
pytest.fail(f"Raised exception: {e}")
|
||||
|
||||
# Assert
|
||||
assert success is True
|
||||
mock_send_email.assert_called_once()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_check_premium_feature_does_not_raise():
|
||||
"""
|
||||
Verify that checking premium feature for email logo/support contact no longer raises
|
||||
an error after the fix for #19860.
|
||||
"""
|
||||
alerting_args = AsyncMock()
|
||||
slack_alerting = SlackAlerting(alerting_args)
|
||||
|
||||
with patch("litellm.proxy.proxy_server.premium_user", False):
|
||||
try:
|
||||
await slack_alerting._check_if_using_premium_email_feature(
|
||||
premium_user=False,
|
||||
email_logo_url="https://example.com/logo.png"
|
||||
)
|
||||
except ValueError:
|
||||
pytest.fail("Should not raise ValueError for email_logo_url")
|
||||
|
||||
Loading…
Add table
Reference in a new issue