Update a project's name or environment. User must be an admin or owner of the organization.
(
*,
request: Request,
project_id: str,
orm: Session = Depends(get_orm_session),
body: ProjectUpdateSchema,
)
| 105 | |
| 106 | |
| 107 | def update_project( |
| 108 | *, |
| 109 | request: Request, |
| 110 | project_id: str, |
| 111 | orm: Session = Depends(get_orm_session), |
| 112 | body: ProjectUpdateSchema, |
| 113 | ) -> ProjectResponse: |
| 114 | """ |
| 115 | Update a project's name or environment. |
| 116 | User must be an admin or owner of the organization. |
| 117 | """ |
| 118 | project = ProjectModel.get_by_id(orm, project_id) |
| 119 | |
| 120 | if not project: |
| 121 | raise HTTPException(status_code=404, detail="Project not found") |
| 122 | |
| 123 | if not project.org.is_user_admin_or_owner(request.state.session.user_id): |
| 124 | raise HTTPException(status_code=403, detail="You don't have permission to update this project") |
| 125 | |
| 126 | if body.name is not None: |
| 127 | project.name = body.name |
| 128 | |
| 129 | if body.environment is not None: |
| 130 | try: |
| 131 | project.environment = Environment(body.environment) |
| 132 | except ValueError: |
| 133 | raise HTTPException(status_code=400, detail="Invalid environment") |
| 134 | |
| 135 | orm.commit() |
| 136 | |
| 137 | # reload project cuz it's more flexible than calling orm.refresh with args |
| 138 | project = ProjectModel.get_by_id(orm, project.id) |
| 139 | project.org.set_current_user(request.state.session.user_id) |
| 140 | return ProjectResponse.model_validate(project) |
| 141 | |
| 142 | |
| 143 | def delete_project( |
searching dependent graphs…