Ensure get_profile_by_remote_actor_id returns profile with actor data
This commit is contained in:
parent
22cf00fd98
commit
0ede2093c5
2 changed files with 12 additions and 5 deletions
|
@ -130,7 +130,7 @@ pub async fn get_profile_by_remote_actor_id(
|
||||||
db_client: &impl GenericClient,
|
db_client: &impl GenericClient,
|
||||||
actor_id: &str,
|
actor_id: &str,
|
||||||
) -> Result<DbActorProfile, DatabaseError> {
|
) -> Result<DbActorProfile, DatabaseError> {
|
||||||
let result = db_client.query_opt(
|
let maybe_row = db_client.query_opt(
|
||||||
"
|
"
|
||||||
SELECT actor_profile
|
SELECT actor_profile
|
||||||
FROM actor_profile
|
FROM actor_profile
|
||||||
|
@ -138,10 +138,9 @@ pub async fn get_profile_by_remote_actor_id(
|
||||||
",
|
",
|
||||||
&[&actor_id],
|
&[&actor_id],
|
||||||
).await?;
|
).await?;
|
||||||
let profile = match result {
|
let row = maybe_row.ok_or(DatabaseError::NotFound("profile"))?;
|
||||||
Some(row) => row.try_get("actor_profile")?,
|
let profile: DbActorProfile = row.try_get("actor_profile")?;
|
||||||
None => return Err(DatabaseError::NotFound("profile")),
|
profile.check_remote()?;
|
||||||
};
|
|
||||||
Ok(profile)
|
Ok(profile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -332,6 +332,14 @@ pub struct DbActorProfile {
|
||||||
// identity proofs: TBD (likely will do "Trust on first use" (TOFU))
|
// identity proofs: TBD (likely will do "Trust on first use" (TOFU))
|
||||||
|
|
||||||
impl DbActorProfile {
|
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 {
|
pub fn is_local(&self) -> bool {
|
||||||
self.actor_json.is_none()
|
self.actor_json.is_none()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue