Create a new project in an organization. User must be an admin or owner of the organization.
(
*,
request: Request,
orm: Session = Depends(get_orm_session),
body: ProjectCreateSchema,
)
| 71 | |
| 72 | |
| 73 | def create_project( |
| 74 | *, |
| 75 | request: Request, |
| 76 | orm: Session = Depends(get_orm_session), |
| 77 | body: ProjectCreateSchema, |
| 78 | ) -> ProjectResponse: |
| 79 | """ |
| 80 | Create a new project in an organization. |
| 81 | User must be an admin or owner of the organization. |
| 82 | """ |
| 83 | org = OrgModel.get_by_id(orm, body.org_id) |
| 84 | |
| 85 | if not org or not org.is_user_admin_or_owner(request.state.session.user_id): |
| 86 | raise HTTPException(status_code=404, detail="Organization not found") |
| 87 | |
| 88 | if org.max_project_count and not org.current_project_count < org.max_project_count: |
| 89 | raise HTTPException(status_code=403, detail="Organization has reached it's project limit") |
| 90 | |
| 91 | environment = Environment(body.environment) if body.environment else Environment.development |
| 92 | project = ProjectModel( |
| 93 | name=body.name, |
| 94 | org_id=body.org_id, |
| 95 | environment=environment, |
| 96 | ) |
| 97 | |
| 98 | orm.add(project) |
| 99 | orm.commit() |
| 100 | |
| 101 | # explicitly load the project so we have all context needed for the response |
| 102 | project = ProjectModel.get_by_id(orm, project.id) |
| 103 | project.org.set_current_user(request.state.session.user_id) |
| 104 | return ProjectResponse.model_validate(project) |
| 105 | |
| 106 | |
| 107 | def update_project( |
searching dependent graphs…