|
|
|
@ -125,32 +125,31 @@ impl ApubObject for ApubPerson {
|
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn from_apub(
|
|
|
|
|
person: Person,
|
|
|
|
|
context: &LemmyContext,
|
|
|
|
|
async fn verify(
|
|
|
|
|
person: &Person,
|
|
|
|
|
expected_domain: &Url,
|
|
|
|
|
context: &LemmyContext,
|
|
|
|
|
_request_counter: &mut i32,
|
|
|
|
|
) -> Result<ApubPerson, LemmyError> {
|
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
|
verify_domains_match(person.id.inner(), expected_domain)?;
|
|
|
|
|
let name = person.preferred_username;
|
|
|
|
|
let display_name: Option<String> = person.name;
|
|
|
|
|
let bio = get_summary_from_string_or_source(&person.summary, &person.source);
|
|
|
|
|
let shared_inbox = person.endpoints.shared_inbox.map(|s| s.into());
|
|
|
|
|
let bot_account = match person.kind {
|
|
|
|
|
UserTypes::Person => false,
|
|
|
|
|
UserTypes::Service => true,
|
|
|
|
|
};
|
|
|
|
|
check_is_apub_id_valid(person.id.inner(), false, &context.settings())?;
|
|
|
|
|
|
|
|
|
|
let slur_regex = &context.settings().slur_regex();
|
|
|
|
|
check_slurs(&name, slur_regex)?;
|
|
|
|
|
check_slurs_opt(&display_name, slur_regex)?;
|
|
|
|
|
check_slurs(&person.preferred_username, slur_regex)?;
|
|
|
|
|
check_slurs_opt(&person.name, slur_regex)?;
|
|
|
|
|
let bio = get_summary_from_string_or_source(&person.summary, &person.source);
|
|
|
|
|
check_slurs_opt(&bio, slur_regex)?;
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
check_is_apub_id_valid(person.id.inner(), false, &context.settings())?;
|
|
|
|
|
|
|
|
|
|
async fn from_apub(
|
|
|
|
|
person: Person,
|
|
|
|
|
context: &LemmyContext,
|
|
|
|
|
_request_counter: &mut i32,
|
|
|
|
|
) -> Result<ApubPerson, LemmyError> {
|
|
|
|
|
let person_form = PersonForm {
|
|
|
|
|
name,
|
|
|
|
|
display_name: Some(display_name),
|
|
|
|
|
name: person.preferred_username,
|
|
|
|
|
display_name: Some(person.name),
|
|
|
|
|
banned: None,
|
|
|
|
|
deleted: None,
|
|
|
|
|
avatar: Some(person.icon.map(|i| i.url.into())),
|
|
|
|
@ -158,15 +157,18 @@ impl ApubObject for ApubPerson {
|
|
|
|
|
published: person.published.map(|u| u.naive_local()),
|
|
|
|
|
updated: person.updated.map(|u| u.naive_local()),
|
|
|
|
|
actor_id: Some(person.id.into()),
|
|
|
|
|
bio: Some(bio),
|
|
|
|
|
bio: Some(get_summary_from_string_or_source(
|
|
|
|
|
&person.summary,
|
|
|
|
|
&person.source,
|
|
|
|
|
)),
|
|
|
|
|
local: Some(false),
|
|
|
|
|
admin: Some(false),
|
|
|
|
|
bot_account: Some(bot_account),
|
|
|
|
|
bot_account: Some(person.kind == UserTypes::Service),
|
|
|
|
|
private_key: None,
|
|
|
|
|
public_key: Some(Some(person.public_key.public_key_pem)),
|
|
|
|
|
last_refreshed_at: Some(naive_now()),
|
|
|
|
|
inbox_url: Some(person.inbox.into()),
|
|
|
|
|
shared_inbox_url: Some(shared_inbox),
|
|
|
|
|
shared_inbox_url: Some(person.endpoints.shared_inbox.map(|s| s.into())),
|
|
|
|
|
matrix_user_id: Some(person.matrix_user_id),
|
|
|
|
|
};
|
|
|
|
|
let person = blocking(context.pool(), move |conn| {
|
|
|
|
@ -210,7 +212,10 @@ pub(crate) mod tests {
|
|
|
|
|
let json = file_to_json_object("assets/lemmy/objects/person.json");
|
|
|
|
|
let url = Url::parse("https://enterprise.lemmy.ml/u/picard").unwrap();
|
|
|
|
|
let mut request_counter = 0;
|
|
|
|
|
let person = ApubPerson::from_apub(json, context, &url, &mut request_counter)
|
|
|
|
|
ApubPerson::verify(&json, &url, context, &mut request_counter)
|
|
|
|
|
.await
|
|
|
|
|
.unwrap();
|
|
|
|
|
let person = ApubPerson::from_apub(json, context, &mut request_counter)
|
|
|
|
|
.await
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert_eq!(request_counter, 0);
|
|
|
|
@ -238,7 +243,10 @@ pub(crate) mod tests {
|
|
|
|
|
let json = file_to_json_object("assets/pleroma/objects/person.json");
|
|
|
|
|
let url = Url::parse("https://queer.hacktivis.me/users/lanodan").unwrap();
|
|
|
|
|
let mut request_counter = 0;
|
|
|
|
|
let person = ApubPerson::from_apub(json, &context, &url, &mut request_counter)
|
|
|
|
|
ApubPerson::verify(&json, &url, &context, &mut request_counter)
|
|
|
|
|
.await
|
|
|
|
|
.unwrap();
|
|
|
|
|
let person = ApubPerson::from_apub(json, &context, &mut request_counter)
|
|
|
|
|
.await
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|