diff --git a/.sqlx/query-e4567475b82642745a7a96ec273efe7b549beedbf7e17b5b18d459334c29aa82.json b/.sqlx/query-e4567475b82642745a7a96ec273efe7b549beedbf7e17b5b18d459334c29aa82.json new file mode 100644 index 000000000..7a31ad126 --- /dev/null +++ b/.sqlx/query-e4567475b82642745a7a96ec273efe7b549beedbf7e17b5b18d459334c29aa82.json @@ -0,0 +1,22 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT EXISTS(\n SELECT 1\n FROM af_workspace\n WHERE publish_namespace = $1\n )\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "exists", + "type_info": "Bool" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + null + ] + }, + "hash": "e4567475b82642745a7a96ec273efe7b549beedbf7e17b5b18d459334c29aa82" +} diff --git a/libs/database/src/publish.rs b/libs/database/src/publish.rs index 85311af5e..a874f5f22 100644 --- a/libs/database/src/publish.rs +++ b/libs/database/src/publish.rs @@ -35,7 +35,6 @@ pub async fn select_user_is_collab_publisher_for_all_views( #[inline] pub async fn select_workspace_publish_namespace_exists<'a, E: Executor<'a, Database = Postgres>>( executor: E, - workspace_id: &Uuid, namespace: &str, ) -> Result { let res = sqlx::query_scalar!( @@ -43,11 +42,9 @@ pub async fn select_workspace_publish_namespace_exists<'a, E: Executor<'a, Datab SELECT EXISTS( SELECT 1 FROM af_workspace - WHERE workspace_id = $1 - AND publish_namespace = $2 + WHERE publish_namespace = $1 ) "#, - workspace_id, namespace, ) .fetch_one(executor) diff --git a/src/biz/workspace/publish.rs b/src/biz/workspace/publish.rs index 06acb6057..09d5be8a3 100644 --- a/src/biz/workspace/publish.rs +++ b/src/biz/workspace/publish.rs @@ -91,7 +91,7 @@ pub async fn set_workspace_namespace( new_namespace: &str, ) -> Result<(), AppError> { check_workspace_namespace(new_namespace).await?; - if select_workspace_publish_namespace_exists(pg_pool, workspace_id, new_namespace).await? { + if select_workspace_publish_namespace_exists(pg_pool, new_namespace).await? { return Err(AppError::PublishNamespaceAlreadyTaken( "publish namespace is already taken".to_string(), )); diff --git a/tests/workspace/publish.rs b/tests/workspace/publish.rs index 9b3ffed7e..82c4896ae 100644 --- a/tests/workspace/publish.rs +++ b/tests/workspace/publish.rs @@ -44,6 +44,22 @@ async fn test_set_publish_namespace_set() { .await .unwrap(); + { + // another workspace cannot have the same namespace + let (c2, _user) = generate_unique_registered_user_client().await; + let workspace_id_2 = get_first_workspace_string(&c2).await; + let err = c2 + .set_workspace_publish_namespace(&workspace_id_2.to_string(), &namespace) + .await + .unwrap_err(); + assert_eq!( + err.code, + ErrorCode::PublishNamespaceAlreadyTaken, + "{:?}", + err + ); + } + { // cannot set the same namespace let err = c