feat(org): add organization limit per user

Add 10 organization limit per user to prevent abuse. Includes
graceful fallback if count service is unavailable.

- Add get_user_org_count method to OrganizationService
- Check org count before allowing new organization creation
- Improve invite email mismatch error message for logged-in users
This commit is contained in:
2026-04-20 15:04:44 +09:30
parent 69f39dfa04
commit b2c2acc84f
3 changed files with 27 additions and 1 deletions
@@ -70,6 +70,22 @@ class OrganizationService:
return org
@staticmethod
def get_user_org_count(user_id):
"""
Get the count of organizations a user belongs to.
Args:
user_id: User ID
Returns:
Count of active memberships (deleted_at is NULL)
"""
return OrganizationMember.query.filter_by(
user_id=user_id,
deleted_at=None,
).count()
@staticmethod
def get_organization_by_id(org_id):
"""