Get all projects the user has access to across all organizations they belong to.
(cls, orm: orm.Session, user_id: str | UUID)
| 671 | |
| 672 | @classmethod |
| 673 | def get_all_for_user(cls, orm: orm.Session, user_id: str | UUID) -> list['ProjectModel']: |
| 674 | """Get all projects the user has access to across all organizations they belong to.""" |
| 675 | projects = ( |
| 676 | orm.query(cls) |
| 677 | .join(OrgModel, cls.org_id == OrgModel.id) |
| 678 | .join( |
| 679 | UserOrgModel, |
| 680 | UserOrgModel.org_id == OrgModel.id, |
| 681 | ) |
| 682 | .filter(UserOrgModel.user_id == normalize_uuid(user_id)) |
| 683 | .filter(OrgModel.id != DEMO_ORG_ID) # TODO hard-code demo org and delete these rows |
| 684 | .options( |
| 685 | joinedload(cls.org).joinedload(OrgModel.users), |
| 686 | joinedload(cls.org).joinedload(OrgModel.invites), |
| 687 | joinedload(cls.org).joinedload(OrgModel.projects), |
| 688 | ) |
| 689 | .all() |
| 690 | ) |
| 691 | |
| 692 | # Set the current user for each project's org |
| 693 | for project in projects: |
| 694 | project.org.set_current_user(user_id) |
| 695 | |
| 696 | return projects |
| 697 | |
| 698 | @classmethod |
| 699 | def get_all_for_user_optimized(cls, orm: orm.Session, user_id: str | UUID) -> list['ProjectModel']: |
nothing calls this directly
no test coverage detected