Skip to content

Commit

Permalink
Check project name for duplicate
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyRonning committed Feb 24, 2025
1 parent 3c0c4dd commit ce42947
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/web/platform/org_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,24 @@ async fn create_project(
return Err(ApiError::Unauthorized);
}

// Check if a project with the same name already exists in this organization
if data
.db
.get_org_project_by_name_and_org(&create_request.name, org.id)
.map_err(|e| {
error!("Failed to check for existing project: {:?}", e);
ApiError::InternalServerError
})?
.is_some()
{
// Project with this name already exists
error!(
"Project with name '{}' already exists in this organization",
&create_request.name
);
return Err(ApiError::BadRequest);
}

// Create the project
let new_project = NewOrgProject::new(org.id, create_request.name).with_description(
create_request
Expand Down Expand Up @@ -558,6 +576,23 @@ async fn update_project(
// Update the project
let mut updated_project = project;
if let Some(name) = update_request.name {
// If name is changing, check if it conflicts with an existing project
if name != updated_project.name && data
.db
.get_org_project_by_name_and_org(&name, org.id)
.map_err(|e| {
error!("Failed to check for existing project: {:?}", e);
ApiError::InternalServerError
})?
.is_some()
{
// Project with this name already exists
error!(
"Project with name '{}' already exists in this organization",
&name
);
return Err(ApiError::BadRequest);
}
updated_project.name = name;
}
if let Some(description) = update_request.description {
Expand Down

0 comments on commit ce42947

Please sign in to comment.