Move DbActorProfile::actor_id function to activitypub::identifiers
This commit is contained in:
parent
306fd7b75b
commit
f76438b6f8
13 changed files with 56 additions and 35 deletions
|
@ -12,6 +12,7 @@ use crate::activitypub::{
|
|||
local_actor_id,
|
||||
local_object_id,
|
||||
post_object_id,
|
||||
profile_actor_id,
|
||||
},
|
||||
types::{build_default_context, Context},
|
||||
vocabulary::ANNOUNCE,
|
||||
|
@ -50,7 +51,7 @@ fn build_announce(
|
|||
.expect("repost_of field should be populated");
|
||||
let object_id = post_object_id(instance_url, post);
|
||||
let activity_id = local_object_id(instance_url, &repost.id);
|
||||
let recipient_id = post.author.actor_id(instance_url);
|
||||
let recipient_id = profile_actor_id(instance_url, &post.author);
|
||||
let followers = local_actor_followers(instance_url, sender_username);
|
||||
Announce {
|
||||
context: build_default_context(),
|
||||
|
@ -77,7 +78,7 @@ pub async fn get_announce_recipients(
|
|||
recipients.push(remote_actor);
|
||||
};
|
||||
};
|
||||
let primary_recipient = post.author.actor_id(instance_url);
|
||||
let primary_recipient = profile_actor_id(instance_url, &post.author);
|
||||
if let Some(remote_actor) = post.author.actor_json.as_ref() {
|
||||
recipients.push(remote_actor.clone());
|
||||
};
|
||||
|
|
|
@ -15,6 +15,7 @@ use crate::activitypub::{
|
|||
local_object_id,
|
||||
local_tag_collection,
|
||||
post_object_id,
|
||||
profile_actor_id,
|
||||
},
|
||||
types::{
|
||||
build_default_context,
|
||||
|
@ -134,7 +135,7 @@ pub fn build_note(
|
|||
let mut tags = vec![];
|
||||
for profile in &post.mentions {
|
||||
let tag_name = format!("@{}", profile.actor_address(instance_hostname));
|
||||
let actor_id = profile.actor_id(instance_url);
|
||||
let actor_id = profile_actor_id(instance_url, profile);
|
||||
if !primary_audience.contains(&actor_id) {
|
||||
primary_audience.push(actor_id.clone());
|
||||
};
|
||||
|
@ -183,7 +184,10 @@ pub fn build_note(
|
|||
let in_reply_to = post.in_reply_to.as_ref()
|
||||
.expect("in_reply_to should be populated");
|
||||
assert_eq!(in_reply_to.id, in_reply_to_id);
|
||||
let in_reply_to_actor_id = in_reply_to.author.actor_id(instance_url);
|
||||
let in_reply_to_actor_id = profile_actor_id(
|
||||
instance_url,
|
||||
&in_reply_to.author,
|
||||
);
|
||||
if !primary_audience.contains(&in_reply_to_actor_id) {
|
||||
primary_audience.push(in_reply_to_actor_id);
|
||||
};
|
||||
|
|
|
@ -7,6 +7,7 @@ use crate::activitypub::{
|
|||
actors::types::Actor,
|
||||
constants::AP_PUBLIC,
|
||||
deliverer::OutgoingActivity,
|
||||
identifiers::local_actor_id,
|
||||
types::{build_default_context, Context},
|
||||
vocabulary::DELETE,
|
||||
};
|
||||
|
@ -35,7 +36,7 @@ fn build_delete_person(
|
|||
instance_url: &str,
|
||||
user: &User,
|
||||
) -> DeletePerson {
|
||||
let actor_id = user.profile.actor_id(instance_url);
|
||||
let actor_id = local_actor_id(instance_url, &user.profile.username);
|
||||
let activity_id = format!("{}/delete", actor_id);
|
||||
DeletePerson {
|
||||
context: build_default_context(),
|
||||
|
|
|
@ -7,7 +7,12 @@ use crate::activitypub::{
|
|||
actors::types::Actor,
|
||||
constants::AP_PUBLIC,
|
||||
deliverer::OutgoingActivity,
|
||||
identifiers::{local_actor_id, local_object_id, post_object_id},
|
||||
identifiers::{
|
||||
local_actor_id,
|
||||
local_object_id,
|
||||
post_object_id,
|
||||
profile_actor_id,
|
||||
},
|
||||
types::{build_default_context, Context},
|
||||
vocabulary::LIKE,
|
||||
};
|
||||
|
@ -94,7 +99,7 @@ pub async fn prepare_like(
|
|||
post,
|
||||
).await?;
|
||||
let object_id = post_object_id(&instance.url(), post);
|
||||
let post_author_id = post.author.actor_id(&instance.url());
|
||||
let post_author_id = profile_actor_id(&instance.url(), &post.author);
|
||||
let activity = build_like(
|
||||
&instance.url(),
|
||||
&sender.profile,
|
||||
|
|
|
@ -5,7 +5,7 @@ use mitra_config::Instance;
|
|||
|
||||
use crate::activitypub::{
|
||||
deliverer::OutgoingActivity,
|
||||
identifiers::{local_actor_id, local_object_id},
|
||||
identifiers::{local_actor_id, local_object_id, profile_actor_id},
|
||||
types::{build_default_context, Context},
|
||||
vocabulary::UNDO,
|
||||
};
|
||||
|
@ -71,7 +71,7 @@ pub async fn prepare_undo_like(
|
|||
&instance.url(),
|
||||
post,
|
||||
).await?;
|
||||
let post_author_id = post.author.actor_id(&instance.url());
|
||||
let post_author_id = profile_actor_id(&instance.url(), &post.author);
|
||||
let activity = build_undo_like(
|
||||
&instance.url(),
|
||||
&sender.profile,
|
||||
|
|
|
@ -19,7 +19,7 @@ use crate::activitypub::{
|
|||
get_or_import_profile_by_actor_id,
|
||||
import_post,
|
||||
},
|
||||
identifiers::parse_local_actor_id,
|
||||
identifiers::{parse_local_actor_id, profile_actor_id},
|
||||
receiver::{parse_array, parse_property_value, HandlerError},
|
||||
types::{Attachment, EmojiTag, Link, LinkTag, Object, Tag},
|
||||
vocabulary::*,
|
||||
|
@ -150,7 +150,7 @@ pub async fn get_object_attachments(
|
|||
},
|
||||
};
|
||||
if is_gnu_social_link(
|
||||
&author.actor_id(&instance.url()),
|
||||
&profile_actor_id(&instance.url(), author),
|
||||
&attachment,
|
||||
) {
|
||||
// Don't fetch HTML pages attached by GNU Social
|
||||
|
|
|
@ -9,7 +9,7 @@ use crate::activitypub::{
|
|||
undo_follow::prepare_undo_follow,
|
||||
},
|
||||
fetcher::helpers::get_or_import_profile_by_actor_id,
|
||||
identifiers::parse_local_actor_id,
|
||||
identifiers::{parse_local_actor_id, profile_actor_id},
|
||||
receiver::parse_array,
|
||||
vocabulary::PERSON,
|
||||
};
|
||||
|
@ -64,7 +64,7 @@ pub async fn handle_move(
|
|||
&activity.object,
|
||||
).await?
|
||||
};
|
||||
let old_actor_id = old_profile.actor_id(&instance.url());
|
||||
let old_actor_id = profile_actor_id(&instance.url(), &old_profile);
|
||||
let new_profile = get_or_import_profile_by_actor_id(
|
||||
db_client,
|
||||
&instance,
|
||||
|
@ -77,7 +77,7 @@ pub async fn handle_move(
|
|||
// Find aliases by DIDs (signed)
|
||||
let mut aliases = find_aliases(db_client, &new_profile).await?
|
||||
.into_iter()
|
||||
.map(|profile| profile.actor_id(&instance.url()))
|
||||
.map(|profile| profile_actor_id(&instance.url(), &profile))
|
||||
.collect::<Vec<_>>();
|
||||
// Read aliases from alsoKnownAs property
|
||||
// TODO: use new_profile.aliases.into_actor_ids()
|
||||
|
|
|
@ -125,13 +125,20 @@ pub fn post_object_id(instance_url: &str, post: &Post) -> String {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn profile_actor_id(instance_url: &str, profile: &DbActorProfile) -> String {
|
||||
match profile.actor_json {
|
||||
Some(ref actor) => actor.id.clone(),
|
||||
None => local_actor_id(instance_url, &profile.username),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn profile_actor_url(instance_url: &str, profile: &DbActorProfile) -> String {
|
||||
if let Some(ref actor) = profile.actor_json {
|
||||
if let Some(ref actor_url) = actor.url {
|
||||
return actor_url.to_string();
|
||||
};
|
||||
};
|
||||
profile.actor_id(instance_url)
|
||||
profile_actor_id(instance_url, profile)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -35,6 +35,7 @@ use super::handlers::{
|
|||
undo::handle_undo,
|
||||
update::handle_update,
|
||||
};
|
||||
use super::identifiers::profile_actor_id;
|
||||
use super::queues::IncomingActivityJobData;
|
||||
use super::vocabulary::*;
|
||||
|
||||
|
@ -298,7 +299,7 @@ pub async fn receive_activity(
|
|||
return Ok(());
|
||||
};
|
||||
|
||||
let signer_id = signer.actor_id(&config.instance_url());
|
||||
let signer_id = profile_actor_id(&config.instance_url(), &signer);
|
||||
let is_authenticated = activity_actor == signer_id;
|
||||
if !is_authenticated {
|
||||
match activity_type {
|
||||
|
|
|
@ -26,12 +26,15 @@ use mitra_utils::{
|
|||
passwords::hash_password,
|
||||
};
|
||||
|
||||
use crate::activitypub::builders::{
|
||||
undo_follow::prepare_undo_follow,
|
||||
update_person::{
|
||||
build_update_person,
|
||||
prepare_update_person,
|
||||
use crate::activitypub::{
|
||||
builders::{
|
||||
undo_follow::prepare_undo_follow,
|
||||
update_person::{
|
||||
build_update_person,
|
||||
prepare_update_person,
|
||||
},
|
||||
},
|
||||
identifiers::local_actor_id,
|
||||
};
|
||||
use crate::database::{get_database_client, DatabaseError, DbPool};
|
||||
use crate::errors::ValidationError;
|
||||
|
@ -369,7 +372,10 @@ async fn get_identity_claim(
|
|||
},
|
||||
_ => return Err(ValidationError("unknown proof type").into()),
|
||||
};
|
||||
let actor_id = current_user.profile.actor_id(&config.instance_url());
|
||||
let actor_id = local_actor_id(
|
||||
&config.instance_url(),
|
||||
¤t_user.profile.username,
|
||||
);
|
||||
let claim = create_identity_claim(&actor_id, &did)
|
||||
.map_err(|_| MastodonError::InternalError)?;
|
||||
let response = IdentityClaim { did, claim };
|
||||
|
@ -399,7 +405,10 @@ async fn create_identity_proof(
|
|||
Err(DatabaseError::NotFound(_)) => (),
|
||||
Err(other_error) => return Err(other_error.into()),
|
||||
};
|
||||
let actor_id = current_user.profile.actor_id(&config.instance_url());
|
||||
let actor_id = local_actor_id(
|
||||
&config.instance_url(),
|
||||
¤t_user.profile.username,
|
||||
);
|
||||
let message = create_identity_claim(&actor_id, &did)
|
||||
.map_err(|_| ValidationError("invalid claim"))?;
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ use actix_web_httpauth::extractors::bearer::BearerAuth;
|
|||
use mitra_config::Config;
|
||||
use mitra_utils::passwords::hash_password;
|
||||
|
||||
use crate::activitypub::identifiers::profile_actor_id;
|
||||
use crate::database::{get_database_client, DatabaseError, DbPool};
|
||||
use crate::errors::ValidationError;
|
||||
use crate::http::get_request_base_url;
|
||||
|
@ -147,7 +148,7 @@ async fn move_followers(
|
|||
// Find known aliases of the current user
|
||||
let mut aliases = find_aliases(db_client, ¤t_user.profile).await?
|
||||
.into_iter()
|
||||
.map(|profile| profile.actor_id(&instance.url()));
|
||||
.map(|profile| profile_actor_id(&instance.url(), &profile));
|
||||
if !aliases.any(|actor_id| actor_id == request_data.from_actor_id) {
|
||||
return Err(ValidationError("old profile is not an alias").into());
|
||||
};
|
||||
|
|
|
@ -15,7 +15,6 @@ use mitra_utils::{
|
|||
|
||||
use crate::activitypub::{
|
||||
actors::types::Actor,
|
||||
identifiers::local_actor_id,
|
||||
};
|
||||
use crate::database::{
|
||||
json_macro::{json_from_sql, json_to_sql},
|
||||
|
@ -399,13 +398,6 @@ impl DbActorProfile {
|
|||
self.actor_json.is_none()
|
||||
}
|
||||
|
||||
pub fn actor_id(&self, instance_url: &str) -> String {
|
||||
match self.actor_json {
|
||||
Some(ref actor) => actor.id.clone(),
|
||||
None => local_actor_id(instance_url, &self.username),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn actor_address(&self, local_hostname: &str) -> ActorAddress {
|
||||
assert_eq!(self.hostname.is_none(), self.is_local());
|
||||
ActorAddress {
|
||||
|
|
|
@ -14,7 +14,7 @@ use uuid::Uuid;
|
|||
use mitra_config::Config;
|
||||
|
||||
use crate::activitypub::{
|
||||
identifiers::post_object_id,
|
||||
identifiers::{post_object_id, profile_actor_id},
|
||||
views::is_activitypub_request,
|
||||
};
|
||||
use crate::database::{get_database_client, DbPool};
|
||||
|
@ -53,7 +53,7 @@ async fn profile_page_redirect_view(
|
|||
) -> Result<HttpResponse, HttpError> {
|
||||
let db_client = &**get_database_client(&db_pool).await?;
|
||||
let profile = get_profile_by_id(db_client, &profile_id).await?;
|
||||
let actor_id = profile.actor_id(&config.instance_url());
|
||||
let actor_id = profile_actor_id(&config.instance_url(), &profile);
|
||||
let response = HttpResponse::Found()
|
||||
.append_header(("Location", actor_id))
|
||||
.finish();
|
||||
|
@ -75,7 +75,7 @@ async fn profile_acct_page_redirect_view(
|
|||
) -> Result<HttpResponse, HttpError> {
|
||||
let db_client = &**get_database_client(&db_pool).await?;
|
||||
let profile = get_profile_by_acct(db_client, &acct).await?;
|
||||
let actor_id = profile.actor_id(&config.instance_url());
|
||||
let actor_id = profile_actor_id(&config.instance_url(), &profile);
|
||||
let response = HttpResponse::Found()
|
||||
.append_header(("Location", actor_id))
|
||||
.finish();
|
||||
|
|
Loading…
Reference in a new issue