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 client_api_entity::publish_dto::DuplicatePublishedPageResponse;
|
||||
use client_api_entity::workspace_dto::{PublishInfoView, PublishedView};
|
||||
use client_api_entity::{workspace_dto::PublishedDuplicate, PublishInfo, UpdatePublishNamespace};
|
||||
use client_api_entity::{
|
||||
|
|
@ -410,7 +411,7 @@ impl Client {
|
|||
&self,
|
||||
workspace_id: &str,
|
||||
publish_duplicate: &PublishedDuplicate,
|
||||
) -> Result<(), AppResponseError> {
|
||||
) -> Result<DuplicatePublishedPageResponse, AppResponseError> {
|
||||
let url = format!(
|
||||
"{}/api/workspace/{}/published-duplicate",
|
||||
self.base_url, workspace_id
|
||||
|
|
@ -422,7 +423,9 @@ impl Client {
|
|||
.send()
|
||||
.await?;
|
||||
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(
|
||||
|
|
|
|||
|
|
@ -59,3 +59,8 @@ pub struct PublishDatabaseData {
|
|||
/// Relation view id map
|
||||
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 rayon::prelude::*;
|
||||
use sha2::{Digest, Sha256};
|
||||
use shared_entity::dto::publish_dto::DuplicatePublishedPageResponse;
|
||||
use shared_entity::dto::workspace_dto::*;
|
||||
use shared_entity::response::AppResponseError;
|
||||
use shared_entity::response::{AppResponse, JsonAppResponse};
|
||||
|
|
@ -1781,25 +1782,30 @@ async fn post_published_duplicate_handler(
|
|||
workspace_id: web::Path<String>,
|
||||
state: Data<AppState>,
|
||||
params: Json<PublishedDuplicate>,
|
||||
) -> Result<Json<AppResponse<()>>> {
|
||||
) -> Result<Json<AppResponse<DuplicatePublishedPageResponse>>> {
|
||||
let uid = state.user_cache.get_user_uid(&user_uuid).await?;
|
||||
state
|
||||
.workspace_access_control
|
||||
.enforce_action(&uid, &workspace_id.to_string(), Action::Write)
|
||||
.await?;
|
||||
let params = params.into_inner();
|
||||
biz::workspace::publish_dup::duplicate_published_collab_to_workspace(
|
||||
&state.pg_pool,
|
||||
state.bucket_client.clone(),
|
||||
state.collab_access_control_storage.clone(),
|
||||
uid,
|
||||
params.published_view_id,
|
||||
workspace_id.into_inner(),
|
||||
params.dest_view_id,
|
||||
)
|
||||
.await?;
|
||||
let root_view_id_for_duplicate =
|
||||
biz::workspace::publish_dup::duplicate_published_collab_to_workspace(
|
||||
&state.pg_pool,
|
||||
state.bucket_client.clone(),
|
||||
state.collab_access_control_storage.clone(),
|
||||
uid,
|
||||
params.published_view_id,
|
||||
workspace_id.into_inner(),
|
||||
params.dest_view_id,
|
||||
)
|
||||
.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(
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ pub async fn duplicate_published_collab_to_workspace(
|
|||
publish_view_id: String,
|
||||
dest_workspace_id: String,
|
||||
dest_view_id: String,
|
||||
) -> Result<(), AppError> {
|
||||
) -> Result<String, AppError> {
|
||||
let copier = PublishCollabDuplicator::new(
|
||||
pg_pool.clone(),
|
||||
bucket_client,
|
||||
|
|
@ -69,13 +69,13 @@ pub async fn duplicate_published_collab_to_workspace(
|
|||
);
|
||||
|
||||
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;
|
||||
tracing::info!(
|
||||
"duplicate_published_collab_to_workspace: elapsed time: {}ms",
|
||||
elapsed
|
||||
);
|
||||
Ok(())
|
||||
Ok(root_view_id_for_duplicate)
|
||||
}
|
||||
|
||||
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
|
||||
// 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,
|
||||
None => {
|
||||
return Err(AppError::RecordNotFound(
|
||||
|
|
@ -363,7 +367,7 @@ impl PublishCollabDuplicator {
|
|||
dest_workspace_id,
|
||||
encoded_update,
|
||||
));
|
||||
Ok(())
|
||||
Ok(root_view_id)
|
||||
}
|
||||
|
||||
/// Deep copy a published collab to the destination workspace.
|
||||
|
|
|
|||
Loading…
Reference in New Issue