MCPcopy Create free account
hub / github.com/AgentOps-AI/agentops / get_by_id_summary

Method get_by_id_summary

app/api/agentops/opsboard/models.py:429–484  ·  view source on GitHub ↗

Get an organization by ID with summary data only. Returns org with current user role but without loading all relationships.

(
        cls, orm: orm.Session, org_id: str | UUID, user_id: str | UUID
    )

Source from the content-addressed store, hash-verified

427
428 @classmethod
429 def get_by_id_summary(
430 cls, orm: orm.Session, org_id: str | UUID, user_id: str | UUID
431 ) -> Optional['OrgModel']:
432 """
433 Get an organization by ID with summary data only.
434 Returns org with current user role but without loading all relationships.
435 """
436 from sqlalchemy import func
437
438 org_id = normalize_uuid(org_id)
439 user_id = normalize_uuid(user_id)
440
441 # Get org with user role
442 result = (
443 orm.query(cls, UserOrgModel.role)
444 .join(UserOrgModel, (UserOrgModel.org_id == cls.id) & (UserOrgModel.user_id == user_id))
445 .filter(cls.id == org_id)
446 .first()
447 )
448
449 if result:
450 org, role = result
451 org._current_user_role = role
452 org._current_user_id = user_id
453
454 # Calculate counts separately
455 user_count = (
456 orm.query(func.count(UserOrgModel.user_id)).filter(UserOrgModel.org_id == org.id).scalar()
457 or 0
458 )
459 invite_count = (
460 orm.query(func.count(OrgInviteModel.invitee_email))
461 .filter(OrgInviteModel.org_id == org.id)
462 .scalar()
463 or 0
464 )
465 project_count = (
466 orm.query(func.count(ProjectModel.id)).filter(ProjectModel.org_id == org.id).scalar() or 0
467 )
468
469 # Calculate paid member count separately
470 paid_user_count = (
471 orm.query(func.count(UserOrgModel.user_id))
472 .filter(UserOrgModel.org_id == org.id, UserOrgModel.is_paid)
473 .scalar()
474 or 0
475 )
476
477 org._member_count = user_count + invite_count
478 org._user_count = user_count # Store user count separately for billing
479 org._invite_count = invite_count # Store invite count separately
480 org._project_count = project_count
481 org._paid_member_count = paid_user_count # Store paid member count
482 return org
483
484 return None
485
486 @classmethod

Callers 3

update_orgFunction · 0.80
__call__Method · 0.80

Calls 2

normalize_uuidFunction · 0.70
filterMethod · 0.45

Tested by

no test coverage detected