let note = NoteExt::from_any_base(create.object().to_owned().one().context(location_info!())?)?
.context(location_info!())?;
- let comment = Comment::from_apub(¬e, context, user.actor_id(), request_counter).await?;
+ let comment = Comment::from_apub(¬e, context, Some(user.actor_id()), request_counter).await?;
let post_id = comment.post_id;
let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
.context(location_info!())?;
let user = get_actor_as_user(&update, context, request_counter).await?;
- let comment = Comment::from_apub(¬e, context, user.actor_id(), request_counter).await?;
+ let comment = Comment::from_apub(¬e, context, Some(user.actor_id()), request_counter).await?;
let comment_id = comment.id;
let post_id = comment.post_id;
let page = PageExt::from_any_base(create.object().to_owned().one().context(location_info!())?)?
.context(location_info!())?;
- let post = Post::from_apub(&page, context, user.actor_id(), request_counter).await?;
+ let post = Post::from_apub(&page, context, Some(user.actor_id()), request_counter).await?;
// Refetch the view
let post_id = post.id;
})
.await??;
+ let mut expected_domain = Some(user.actor_id());
// If sticked or locked state was changed, make sure the actor is a mod
let stickied = page.ext_one.stickied.context(location_info!())?;
let locked = !page.ext_one.comments_enabled.context(location_info!())?;
})
.await??;
verify_mod_activity(&update, announce, &community, context).await?;
+ expected_domain = None;
}
- let post = Post::from_apub(&page, context, user.actor_id(), request_counter).await?;
+ let post = Post::from_apub(&page, context, expected_domain, request_counter).await?;
let post_id = post.id;
// Refetch the view
.context(location_info!())?;
let private_message =
- PrivateMessage::from_apub(¬e, context, expected_domain, request_counter).await?;
+ PrivateMessage::from_apub(¬e, context, Some(expected_domain), request_counter).await?;
let message = blocking(&context.pool(), move |conn| {
PrivateMessageView::read(conn, private_message.id)
let note = NoteExt::from_any_base(object)?.context(location_info!())?;
let private_message =
- PrivateMessage::from_apub(¬e, context, expected_domain, request_counter).await?;
+ PrivateMessage::from_apub(¬e, context, Some(expected_domain), request_counter).await?;
let private_message_id = private_message.id;
let message = blocking(&context.pool(), move |conn| {
let group = group?;
let community =
- Community::from_apub(&group, context, apub_id.to_owned(), recursion_counter).await?;
+ Community::from_apub(&group, context, Some(apub_id.to_owned()), recursion_counter).await?;
// only fetch outbox for new communities, otherwise this can create an infinite loop
if old_community.is_none() {
debug!("Fetching and creating remote post: {}", post_ap_id);
let page =
fetch_remote_object::<PageExt>(context.client(), post_ap_id, recursion_counter).await?;
- let post = Post::from_apub(&page, context, post_ap_id.to_owned(), recursion_counter).await?;
+ let post = Post::from_apub(
+ &page,
+ context,
+ Some(post_ap_id.to_owned()),
+ recursion_counter,
+ )
+ .await?;
Ok(post)
}
let comment = Comment::from_apub(
&comment,
context,
- comment_ap_id.to_owned(),
+ Some(comment_ap_id.to_owned()),
recursion_counter,
)
.await?;
];
}
SearchAcceptedObjects::Page(p) => {
- let p = Post::from_apub(&p, context, query_url, recursion_counter).await?;
+ let p = Post::from_apub(&p, context, Some(query_url), recursion_counter).await?;
response.posts =
vec![blocking(context.pool(), move |conn| PostView::read(conn, p.id, None)).await??];
}
SearchAcceptedObjects::Comment(c) => {
- let c = Comment::from_apub(&c, context, query_url, recursion_counter).await?;
+ let c = Comment::from_apub(&c, context, Some(query_url), recursion_counter).await?;
response.comments = vec![
blocking(context.pool(), move |conn| {
return Ok(u);
}
- let user = User_::from_apub(&person?, context, apub_id.to_owned(), recursion_counter).await?;
+ let user = User_::from_apub(
+ &person?,
+ context,
+ Some(apub_id.to_owned()),
+ recursion_counter,
+ )
+ .await?;
let user_id = user.id;
blocking(context.pool(), move |conn| {
let person =
fetch_remote_object::<PersonExt>(context.client(), apub_id, recursion_counter).await?;
- let user = User_::from_apub(&person, context, apub_id.to_owned(), recursion_counter).await?;
+ let user = User_::from_apub(
+ &person,
+ context,
+ Some(apub_id.to_owned()),
+ recursion_counter,
+ )
+ .await?;
Ok(user)
}
request_counter: &mut i32,
) -> Result<(), LemmyError> {
let update = Update::from_any_base(activity)?.context(location_info!())?;
- verify_activity_domains_valid(&update, &expected_domain, true)?;
+ verify_activity_domains_valid(&update, &expected_domain, false)?;
verify_is_addressed_to_public(&update)?;
verify_modification_actor_instance(&update, &announce, context).await?;
CommunityModerator::get_user_moderated_communities(conn, new_mod_id)
})
.await??;
- if moderated_communities.contains(&community.id) {
+ if !moderated_communities.contains(&community.id) {
let form = CommunityModeratorForm {
community_id: community.id,
user_id: new_mod.id,
/// For activities like Update, Delete or Undo, check that the actor is from the same instance
/// as the original object itself (or is a remote mod).
+///
+/// Note: This is only needed for mod actions. Normal user actions (edit post, undo vote etc) are
+/// already verified with `expected_domain`, so this serves as an additional check.
async fn verify_modification_actor_instance<T, Kind>(
activity: &T,
announce: &Option<Announce>,
async fn from_apub(
note: &NoteExt,
context: &LemmyContext,
- expected_domain: Url,
+ expected_domain: Option<Url>,
request_counter: &mut i32,
) -> Result<Comment, LemmyError> {
let comment: Comment =
async fn from_apub(
note: &NoteExt,
context: &LemmyContext,
- expected_domain: Url,
+ expected_domain: Option<Url>,
request_counter: &mut i32,
) -> Result<CommentForm, LemmyError> {
+ let expected_domain = expected_domain.expect("expected_domain must be set for comment");
let creator_actor_id = ¬e
.attributed_to()
.context(location_info!())?
async fn from_apub(
group: &GroupExt,
context: &LemmyContext,
- expected_domain: Url,
+ expected_domain: Option<Url>,
request_counter: &mut i32,
) -> Result<Community, LemmyError> {
let community: Community =
async fn from_apub(
group: &GroupExt,
context: &LemmyContext,
- expected_domain: Url,
+ expected_domain: Option<Url>,
request_counter: &mut i32,
) -> Result<Self, LemmyError> {
+ let expected_domain = expected_domain.expect("expected_domain must be set for community");
let moderator_uris = fetch_community_mods(context, group, request_counter).await?;
let creator_uri = moderator_uris.first().context(location_info!())?;
///
/// * `apub` The object to read from
/// * `context` LemmyContext which holds DB pool, HTTP client etc
- /// * `expected_domain` Domain where the object was received from
+ /// * `expected_domain` Domain where the object was received from. None in case of mod action.
async fn from_apub(
apub: &Self::ApubType,
context: &LemmyContext,
- expected_domain: Url,
+ expected_domain: Option<Url>,
request_counter: &mut i32,
) -> Result<Self, LemmyError>
where
async fn from_apub(
apub: &ApubType,
context: &LemmyContext,
- expected_domain: Url,
+ expected_domain: Option<Url>,
request_counter: &mut i32,
) -> Result<Self, LemmyError>
where
pub(in crate::objects) async fn get_object_from_apub<From, Kind, To, ToForm>(
from: &From,
context: &LemmyContext,
- expected_domain: Url,
+ expected_domain: Option<Url>,
request_counter: &mut i32,
) -> Result<To, LemmyError>
where
use crate::{
+ check_is_apub_id_valid,
extensions::{context::lemmy_context, page_extension::PageExtension},
fetcher::user::get_or_fetch_and_upsert_user,
objects::{
async fn from_apub(
page: &PageExt,
context: &LemmyContext,
- expected_domain: Url,
+ expected_domain: Option<Url>,
request_counter: &mut i32,
) -> Result<Post, LemmyError> {
let post: Post = get_object_from_apub(page, context, expected_domain, request_counter).await?;
async fn from_apub(
page: &PageExt,
context: &LemmyContext,
- expected_domain: Url,
+ expected_domain: Option<Url>,
request_counter: &mut i32,
) -> Result<PostForm, LemmyError> {
+ let ap_id = match expected_domain {
+ Some(e) => check_object_domain(page, e)?,
+ None => {
+ let id = page.id_unchecked().context(location_info!())?;
+ check_is_apub_id_valid(id)?;
+ id.to_owned().into()
+ }
+ };
let ext = &page.ext_one;
let creator_actor_id = page
.inner
.to_string();
let body = get_source_markdown_value(page)?;
+ // TODO: expected_domain is wrong in this case, because it simply takes the domain of the actor
+ // maybe we need to take id_unchecked() if the activity is from community to user?
+ // why did this work before? -> i dont think it did?
+ // -> try to make expected_domain optional and set it null if it is a mod action
+
check_slurs(&name)?;
let body_slurs_removed = body.map(|b| remove_slurs(&b));
Ok(PostForm {
embed_description: iframely_description,
embed_html: iframely_html,
thumbnail_url: pictrs_thumbnail.map(|u| u.into()),
- ap_id: Some(check_object_domain(page, expected_domain)?),
+ ap_id: Some(ap_id),
local: false,
})
}
async fn from_apub(
note: &NoteExt,
context: &LemmyContext,
- expected_domain: Url,
+ expected_domain: Option<Url>,
request_counter: &mut i32,
) -> Result<PrivateMessage, LemmyError> {
get_object_from_apub(note, context, expected_domain, request_counter).await
async fn from_apub(
note: &NoteExt,
context: &LemmyContext,
- expected_domain: Url,
+ expected_domain: Option<Url>,
request_counter: &mut i32,
) -> Result<PrivateMessageForm, LemmyError> {
+ let expected_domain = expected_domain.expect("expected_domain must be set for private message");
let creator_actor_id = note
.attributed_to()
.context(location_info!())?
async fn from_apub(
person: &PersonExt,
context: &LemmyContext,
- expected_domain: Url,
+ expected_domain: Option<Url>,
request_counter: &mut i32,
) -> Result<User_, LemmyError> {
let user_id = person.id_unchecked().context(location_info!())?.to_owned();
async fn from_apub(
person: &PersonExt,
_context: &LemmyContext,
- expected_domain: Url,
+ expected_domain: Option<Url>,
_request_counter: &mut i32,
) -> Result<Self, LemmyError> {
+ let expected_domain = expected_domain.expect("expected_domain must be set for user");
let avatar = match person.icon() {
Some(any_image) => Some(
Image::from_any_base(any_image.as_one().context(location_info!())?.clone())?