Improve onboarding
This commit is contained in:
@@ -48,6 +48,31 @@ async def add_team_member_with_user_creation(
|
||||
In production, this will be replaced with an invitation-based flow.
|
||||
"""
|
||||
try:
|
||||
# CRITICAL: Check subscription limit before adding user
|
||||
from app.services.subscription_limit_service import SubscriptionLimitService
|
||||
|
||||
limit_service = SubscriptionLimitService()
|
||||
limit_check = await limit_service.can_add_user(str(tenant_id))
|
||||
|
||||
if not limit_check.get('can_add', False):
|
||||
logger.warning(
|
||||
"User limit exceeded",
|
||||
tenant_id=str(tenant_id),
|
||||
current=limit_check.get('current_count'),
|
||||
max=limit_check.get('max_allowed'),
|
||||
reason=limit_check.get('reason')
|
||||
)
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_402_PAYMENT_REQUIRED,
|
||||
detail={
|
||||
"error": "user_limit_exceeded",
|
||||
"message": limit_check.get('reason', 'User limit exceeded'),
|
||||
"current_count": limit_check.get('current_count'),
|
||||
"max_allowed": limit_check.get('max_allowed'),
|
||||
"upgrade_required": True
|
||||
}
|
||||
)
|
||||
|
||||
user_id_to_add = member_data.user_id
|
||||
|
||||
# If create_user is True, create the user first via auth service
|
||||
@@ -151,12 +176,45 @@ async def add_team_member(
|
||||
"""Add an existing team member to tenant (legacy endpoint)"""
|
||||
|
||||
try:
|
||||
# CRITICAL: Check subscription limit before adding user
|
||||
from app.services.subscription_limit_service import SubscriptionLimitService
|
||||
|
||||
limit_service = SubscriptionLimitService()
|
||||
limit_check = await limit_service.can_add_user(str(tenant_id))
|
||||
|
||||
if not limit_check.get('can_add', False):
|
||||
logger.warning(
|
||||
"User limit exceeded",
|
||||
tenant_id=str(tenant_id),
|
||||
current=limit_check.get('current_count'),
|
||||
max=limit_check.get('max_allowed'),
|
||||
reason=limit_check.get('reason')
|
||||
)
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_402_PAYMENT_REQUIRED,
|
||||
detail={
|
||||
"error": "user_limit_exceeded",
|
||||
"message": limit_check.get('reason', 'User limit exceeded'),
|
||||
"current_count": limit_check.get('current_count'),
|
||||
"max_allowed": limit_check.get('max_allowed'),
|
||||
"upgrade_required": True
|
||||
}
|
||||
)
|
||||
|
||||
result = await tenant_service.add_team_member(
|
||||
str(tenant_id),
|
||||
user_id,
|
||||
role,
|
||||
current_user["user_id"]
|
||||
)
|
||||
|
||||
logger.info(
|
||||
"Team member added successfully",
|
||||
tenant_id=str(tenant_id),
|
||||
user_id=user_id,
|
||||
role=role
|
||||
)
|
||||
|
||||
return result
|
||||
|
||||
except HTTPException:
|
||||
|
||||
Reference in New Issue
Block a user