Ensure get_profile_by_remote_actor_id returns profile with actor data

This commit is contained in:
silverpill 2023-01-11 20:04:47 +00:00
parent 22cf00fd98
commit 0ede2093c5
2 changed files with 12 additions and 5 deletions

View file

@ -130,7 +130,7 @@ pub async fn get_profile_by_remote_actor_id(
db_client: &impl GenericClient,
actor_id: &str,
) -> Result<DbActorProfile, DatabaseError> {
let result = db_client.query_opt(
let maybe_row = db_client.query_opt(
"
SELECT actor_profile
FROM actor_profile
@ -138,10 +138,9 @@ pub async fn get_profile_by_remote_actor_id(
",
&[&actor_id],
).await?;
let profile = match result {
Some(row) => row.try_get("actor_profile")?,
None => return Err(DatabaseError::NotFound("profile")),
};
let row = maybe_row.ok_or(DatabaseError::NotFound("profile"))?;
let profile: DbActorProfile = row.try_get("actor_profile")?;
profile.check_remote()?;
Ok(profile)
}

View file

@ -332,6 +332,14 @@ pub struct DbActorProfile {
// identity proofs: TBD (likely will do "Trust on first use" (TOFU))
impl DbActorProfile {
pub fn check_remote(&self) -> Result<(), DatabaseTypeError> {
// Consistency checks
if self.hostname.is_none() || self.actor_json.is_none() {
return Err(DatabaseTypeError);
};
Ok(())
}
pub fn is_local(&self) -> bool {
self.actor_json.is_none()
}