Delete an organization. User must be the owner. Organization cannot be deleted if it still contains projects.
(
*,
request: Request,
org_id: str,
orm: Session = Depends(get_orm_session),
)
| 821 | |
| 822 | |
| 823 | def delete_org( |
| 824 | *, |
| 825 | request: Request, |
| 826 | org_id: str, |
| 827 | orm: Session = Depends(get_orm_session), |
| 828 | ) -> StatusResponse: |
| 829 | """ |
| 830 | Delete an organization. User must be the owner. |
| 831 | Organization cannot be deleted if it still contains projects. |
| 832 | """ |
| 833 | org: Optional[OrgModel] = OrgModel.get_by_id(orm, org_id) |
| 834 | |
| 835 | if not org or not org.is_user_owner(request.state.session.user_id): |
| 836 | raise HTTPException(status_code=403, detail="Organization cannot be deleted") |
| 837 | |
| 838 | if org.projects: |
| 839 | raise HTTPException( |
| 840 | status_code=400, |
| 841 | detail="Organization cannot be deleted while it still contains projects", |
| 842 | ) |
| 843 | |
| 844 | orm.delete(org) |
| 845 | orm.commit() |
| 846 | |
| 847 | return StatusResponse(message="Organization deleted") |
| 848 | |
| 849 | |
| 850 | class UpdateMemberLicensesBody(pydantic.BaseModel): |
searching dependent graphs…