Skip to content

Commit

Permalink
Merge pull request #959 from AppFlowy-IO/fix/custom-namespace-taken
Browse files Browse the repository at this point in the history
fix: namespace already taken
  • Loading branch information
speed2exe authored Nov 3, 2024
2 parents a5a5a6b + d6d7e73 commit 1fbb971
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions libs/database/src/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,16 @@ 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<bool, AppError> {
let res = sqlx::query_scalar!(
r#"
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)
Expand Down
2 changes: 1 addition & 1 deletion src/biz/workspace/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
));
Expand Down
16 changes: 16 additions & 0 deletions tests/workspace/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1fbb971

Please sign in to comment.