Skip to content

Commit

Permalink
fix: get page view should handle situation where last editor or docum…
Browse files Browse the repository at this point in the history
…ent owner cannot be found
  • Loading branch information
khorshuheng committed Jan 18, 2025
1 parent ab9932a commit c306b33
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions libs/database/src/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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#"
Expand All @@ -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))?;

Expand Down
4 changes: 2 additions & 2 deletions src/biz/workspace/page_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c306b33

Please sign in to comment.