diff --git a/libs/client-api/src/http_publish.rs b/libs/client-api/src/http_publish.rs index c8049faa..c45881f1 100644 --- a/libs/client-api/src/http_publish.rs +++ b/libs/client-api/src/http_publish.rs @@ -1,6 +1,5 @@ use database_entity::dto::UpdatePublishNamespace; use reqwest::Method; -use serde_json::json; use shared_entity::response::{AppResponse, AppResponseError}; use crate::Client; @@ -23,7 +22,7 @@ impl Client { pub async fn set_workspace_publish_namespace( &self, workspace_id: &str, - new_namespace: String, + new_namespace: &str, ) -> Result<(), AppResponseError> { let url = format!( "{}/api/workspace/{}/publish-namespace", @@ -33,7 +32,9 @@ impl Client { let resp = self .http_client_with_auth(Method::PUT, &url) .await? - .json(&UpdatePublishNamespace { new_namespace }) + .json(&UpdatePublishNamespace { + new_namespace: new_namespace.to_string(), + }) .send() .await?; @@ -64,7 +65,7 @@ impl Client { AppResponse::<()>::from_response(resp).await?.into_error() } - pub async fn get_publish_collab( + pub async fn get_published_collab( &self, workspace_id: &str, doc_name: &str, @@ -87,4 +88,28 @@ impl Client { .await?; Ok(resp) } + + pub async fn get_published_collab_using_publish_namespace( + &self, + publish_namespace: &str, + doc_name: &str, + ) -> Result + where + T: serde::de::DeserializeOwned + 'static, + { + let url = format!( + "{}/api/workspace/published/{}/{}", + self.base_url, publish_namespace, doc_name + ); + + let resp = self + .cloud_client + .get(&url) + .send() + .await? + .error_for_status()? + .json::() + .await?; + Ok(resp) + } } diff --git a/src/api/workspace.rs b/src/api/workspace.rs index 74038cd2..62c5d343 100644 --- a/src/api/workspace.rs +++ b/src/api/workspace.rs @@ -989,7 +989,7 @@ async fn get_publish_namespace_handler( async fn get_published_collab_handler( path_param: web::Path<(String, String)>, state: Data, -) -> Result>> { +) -> Result> { let (workspace_namespace, doc_name) = path_param.into_inner(); let metadata = biz::workspace::ops::get_published_collab_using_publish_namespace( &state.pg_pool, @@ -997,7 +997,7 @@ async fn get_published_collab_handler( &doc_name, ) .await?; - Ok(Json(AppResponse::Ok().with_data(metadata))) + Ok(Json(metadata)) } async fn get_published_collab_blob_handler( diff --git a/tests/workspace/publish.rs b/tests/workspace/publish.rs index f639dd00..89aa91a9 100644 --- a/tests/workspace/publish.rs +++ b/tests/workspace/publish.rs @@ -18,14 +18,14 @@ async fn test_set_publish_namespace_set() { let (c, _user) = generate_unique_registered_user_client().await; let workspace_id = get_first_workspace_string(&c).await; let namespace = uuid::Uuid::new_v4().to_string(); - c.set_workspace_publish_namespace(&workspace_id.to_string(), namespace.clone()) + c.set_workspace_publish_namespace(&workspace_id.to_string(), &namespace) .await .unwrap(); { // cannot set the same namespace let err = c - .set_workspace_publish_namespace(&workspace_id.to_string(), namespace.clone()) + .set_workspace_publish_namespace(&workspace_id.to_string(), &namespace) .await .err() .unwrap(); @@ -34,7 +34,7 @@ async fn test_set_publish_namespace_set() { { // can replace the namespace let namespace = uuid::Uuid::new_v4().to_string(); - c.set_workspace_publish_namespace(&workspace_id.to_string(), namespace.clone()) + c.set_workspace_publish_namespace(&workspace_id.to_string(), &namespace) .await .unwrap(); @@ -47,7 +47,7 @@ async fn test_set_publish_namespace_set() { { // cannot set namespace too short let err = c - .set_workspace_publish_namespace(&workspace_id.to_string(), "a".to_string()) // too short + .set_workspace_publish_namespace(&workspace_id.to_string(), "a") // too short .await .err() .unwrap(); @@ -57,7 +57,7 @@ async fn test_set_publish_namespace_set() { { // cannot set namespace with invalid chars let err = c - .set_workspace_publish_namespace(&workspace_id.to_string(), "/|(*&)(&#@!".to_string()) // invalid chars + .set_workspace_publish_namespace(&workspace_id.to_string(), "/|(*&)(&#@!") // invalid chars .await .err() .unwrap(); @@ -75,7 +75,7 @@ async fn test_publish_doc() { let (c, _user) = generate_unique_registered_user_client().await; let workspace_id = get_first_workspace_string(&c).await; let my_namespace = uuid::Uuid::new_v4().to_string(); - c.set_workspace_publish_namespace(&workspace_id.to_string(), my_namespace) + c.set_workspace_publish_namespace(&workspace_id.to_string(), &my_namespace) .await .unwrap(); @@ -93,7 +93,14 @@ async fn test_publish_doc() { // Non login user should be able to view the published collab metadata let non_login = localhost_client(); let published_collab = non_login - .get_publish_collab::(&workspace_id, "my_doc") + .get_published_collab::(&workspace_id, "my_doc") + .await + .unwrap(); + assert_eq!(published_collab.title, "my_title"); + + // using workspace publish_namespace instead + let published_collab = non_login + .get_published_collab_using_publish_namespace::(&my_namespace, "my_doc") .await .unwrap(); assert_eq!(published_collab.title, "my_title");