2026.03.29 20:00 Gitea_manager javítás előtt
This commit is contained in:
@@ -17,7 +17,79 @@ async def read_users_me(
|
||||
current_user: User = Depends(get_current_user),
|
||||
):
|
||||
"""Visszaadja a bejelentkezett felhasználó profilját"""
|
||||
return current_user
|
||||
from sqlalchemy import select, or_
|
||||
from app.models.marketplace.organization import Organization, OrganizationMember
|
||||
from app.models.marketplace.organization import OrgUserRole
|
||||
|
||||
# Determine active organization ID
|
||||
active_org_id = None
|
||||
|
||||
# If user already has a scope_id, use it
|
||||
if current_user.scope_id is not None:
|
||||
try:
|
||||
active_org_id = int(current_user.scope_id)
|
||||
except (ValueError, TypeError):
|
||||
active_org_id = None
|
||||
|
||||
# If still no active org ID, try to find user's primary organization
|
||||
if active_org_id is None:
|
||||
# 1. Check if user is a member of any organization with ADMIN/OWNER role
|
||||
stmt = select(OrganizationMember.organization_id).where(
|
||||
OrganizationMember.user_id == current_user.id,
|
||||
or_(
|
||||
OrganizationMember.role == OrgUserRole.ADMIN,
|
||||
OrganizationMember.role == OrgUserRole.OWNER
|
||||
)
|
||||
).limit(1)
|
||||
|
||||
result = await db.execute(stmt)
|
||||
org_member_row = result.first()
|
||||
|
||||
if org_member_row:
|
||||
active_org_id = org_member_row[0]
|
||||
else:
|
||||
# 2. Check if user owns any organization (owner_id matches user.id)
|
||||
stmt = select(Organization.id).where(
|
||||
Organization.owner_id == current_user.id
|
||||
).limit(1)
|
||||
result = await db.execute(stmt)
|
||||
org_owner_row = result.first()
|
||||
|
||||
if org_owner_row:
|
||||
active_org_id = org_owner_row[0]
|
||||
else:
|
||||
# 3. Fallback: get first organization they're a member of
|
||||
stmt = select(OrganizationMember.organization_id).where(
|
||||
OrganizationMember.user_id == current_user.id
|
||||
).limit(1)
|
||||
result = await db.execute(stmt)
|
||||
org_row = result.first()
|
||||
|
||||
active_org_id = org_row[0] if org_row else None
|
||||
|
||||
# Create a response dictionary with the active_organization_id
|
||||
# Get first_name and last_name from person relation if available
|
||||
person = current_user.person
|
||||
first_name = person.first_name if person else ""
|
||||
last_name = person.last_name if person else ""
|
||||
|
||||
response_data = {
|
||||
"id": current_user.id,
|
||||
"email": current_user.email,
|
||||
"first_name": first_name,
|
||||
"last_name": last_name,
|
||||
"is_active": current_user.is_active,
|
||||
"region_code": current_user.region_code,
|
||||
"person_id": current_user.person_id,
|
||||
"role": current_user.role.value if hasattr(current_user.role, 'value') else str(current_user.role),
|
||||
"subscription_plan": current_user.subscription_plan,
|
||||
"scope_level": current_user.scope_level or "individual",
|
||||
"scope_id": str(active_org_id) if active_org_id else None,
|
||||
"ui_mode": current_user.ui_mode or "personal",
|
||||
"active_organization_id": active_org_id
|
||||
}
|
||||
|
||||
return UserResponse.model_validate(response_data)
|
||||
|
||||
@router.get("/me/trust")
|
||||
async def get_user_trust(
|
||||
|
||||
Reference in New Issue
Block a user