feat: add root view id of the created web template to duplicate published page response (#1159)
This commit is contained in:
parent
2e96be34b4
commit
4ddb08e0eb
|
|
@ -1,4 +1,5 @@
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
|
use client_api_entity::publish_dto::DuplicatePublishedPageResponse;
|
||||||
use client_api_entity::workspace_dto::{PublishInfoView, PublishedView};
|
use client_api_entity::workspace_dto::{PublishInfoView, PublishedView};
|
||||||
use client_api_entity::{workspace_dto::PublishedDuplicate, PublishInfo, UpdatePublishNamespace};
|
use client_api_entity::{workspace_dto::PublishedDuplicate, PublishInfo, UpdatePublishNamespace};
|
||||||
use client_api_entity::{
|
use client_api_entity::{
|
||||||
|
|
@ -410,7 +411,7 @@ impl Client {
|
||||||
&self,
|
&self,
|
||||||
workspace_id: &str,
|
workspace_id: &str,
|
||||||
publish_duplicate: &PublishedDuplicate,
|
publish_duplicate: &PublishedDuplicate,
|
||||||
) -> Result<(), AppResponseError> {
|
) -> Result<DuplicatePublishedPageResponse, AppResponseError> {
|
||||||
let url = format!(
|
let url = format!(
|
||||||
"{}/api/workspace/{}/published-duplicate",
|
"{}/api/workspace/{}/published-duplicate",
|
||||||
self.base_url, workspace_id
|
self.base_url, workspace_id
|
||||||
|
|
@ -422,7 +423,9 @@ impl Client {
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
log_request_id(&resp);
|
log_request_id(&resp);
|
||||||
AppResponse::<()>::from_response(resp).await?.into_error()
|
AppResponse::<DuplicatePublishedPageResponse>::from_response(resp)
|
||||||
|
.await?
|
||||||
|
.into_data()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_published_view_reactions(
|
pub async fn get_published_view_reactions(
|
||||||
|
|
|
||||||
|
|
@ -59,3 +59,8 @@ pub struct PublishDatabaseData {
|
||||||
/// Relation view id map
|
/// Relation view id map
|
||||||
pub database_relations: HashMap<String, String>,
|
pub database_relations: HashMap<String, String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Deserialize, Serialize, Clone, Debug, Eq, PartialEq)]
|
||||||
|
pub struct DuplicatePublishedPageResponse {
|
||||||
|
pub view_id: String,
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@ use indexer::scheduler::{UnindexedCollabTask, UnindexedData};
|
||||||
use prost::Message as ProstMessage;
|
use prost::Message as ProstMessage;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
|
use shared_entity::dto::publish_dto::DuplicatePublishedPageResponse;
|
||||||
use shared_entity::dto::workspace_dto::*;
|
use shared_entity::dto::workspace_dto::*;
|
||||||
use shared_entity::response::AppResponseError;
|
use shared_entity::response::AppResponseError;
|
||||||
use shared_entity::response::{AppResponse, JsonAppResponse};
|
use shared_entity::response::{AppResponse, JsonAppResponse};
|
||||||
|
|
@ -1781,25 +1782,30 @@ async fn post_published_duplicate_handler(
|
||||||
workspace_id: web::Path<String>,
|
workspace_id: web::Path<String>,
|
||||||
state: Data<AppState>,
|
state: Data<AppState>,
|
||||||
params: Json<PublishedDuplicate>,
|
params: Json<PublishedDuplicate>,
|
||||||
) -> Result<Json<AppResponse<()>>> {
|
) -> Result<Json<AppResponse<DuplicatePublishedPageResponse>>> {
|
||||||
let uid = state.user_cache.get_user_uid(&user_uuid).await?;
|
let uid = state.user_cache.get_user_uid(&user_uuid).await?;
|
||||||
state
|
state
|
||||||
.workspace_access_control
|
.workspace_access_control
|
||||||
.enforce_action(&uid, &workspace_id.to_string(), Action::Write)
|
.enforce_action(&uid, &workspace_id.to_string(), Action::Write)
|
||||||
.await?;
|
.await?;
|
||||||
let params = params.into_inner();
|
let params = params.into_inner();
|
||||||
biz::workspace::publish_dup::duplicate_published_collab_to_workspace(
|
let root_view_id_for_duplicate =
|
||||||
&state.pg_pool,
|
biz::workspace::publish_dup::duplicate_published_collab_to_workspace(
|
||||||
state.bucket_client.clone(),
|
&state.pg_pool,
|
||||||
state.collab_access_control_storage.clone(),
|
state.bucket_client.clone(),
|
||||||
uid,
|
state.collab_access_control_storage.clone(),
|
||||||
params.published_view_id,
|
uid,
|
||||||
workspace_id.into_inner(),
|
params.published_view_id,
|
||||||
params.dest_view_id,
|
workspace_id.into_inner(),
|
||||||
)
|
params.dest_view_id,
|
||||||
.await?;
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
Ok(Json(AppResponse::Ok()))
|
Ok(Json(AppResponse::Ok().with_data(
|
||||||
|
DuplicatePublishedPageResponse {
|
||||||
|
view_id: root_view_id_for_duplicate,
|
||||||
|
},
|
||||||
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn list_published_collab_info_handler(
|
async fn list_published_collab_info_handler(
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ pub async fn duplicate_published_collab_to_workspace(
|
||||||
publish_view_id: String,
|
publish_view_id: String,
|
||||||
dest_workspace_id: String,
|
dest_workspace_id: String,
|
||||||
dest_view_id: String,
|
dest_view_id: String,
|
||||||
) -> Result<(), AppError> {
|
) -> Result<String, AppError> {
|
||||||
let copier = PublishCollabDuplicator::new(
|
let copier = PublishCollabDuplicator::new(
|
||||||
pg_pool.clone(),
|
pg_pool.clone(),
|
||||||
bucket_client,
|
bucket_client,
|
||||||
|
|
@ -69,13 +69,13 @@ pub async fn duplicate_published_collab_to_workspace(
|
||||||
);
|
);
|
||||||
|
|
||||||
let time_now = chrono::Utc::now().timestamp_millis();
|
let time_now = chrono::Utc::now().timestamp_millis();
|
||||||
copier.duplicate(&publish_view_id).await?;
|
let root_view_id_for_duplicate = copier.duplicate(&publish_view_id).await?;
|
||||||
let elapsed = chrono::Utc::now().timestamp_millis() - time_now;
|
let elapsed = chrono::Utc::now().timestamp_millis() - time_now;
|
||||||
tracing::info!(
|
tracing::info!(
|
||||||
"duplicate_published_collab_to_workspace: elapsed time: {}ms",
|
"duplicate_published_collab_to_workspace: elapsed time: {}ms",
|
||||||
elapsed
|
elapsed
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(root_view_id_for_duplicate)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct PublishCollabDuplicator {
|
pub struct PublishCollabDuplicator {
|
||||||
|
|
@ -141,10 +141,14 @@ impl PublishCollabDuplicator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn duplicate(mut self, publish_view_id: &str) -> Result<(), AppError> {
|
async fn duplicate(mut self, publish_view_id: &str) -> Result<String, AppError> {
|
||||||
// new view after deep copy
|
// new view after deep copy
|
||||||
// this is the root of the document/database duplicated
|
// this is the root of the document/database duplicated
|
||||||
let mut root_view = match self.deep_copy(gen_view_id(), publish_view_id).await? {
|
let root_view_id = gen_view_id();
|
||||||
|
let mut root_view = match self
|
||||||
|
.deep_copy(root_view_id.clone(), publish_view_id)
|
||||||
|
.await?
|
||||||
|
{
|
||||||
Some(v) => v,
|
Some(v) => v,
|
||||||
None => {
|
None => {
|
||||||
return Err(AppError::RecordNotFound(
|
return Err(AppError::RecordNotFound(
|
||||||
|
|
@ -363,7 +367,7 @@ impl PublishCollabDuplicator {
|
||||||
dest_workspace_id,
|
dest_workspace_id,
|
||||||
encoded_update,
|
encoded_update,
|
||||||
));
|
));
|
||||||
Ok(())
|
Ok(root_view_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deep copy a published collab to the destination workspace.
|
/// Deep copy a published collab to the destination workspace.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue