Skip to content

Commit

Permalink
fix: check for existing project name (#1285)
Browse files Browse the repository at this point in the history
* feat:Add check for existing project name in create_project endpoint

* refactor sql and check case insensitively

---------

Co-authored-by: sujanadh <[email protected]>
  • Loading branch information
Sujanadh and sujanadh authored Feb 27, 2024
1 parent d5db571 commit 45c3238
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/backend/app/projects/project_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,24 @@ async def create_project(
)
odk_creds_decrypted = await organisation_deps.get_org_odk_creds(db_org)

sql = text(
"""
SELECT EXISTS (
SELECT 1
FROM project_info
WHERE LOWER(name) = :project_name
)
"""
)
result = db.execute(sql, {"project_name": project_info.project_info.name.lower()})
project_exists = result.fetchone()[0]
if project_exists:
raise HTTPException(
status_code=400,
detail=f"Project already exists with the name "
f"{project_info.project_info.name}",
)

odkproject = central_crud.create_odk_project(
project_info.project_info.name,
odk_creds_decrypted,
Expand Down

0 comments on commit 45c3238

Please sign in to comment.