fix: get page view should handle situation where last editor or document owner cannot be found (#1171)

This commit is contained in:
Khor Shu Heng 2025-01-19 22:46:18 +08:00 committed by GitHub
parent e958dda0b8
commit eb53361a2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 4 deletions

View File

@ -251,7 +251,10 @@ pub async fn select_name_and_email_from_uuid(
Ok((row.name, row.email))
}
pub async fn select_web_user_from_uid(pool: &PgPool, uid: i64) -> Result<AFWebUser, AppError> {
pub async fn select_web_user_from_uid(
pool: &PgPool,
uid: i64,
) -> Result<Option<AFWebUser>, AppError> {
let row = sqlx::query_as!(
AFWebUser,
r#"
@ -264,7 +267,7 @@ pub async fn select_web_user_from_uid(pool: &PgPool, uid: i64) -> Result<AFWebUs
"#,
uid
)
.fetch_one(pool)
.fetch_optional(pool)
.await
.map_err(|err| anyhow::anyhow!("Unable to get user detail for {}: {}", uid, err))?;

View File

@ -1290,11 +1290,11 @@ pub async fn get_page_view_collab(
)))?;
let owner = match view.created_by {
Some(uid) => Some(select_web_user_from_uid(pg_pool, uid).await?),
Some(uid) => select_web_user_from_uid(pg_pool, uid).await?,
None => None,
};
let last_editor = match view.last_edited_by {
Some(uid) => Some(select_web_user_from_uid(pg_pool, uid).await?),
Some(uid) => select_web_user_from_uid(pg_pool, uid).await?,
None => None,
};
let publish_view_ids = select_published_view_ids_for_workspace(pg_pool, workspace_id)