feat: change doc name to publish name
This commit is contained in:
parent
af9850817a
commit
0bf6d3bd60
|
|
@ -80,14 +80,14 @@ impl Client {
|
||||||
pub async fn get_published_collab<T>(
|
pub async fn get_published_collab<T>(
|
||||||
&self,
|
&self,
|
||||||
publish_namespace: &str,
|
publish_namespace: &str,
|
||||||
doc_name: &str,
|
publish_name: &str,
|
||||||
) -> Result<T, AppResponseError>
|
) -> Result<T, AppResponseError>
|
||||||
where
|
where
|
||||||
T: serde::de::DeserializeOwned,
|
T: serde::de::DeserializeOwned,
|
||||||
{
|
{
|
||||||
let url = format!(
|
let url = format!(
|
||||||
"{}/api/workspace/published/{}/{}",
|
"{}/api/workspace/published/{}/{}",
|
||||||
self.base_url, publish_namespace, doc_name
|
self.base_url, publish_namespace, publish_name
|
||||||
);
|
);
|
||||||
|
|
||||||
let resp = self
|
let resp = self
|
||||||
|
|
@ -110,11 +110,11 @@ impl Client {
|
||||||
pub async fn get_published_collab_blob(
|
pub async fn get_published_collab_blob(
|
||||||
&self,
|
&self,
|
||||||
publish_namespace: &str,
|
publish_namespace: &str,
|
||||||
doc_name: &str,
|
publish_name: &str,
|
||||||
) -> Result<Bytes, AppResponseError> {
|
) -> Result<Bytes, AppResponseError> {
|
||||||
let url = format!(
|
let url = format!(
|
||||||
"{}/api/workspace/published/{}/{}/blob",
|
"{}/api/workspace/published/{}/{}/blob",
|
||||||
self.base_url, publish_namespace, doc_name
|
self.base_url, publish_namespace, publish_name
|
||||||
);
|
);
|
||||||
let bytes = self
|
let bytes = self
|
||||||
.cloud_client
|
.cloud_client
|
||||||
|
|
|
||||||
|
|
@ -309,7 +309,7 @@ pub struct AFCollabMember {
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct PublishInfo {
|
pub struct PublishInfo {
|
||||||
pub namespace: Option<String>,
|
pub namespace: Option<String>,
|
||||||
pub doc_name: String,
|
pub publish_name: String,
|
||||||
pub view_id: Uuid,
|
pub view_id: Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -766,7 +766,7 @@ pub struct CreateAnswerMessageParams {
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct PublishCollabMetadata<Metadata> {
|
pub struct PublishCollabMetadata<Metadata> {
|
||||||
pub view_id: uuid::Uuid,
|
pub view_id: uuid::Uuid,
|
||||||
pub doc_name: String,
|
pub publish_name: String,
|
||||||
pub metadata: Metadata,
|
pub metadata: Metadata,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -896,9 +896,9 @@ pub async fn insert_or_replace_publish_collab_metas<'a, E: Executor<'a, Database
|
||||||
publish_item: &[PublishCollabItem<serde_json::Value, Vec<u8>>],
|
publish_item: &[PublishCollabItem<serde_json::Value, Vec<u8>>],
|
||||||
) -> Result<(), AppError> {
|
) -> Result<(), AppError> {
|
||||||
let view_ids: Vec<Uuid> = publish_item.iter().map(|item| item.meta.view_id).collect();
|
let view_ids: Vec<Uuid> = publish_item.iter().map(|item| item.meta.view_id).collect();
|
||||||
let doc_names: Vec<String> = publish_item
|
let publish_names: Vec<String> = publish_item
|
||||||
.iter()
|
.iter()
|
||||||
.map(|item| item.meta.doc_name.clone())
|
.map(|item| item.meta.publish_name.clone())
|
||||||
.collect();
|
.collect();
|
||||||
let metadatas: Vec<serde_json::Value> = publish_item
|
let metadatas: Vec<serde_json::Value> = publish_item
|
||||||
.iter()
|
.iter()
|
||||||
|
|
@ -908,7 +908,7 @@ pub async fn insert_or_replace_publish_collab_metas<'a, E: Executor<'a, Database
|
||||||
let blobs: Vec<Vec<u8>> = publish_item.iter().map(|item| item.data.clone()).collect();
|
let blobs: Vec<Vec<u8>> = publish_item.iter().map(|item| item.data.clone()).collect();
|
||||||
let res = sqlx::query!(
|
let res = sqlx::query!(
|
||||||
r#"
|
r#"
|
||||||
INSERT INTO af_published_collab (workspace_id, view_id, doc_name, published_by, metadata, blob)
|
INSERT INTO af_published_collab (workspace_id, view_id, publish_name, published_by, metadata, blob)
|
||||||
SELECT * FROM UNNEST(
|
SELECT * FROM UNNEST(
|
||||||
(SELECT array_agg((SELECT $1::uuid)) FROM generate_series(1, $7))::uuid[],
|
(SELECT array_agg((SELECT $1::uuid)) FROM generate_series(1, $7))::uuid[],
|
||||||
$2::uuid[],
|
$2::uuid[],
|
||||||
|
|
@ -922,7 +922,7 @@ pub async fn insert_or_replace_publish_collab_metas<'a, E: Executor<'a, Database
|
||||||
"#,
|
"#,
|
||||||
workspace_id,
|
workspace_id,
|
||||||
&view_ids,
|
&view_ids,
|
||||||
&doc_names,
|
&publish_names,
|
||||||
publisher_uuid,
|
publisher_uuid,
|
||||||
&metadatas,
|
&metadatas,
|
||||||
&blobs,
|
&blobs,
|
||||||
|
|
@ -945,17 +945,17 @@ pub async fn insert_or_replace_publish_collab_metas<'a, E: Executor<'a, Database
|
||||||
pub async fn select_publish_collab_meta<'a, E: Executor<'a, Database = Postgres>>(
|
pub async fn select_publish_collab_meta<'a, E: Executor<'a, Database = Postgres>>(
|
||||||
executor: E,
|
executor: E,
|
||||||
publish_namespace: &str,
|
publish_namespace: &str,
|
||||||
doc_name: &str,
|
publish_name: &str,
|
||||||
) -> Result<serde_json::Value, AppError> {
|
) -> Result<serde_json::Value, AppError> {
|
||||||
let res = sqlx::query!(
|
let res = sqlx::query!(
|
||||||
r#"
|
r#"
|
||||||
SELECT metadata
|
SELECT metadata
|
||||||
FROM af_published_collab
|
FROM af_published_collab
|
||||||
WHERE workspace_id = (SELECT workspace_id FROM af_workspace WHERE publish_namespace = $1)
|
WHERE workspace_id = (SELECT workspace_id FROM af_workspace WHERE publish_namespace = $1)
|
||||||
AND doc_name = $2
|
AND publish_name = $2
|
||||||
"#,
|
"#,
|
||||||
publish_namespace,
|
publish_namespace,
|
||||||
doc_name,
|
publish_name,
|
||||||
)
|
)
|
||||||
.fetch_one(executor)
|
.fetch_one(executor)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
@ -997,17 +997,17 @@ pub async fn delete_published_collabs<'a, E: Executor<'a, Database = Postgres>>(
|
||||||
pub async fn select_published_collab_blob<'a, E: Executor<'a, Database = Postgres>>(
|
pub async fn select_published_collab_blob<'a, E: Executor<'a, Database = Postgres>>(
|
||||||
executor: E,
|
executor: E,
|
||||||
publish_namespace: &str,
|
publish_namespace: &str,
|
||||||
doc_name: &str,
|
publish_name: &str,
|
||||||
) -> Result<Vec<u8>, AppError> {
|
) -> Result<Vec<u8>, AppError> {
|
||||||
let res = sqlx::query_scalar!(
|
let res = sqlx::query_scalar!(
|
||||||
r#"
|
r#"
|
||||||
SELECT blob
|
SELECT blob
|
||||||
FROM af_published_collab
|
FROM af_published_collab
|
||||||
WHERE workspace_id = (SELECT workspace_id FROM af_workspace WHERE publish_namespace = $1)
|
WHERE workspace_id = (SELECT workspace_id FROM af_workspace WHERE publish_namespace = $1)
|
||||||
AND doc_name = $2
|
AND publish_name = $2
|
||||||
"#,
|
"#,
|
||||||
publish_namespace,
|
publish_namespace,
|
||||||
doc_name,
|
publish_name,
|
||||||
)
|
)
|
||||||
.fetch_one(executor)
|
.fetch_one(executor)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
@ -1024,7 +1024,7 @@ pub async fn select_published_collab_info<'a, E: Executor<'a, Database = Postgre
|
||||||
r#"
|
r#"
|
||||||
SELECT
|
SELECT
|
||||||
(SELECT publish_namespace FROM af_workspace aw WHERE aw.workspace_id = apc.workspace_id) AS namespace,
|
(SELECT publish_namespace FROM af_workspace aw WHERE aw.workspace_id = apc.workspace_id) AS namespace,
|
||||||
doc_name,
|
publish_name,
|
||||||
view_id
|
view_id
|
||||||
FROM af_published_collab apc
|
FROM af_published_collab apc
|
||||||
WHERE view_id = $1
|
WHERE view_id = $1
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE af_published_collab RENAME COLUMN doc_name TO publish_name;
|
||||||
|
|
@ -128,11 +128,11 @@ pub fn workspace_scope() -> Scope {
|
||||||
.route(web::delete().to(remove_collab_member_handler)),
|
.route(web::delete().to(remove_collab_member_handler)),
|
||||||
)
|
)
|
||||||
.service(
|
.service(
|
||||||
web::resource("/published/{publish_namespace}/{doc_name}")
|
web::resource("/published/{publish_namespace}/{publish_name}")
|
||||||
.route(web::get().to(get_published_collab_handler))
|
.route(web::get().to(get_published_collab_handler))
|
||||||
)
|
)
|
||||||
.service(
|
.service(
|
||||||
web::resource("/published/{publish_namespace}/{doc_name}/blob")
|
web::resource("/published/{publish_namespace}/{publish_name}/blob")
|
||||||
.route(web::get().to(get_published_collab_blob_handler))
|
.route(web::get().to(get_published_collab_blob_handler))
|
||||||
)
|
)
|
||||||
.service(
|
.service(
|
||||||
|
|
@ -970,9 +970,9 @@ async fn get_published_collab_handler(
|
||||||
path_param: web::Path<(String, String)>,
|
path_param: web::Path<(String, String)>,
|
||||||
state: Data<AppState>,
|
state: Data<AppState>,
|
||||||
) -> Result<Json<serde_json::Value>> {
|
) -> Result<Json<serde_json::Value>> {
|
||||||
let (workspace_namespace, doc_name) = path_param.into_inner();
|
let (workspace_namespace, publish_name) = path_param.into_inner();
|
||||||
let metadata =
|
let metadata =
|
||||||
biz::workspace::ops::get_published_collab(&state.pg_pool, &workspace_namespace, &doc_name)
|
biz::workspace::ops::get_published_collab(&state.pg_pool, &workspace_namespace, &publish_name)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(Json(metadata))
|
Ok(Json(metadata))
|
||||||
}
|
}
|
||||||
|
|
@ -981,10 +981,13 @@ async fn get_published_collab_blob_handler(
|
||||||
path_param: web::Path<(String, String)>,
|
path_param: web::Path<(String, String)>,
|
||||||
state: Data<AppState>,
|
state: Data<AppState>,
|
||||||
) -> Result<Vec<u8>> {
|
) -> Result<Vec<u8>> {
|
||||||
let (publish_namespace, doc_name) = path_param.into_inner();
|
let (publish_namespace, publish_name) = path_param.into_inner();
|
||||||
let collab_data =
|
let collab_data = biz::workspace::ops::get_published_collab_blob(
|
||||||
biz::workspace::ops::get_published_collab_blob(&state.pg_pool, &publish_namespace, &doc_name)
|
&state.pg_pool,
|
||||||
.await?;
|
&publish_namespace,
|
||||||
|
&publish_name,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
Ok(collab_data)
|
Ok(collab_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -150,7 +150,7 @@ pub async fn publish_collabs(
|
||||||
publish_items: &[PublishCollabItem<serde_json::Value, Vec<u8>>],
|
publish_items: &[PublishCollabItem<serde_json::Value, Vec<u8>>],
|
||||||
) -> Result<(), AppError> {
|
) -> Result<(), AppError> {
|
||||||
for publish_item in publish_items {
|
for publish_item in publish_items {
|
||||||
check_collab_doc_name(publish_item.meta.doc_name.as_str())?;
|
check_collab_publish_name(publish_item.meta.publish_name.as_str())?;
|
||||||
}
|
}
|
||||||
insert_or_replace_publish_collab_metas(pg_pool, workspace_id, publisher_uuid, publish_items)
|
insert_or_replace_publish_collab_metas(pg_pool, workspace_id, publisher_uuid, publish_items)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
@ -160,18 +160,18 @@ pub async fn publish_collabs(
|
||||||
pub async fn get_published_collab(
|
pub async fn get_published_collab(
|
||||||
pg_pool: &PgPool,
|
pg_pool: &PgPool,
|
||||||
publish_namespace: &str,
|
publish_namespace: &str,
|
||||||
doc_name: &str,
|
publish_name: &str,
|
||||||
) -> Result<serde_json::Value, AppError> {
|
) -> Result<serde_json::Value, AppError> {
|
||||||
let metadata = select_publish_collab_meta(pg_pool, publish_namespace, doc_name).await?;
|
let metadata = select_publish_collab_meta(pg_pool, publish_namespace, publish_name).await?;
|
||||||
Ok(metadata)
|
Ok(metadata)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_published_collab_blob(
|
pub async fn get_published_collab_blob(
|
||||||
pg_pool: &PgPool,
|
pg_pool: &PgPool,
|
||||||
publish_namespace: &str,
|
publish_namespace: &str,
|
||||||
doc_name: &str,
|
publish_name: &str,
|
||||||
) -> Result<Vec<u8>, AppError> {
|
) -> Result<Vec<u8>, AppError> {
|
||||||
select_published_collab_blob(pg_pool, publish_namespace, doc_name).await
|
select_published_collab_blob(pg_pool, publish_namespace, publish_name).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_published_collab_info(
|
pub async fn get_published_collab_info(
|
||||||
|
|
@ -589,16 +589,16 @@ async fn check_workspace_owner_or_publisher(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_collab_doc_name(doc_name: &str) -> Result<(), AppError> {
|
fn check_collab_publish_name(publish_name: &str) -> Result<(), AppError> {
|
||||||
// Check len
|
// Check len
|
||||||
if doc_name.len() > 20 {
|
if publish_name.len() > 20 {
|
||||||
return Err(AppError::InvalidRequest(
|
return Err(AppError::InvalidRequest(
|
||||||
"Document name must be at most 20 characters long".to_string(),
|
"Document name must be at most 20 characters long".to_string(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only contain alphanumeric characters and hyphens
|
// Only contain alphanumeric characters and hyphens
|
||||||
for c in doc_name.chars() {
|
for c in publish_name.chars() {
|
||||||
if !c.is_alphanumeric() && c != '-' {
|
if !c.is_alphanumeric() && c != '-' {
|
||||||
return Err(AppError::InvalidRequest(
|
return Err(AppError::InvalidRequest(
|
||||||
"Document name must only contain alphanumeric characters and hyphens".to_string(),
|
"Document name must only contain alphanumeric characters and hyphens".to_string(),
|
||||||
|
|
|
||||||
|
|
@ -73,9 +73,9 @@ async fn test_publish_doc() {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let doc_name_1 = "doc1";
|
let publish_name_1 = "publish_name_1";
|
||||||
let view_id_1 = uuid::Uuid::new_v4();
|
let view_id_1 = uuid::Uuid::new_v4();
|
||||||
let doc_name_2 = "doc2";
|
let publish_name_2 = "publish_name_2";
|
||||||
let view_id_2 = uuid::Uuid::new_v4();
|
let view_id_2 = uuid::Uuid::new_v4();
|
||||||
c.publish_collabs::<MyCustomMetadata, &[u8]>(
|
c.publish_collabs::<MyCustomMetadata, &[u8]>(
|
||||||
&workspace_id,
|
&workspace_id,
|
||||||
|
|
@ -83,7 +83,7 @@ async fn test_publish_doc() {
|
||||||
PublishCollabItem {
|
PublishCollabItem {
|
||||||
meta: PublishCollabMetadata {
|
meta: PublishCollabMetadata {
|
||||||
view_id: view_id_1,
|
view_id: view_id_1,
|
||||||
doc_name: doc_name_1.to_string(),
|
publish_name: publish_name_1.to_string(),
|
||||||
metadata: MyCustomMetadata {
|
metadata: MyCustomMetadata {
|
||||||
title: "my_title_1".to_string(),
|
title: "my_title_1".to_string(),
|
||||||
},
|
},
|
||||||
|
|
@ -93,7 +93,7 @@ async fn test_publish_doc() {
|
||||||
PublishCollabItem {
|
PublishCollabItem {
|
||||||
meta: PublishCollabMetadata {
|
meta: PublishCollabMetadata {
|
||||||
view_id: view_id_2,
|
view_id: view_id_2,
|
||||||
doc_name: doc_name_2.to_string(),
|
publish_name: publish_name_2.to_string(),
|
||||||
metadata: MyCustomMetadata {
|
metadata: MyCustomMetadata {
|
||||||
title: "my_title_2".to_string(),
|
title: "my_title_2".to_string(),
|
||||||
},
|
},
|
||||||
|
|
@ -109,7 +109,7 @@ async fn test_publish_doc() {
|
||||||
// Non login user should be able to view the published collab
|
// Non login user should be able to view the published collab
|
||||||
let guest_client = localhost_client();
|
let guest_client = localhost_client();
|
||||||
let published_collab = guest_client
|
let published_collab = guest_client
|
||||||
.get_published_collab::<MyCustomMetadata>(&my_namespace, doc_name_1)
|
.get_published_collab::<MyCustomMetadata>(&my_namespace, publish_name_1)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(published_collab.title, "my_title_1");
|
assert_eq!(published_collab.title, "my_title_1");
|
||||||
|
|
@ -119,11 +119,11 @@ async fn test_publish_doc() {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(publish_info.namespace, Some(my_namespace.clone()));
|
assert_eq!(publish_info.namespace, Some(my_namespace.clone()));
|
||||||
assert_eq!(publish_info.doc_name, doc_name_1);
|
assert_eq!(publish_info.publish_name, publish_name_1);
|
||||||
assert_eq!(publish_info.view_id, view_id_1);
|
assert_eq!(publish_info.view_id, view_id_1);
|
||||||
|
|
||||||
let blob = guest_client
|
let blob = guest_client
|
||||||
.get_published_collab_blob(&my_namespace, doc_name_1)
|
.get_published_collab_blob(&my_namespace, publish_name_1)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(blob, "yrs_encoded_data_1");
|
assert_eq!(blob, "yrs_encoded_data_1");
|
||||||
|
|
@ -137,7 +137,7 @@ async fn test_publish_doc() {
|
||||||
// Deleted collab should not be accessible
|
// Deleted collab should not be accessible
|
||||||
let guest_client = localhost_client();
|
let guest_client = localhost_client();
|
||||||
let err = guest_client
|
let err = guest_client
|
||||||
.get_published_collab::<MyCustomMetadata>(&my_namespace, doc_name_1)
|
.get_published_collab::<MyCustomMetadata>(&my_namespace, publish_name_1)
|
||||||
.await
|
.await
|
||||||
.err()
|
.err()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
@ -145,7 +145,7 @@ async fn test_publish_doc() {
|
||||||
|
|
||||||
let guest_client = localhost_client();
|
let guest_client = localhost_client();
|
||||||
let err = guest_client
|
let err = guest_client
|
||||||
.get_published_collab_blob(&my_namespace, doc_name_1)
|
.get_published_collab_blob(&my_namespace, publish_name_1)
|
||||||
.await
|
.await
|
||||||
.err()
|
.err()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
@ -177,9 +177,9 @@ async fn test_publish_load_test() {
|
||||||
.map(|i| PublishCollabItem {
|
.map(|i| PublishCollabItem {
|
||||||
meta: PublishCollabMetadata {
|
meta: PublishCollabMetadata {
|
||||||
view_id: uuid::Uuid::new_v4(),
|
view_id: uuid::Uuid::new_v4(),
|
||||||
doc_name: format!("doc{}", i),
|
publish_name: format!("publish_name_{}", i),
|
||||||
metadata: MyCustomMetadata {
|
metadata: MyCustomMetadata {
|
||||||
title: format!("title{}", i),
|
title: format!("title_{}", i),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
data: vec![0; 100_000], // 100 KB
|
data: vec![0; 100_000], // 100 KB
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue