Fix invite domain URL and improve shared mobile header
This commit is contained in:
@@ -286,8 +286,31 @@ ONBOARDING_ROLE_CONFIG: dict[str, dict[str, str]] = {
|
||||
}
|
||||
|
||||
|
||||
def _public_invite_url(invite_token: str) -> str:
|
||||
base = (get_settings().ERP_PUBLIC_BASE_URL or "").strip().rstrip("/") or "http://localhost:8000"
|
||||
def _public_invite_url(request, invite_token: str) -> str:
|
||||
"""Build an invite URL for the domain currently used by the Firm Admin.
|
||||
|
||||
Tenant custom domains must remain tenant-specific. Prefer the request host
|
||||
(including trusted proxy headers) and retain ERP_PUBLIC_BASE_URL only as a
|
||||
defensive fallback for non-HTTP callers.
|
||||
"""
|
||||
forwarded_proto = (request.headers.get("x-forwarded-proto") or "").split(",", 1)[0].strip().lower()
|
||||
forwarded_host = (request.headers.get("x-forwarded-host") or "").split(",", 1)[0].strip()
|
||||
request_host = (request.headers.get("host") or "").strip()
|
||||
|
||||
scheme = forwarded_proto if forwarded_proto in {"http", "https"} else str(request.url.scheme or "https").lower()
|
||||
host = forwarded_host or request_host or str(request.url.netloc or "").strip()
|
||||
|
||||
# Reject header-control characters before using a host in a generated URL.
|
||||
if host and not any(ch in host for ch in "\r\n/\\"):
|
||||
base = f"{scheme}://{host}".rstrip("/")
|
||||
else:
|
||||
base = str(request.base_url).strip().rstrip("/")
|
||||
|
||||
if not base:
|
||||
base = (get_settings().ERP_PUBLIC_BASE_URL or "").strip().rstrip("/")
|
||||
if not base:
|
||||
raise ValueError("Unable to determine the public ERP URL for the invite link.")
|
||||
|
||||
return f"{base}/invite/accept?token={invite_token}"
|
||||
|
||||
|
||||
@@ -498,7 +521,7 @@ def create_firm_internal_user(
|
||||
|
||||
db.refresh(user)
|
||||
invite_token = issue_invite_token(db, user)
|
||||
invite_url = _public_invite_url(invite_token)
|
||||
invite_url = _public_invite_url(request, invite_token)
|
||||
email_status = "not_attempted"
|
||||
email_error = None
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user