Get all organizations for a user with relationships preloaded.
(cls, orm: orm.Session, user_id: str | UUID)
| 334 | |
| 335 | @classmethod |
| 336 | def get_all_for_user(cls, orm: orm.Session, user_id: str | UUID) -> Optional[list['OrgModel']]: |
| 337 | """Get all organizations for a user with relationships preloaded.""" |
| 338 | orgs = ( |
| 339 | orm.query(cls) |
| 340 | .options( |
| 341 | joinedload(cls.users), |
| 342 | joinedload(cls.invites), |
| 343 | joinedload(cls.projects), |
| 344 | ) |
| 345 | .join(UserOrgModel, UserOrgModel.org_id == cls.id) |
| 346 | .filter(UserOrgModel.user_id == normalize_uuid(user_id)) |
| 347 | .filter(cls.id != DEMO_ORG_ID) # TODO hard-code demo org and delete these rows |
| 348 | .all() |
| 349 | ) |
| 350 | for org in orgs: |
| 351 | # populate current user so `org.current_user_role` is available |
| 352 | org.set_current_user(user_id) |
| 353 | return orgs |
| 354 | |
| 355 | @classmethod |
| 356 | def get_all_for_user_summary(cls, orm: orm.Session, user_id: str | UUID) -> list['OrgModel']: |
no test coverage detected