feat: Implement open email registration with conditional organization assignment

- Remove email domain validation requirement from registration endpoint
- Implement conditional organization assignment logic (auto-assign if domain match, else NULL)
- Allow users to register with any email address without requiring organization match
- Maintain backward compatibility for domain-matched emails (auto-assign to organization)
- Remove unused OrganizationNotFoundError import and fix code style

Key Changes:
- Modified EmailCodeLoginApi to allow registration without organization assignment
- Users with matching email domains are auto-assigned to organizations
- Users without matching domains can register and use platform with organization_id=NULL
- Prepared foundation for future organization invitation system

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
pull/21891/head
ytqh 11 months ago
parent bba1d844e4
commit f1080f060c

@ -12,7 +12,6 @@ from controllers.service_api_with_auth.error import (
AccountInFreezeError, AccountInFreezeError,
EmailSendIpLimitError, EmailSendIpLimitError,
OrganizationMismatchError, OrganizationMismatchError,
OrganizationNotFoundError,
TenantNotFoundError, TenantNotFoundError,
) )
from libs.helper import email, extract_remote_ip from libs.helper import email, extract_remote_ip
@ -196,9 +195,6 @@ class EmailCodeLoginApi(Resource):
# Find organization based on email domain # Find organization based on email domain
organization = OrganizationService.find_organization_by_email_domain(user_email, tenant.id) organization = OrganizationService.find_organization_by_email_domain(user_email, tenant.id)
if organization is None:
raise OrganizationNotFoundError()
is_new_user = account is None is_new_user = account is None
if account is None: if account is None:
@ -211,11 +207,14 @@ class EmailCodeLoginApi(Resource):
interface_language=languages[0], interface_language=languages[0],
) )
OrganizationService.assign_account_to_organization(account, organization.id) # Assign to organization if domain match found, otherwise leave organization_id as NULL
if organization is not None:
OrganizationService.assign_account_to_organization(account, organization.id)
else: else:
if account.current_organization_id is not None and account.current_organization_id != organization.id: if (organization is not None and account.current_organization_id is not None
and account.current_organization_id != organization.id):
raise OrganizationMismatchError() raise OrganizationMismatchError()
connected_tenant = TenantService.get_join_tenants(account) connected_tenant = TenantService.get_join_tenants(account)

Loading…
Cancel
Save