fix: published doc alias
This commit is contained in:
parent
cb74f38ac8
commit
ae29bbe9fe
|
|
@ -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<T>(
|
||||
pub async fn get_published_collab<T>(
|
||||
&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<T>(
|
||||
&self,
|
||||
publish_namespace: &str,
|
||||
doc_name: &str,
|
||||
) -> Result<T, AppResponseError>
|
||||
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::<T>()
|
||||
.await?;
|
||||
Ok(resp)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -989,7 +989,7 @@ async fn get_publish_namespace_handler(
|
|||
async fn get_published_collab_handler(
|
||||
path_param: web::Path<(String, String)>,
|
||||
state: Data<AppState>,
|
||||
) -> Result<Json<AppResponse<serde_json::Value>>> {
|
||||
) -> Result<Json<serde_json::Value>> {
|
||||
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(
|
||||
|
|
|
|||
|
|
@ -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::<Metadata>(&workspace_id, "my_doc")
|
||||
.get_published_collab::<Metadata>(&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::<Metadata>(&my_namespace, "my_doc")
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(published_collab.title, "my_title");
|
||||
|
|
|
|||
Loading…
Reference in New Issue