mirror of https://github.com/LemmyNet/lemmy.git
Instrument apub functions
parent
8b170096f1
commit
b176b71d09
|
@ -28,6 +28,7 @@ use lemmy_utils::LemmyError;
|
|||
use lemmy_websocket::{send::send_comment_ws_message, LemmyContext, UserOperationCrud};
|
||||
|
||||
impl CreateOrUpdateComment {
|
||||
#[tracing::instrument(skip(comment, actor, kind, context))]
|
||||
pub async fn send(
|
||||
comment: ApubComment,
|
||||
actor: &ApubPerson,
|
||||
|
@ -83,6 +84,7 @@ impl CreateOrUpdateComment {
|
|||
impl ActivityHandler for CreateOrUpdateComment {
|
||||
type DataType = LemmyContext;
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn verify(
|
||||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -102,6 +104,7 @@ impl ActivityHandler for CreateOrUpdateComment {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn receive(
|
||||
self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -131,6 +134,7 @@ impl ActivityHandler for CreateOrUpdateComment {
|
|||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl GetCommunity for CreateOrUpdateComment {
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn get_community(
|
||||
&self,
|
||||
context: &LemmyContext,
|
||||
|
|
|
@ -11,6 +11,7 @@ use lemmy_websocket::{send::send_local_notifs, LemmyContext};
|
|||
|
||||
pub mod create_or_update;
|
||||
|
||||
#[tracing::instrument(skip(actor, comment, context))]
|
||||
async fn get_notif_recipients(
|
||||
actor: &ObjectId<ApubPerson>,
|
||||
comment: &Comment,
|
||||
|
|
|
@ -32,6 +32,7 @@ use lemmy_utils::LemmyError;
|
|||
use lemmy_websocket::LemmyContext;
|
||||
|
||||
impl AddMod {
|
||||
#[tracing::instrument(skip(community, added_mod, actor, context))]
|
||||
pub async fn send(
|
||||
community: &ApubCommunity,
|
||||
added_mod: &ApubPerson,
|
||||
|
@ -63,6 +64,7 @@ impl AddMod {
|
|||
impl ActivityHandler for AddMod {
|
||||
type DataType = LemmyContext;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn verify(
|
||||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -77,6 +79,7 @@ impl ActivityHandler for AddMod {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn receive(
|
||||
self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -109,6 +112,7 @@ impl ActivityHandler for AddMod {
|
|||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl GetCommunity for AddMod {
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn get_community(
|
||||
&self,
|
||||
context: &LemmyContext,
|
||||
|
|
|
@ -44,6 +44,7 @@ impl AnnounceActivity {
|
|||
})
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(object, community, context))]
|
||||
pub async fn send(
|
||||
object: AnnouncableActivities,
|
||||
community: &ApubCommunity,
|
||||
|
@ -85,6 +86,8 @@ impl AnnounceActivity {
|
|||
#[async_trait::async_trait(?Send)]
|
||||
impl ActivityHandler for AnnounceActivity {
|
||||
type DataType = LemmyContext;
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn verify(
|
||||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -96,6 +99,7 @@ impl ActivityHandler for AnnounceActivity {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn receive(
|
||||
self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
|
|
@ -52,6 +52,7 @@ impl BlockUserFromCommunity {
|
|||
})
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(community, target, actor, context))]
|
||||
pub async fn send(
|
||||
community: &ApubCommunity,
|
||||
target: &ApubPerson,
|
||||
|
@ -70,6 +71,8 @@ impl BlockUserFromCommunity {
|
|||
#[async_trait::async_trait(?Send)]
|
||||
impl ActivityHandler for BlockUserFromCommunity {
|
||||
type DataType = LemmyContext;
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn verify(
|
||||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -83,6 +86,7 @@ impl ActivityHandler for BlockUserFromCommunity {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn receive(
|
||||
self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -119,6 +123,7 @@ impl ActivityHandler for BlockUserFromCommunity {
|
|||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl GetCommunity for BlockUserFromCommunity {
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn get_community(
|
||||
&self,
|
||||
context: &LemmyContext,
|
||||
|
|
|
@ -17,6 +17,7 @@ pub mod report;
|
|||
pub mod undo_block_user;
|
||||
pub mod update;
|
||||
|
||||
#[tracing::instrument(skip(activity, actor, community, context))]
|
||||
pub(crate) async fn send_activity_in_community<T: ActorType>(
|
||||
activity: AnnouncableActivities,
|
||||
activity_id: &Url,
|
||||
|
@ -35,6 +36,7 @@ pub(crate) async fn send_activity_in_community<T: ActorType>(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(moderators, context))]
|
||||
async fn get_community_from_moderators_url(
|
||||
moderators: &Url,
|
||||
context: &LemmyContext,
|
||||
|
|
|
@ -32,6 +32,7 @@ use lemmy_utils::LemmyError;
|
|||
use lemmy_websocket::LemmyContext;
|
||||
|
||||
impl RemoveMod {
|
||||
#[tracing::instrument(skip(community, removed_mod, actor, context))]
|
||||
pub async fn send(
|
||||
community: &ApubCommunity,
|
||||
removed_mod: &ApubPerson,
|
||||
|
@ -62,6 +63,8 @@ impl RemoveMod {
|
|||
#[async_trait::async_trait(?Send)]
|
||||
impl ActivityHandler for RemoveMod {
|
||||
type DataType = LemmyContext;
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn verify(
|
||||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -76,6 +79,7 @@ impl ActivityHandler for RemoveMod {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn receive(
|
||||
self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -99,6 +103,7 @@ impl ActivityHandler for RemoveMod {
|
|||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl GetCommunity for RemoveMod {
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn get_community(
|
||||
&self,
|
||||
context: &LemmyContext,
|
||||
|
|
|
@ -28,6 +28,7 @@ use lemmy_utils::LemmyError;
|
|||
use lemmy_websocket::{messages::SendModRoomMessage, LemmyContext, UserOperation};
|
||||
|
||||
impl Report {
|
||||
#[tracing::instrument(skip(object_id, actor, community_id, reason, context))]
|
||||
pub async fn send(
|
||||
object_id: ObjectId<PostOrComment>,
|
||||
actor: &ApubPerson,
|
||||
|
@ -65,6 +66,8 @@ impl Report {
|
|||
#[async_trait::async_trait(?Send)]
|
||||
impl ActivityHandler for Report {
|
||||
type DataType = LemmyContext;
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn verify(
|
||||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -76,6 +79,7 @@ impl ActivityHandler for Report {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn receive(
|
||||
self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
|
|
@ -29,6 +29,7 @@ use lemmy_utils::LemmyError;
|
|||
use lemmy_websocket::LemmyContext;
|
||||
|
||||
impl UndoBlockUserFromCommunity {
|
||||
#[tracing::instrument(skip(community, target, actor, context))]
|
||||
pub async fn send(
|
||||
community: &ApubCommunity,
|
||||
target: &ApubPerson,
|
||||
|
@ -60,6 +61,8 @@ impl UndoBlockUserFromCommunity {
|
|||
#[async_trait::async_trait(?Send)]
|
||||
impl ActivityHandler for UndoBlockUserFromCommunity {
|
||||
type DataType = LemmyContext;
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn verify(
|
||||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -74,6 +77,7 @@ impl ActivityHandler for UndoBlockUserFromCommunity {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn receive(
|
||||
self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -102,6 +106,7 @@ impl ActivityHandler for UndoBlockUserFromCommunity {
|
|||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl GetCommunity for UndoBlockUserFromCommunity {
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn get_community(
|
||||
&self,
|
||||
context: &LemmyContext,
|
||||
|
|
|
@ -26,6 +26,7 @@ use lemmy_utils::LemmyError;
|
|||
use lemmy_websocket::{send::send_community_ws_message, LemmyContext, UserOperationCrud};
|
||||
|
||||
impl UpdateCommunity {
|
||||
#[tracing::instrument(skip(community, actor, context))]
|
||||
pub async fn send(
|
||||
community: ApubCommunity,
|
||||
actor: &ApubPerson,
|
||||
|
@ -53,6 +54,8 @@ impl UpdateCommunity {
|
|||
#[async_trait::async_trait(?Send)]
|
||||
impl ActivityHandler for UpdateCommunity {
|
||||
type DataType = LemmyContext;
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn verify(
|
||||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -73,6 +76,7 @@ impl ActivityHandler for UpdateCommunity {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn receive(
|
||||
self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -110,6 +114,7 @@ impl ActivityHandler for UpdateCommunity {
|
|||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl GetCommunity for UpdateCommunity {
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn get_community(
|
||||
&self,
|
||||
context: &LemmyContext,
|
||||
|
|
|
@ -11,7 +11,6 @@ use crate::{
|
|||
protocol::activities::deletion::delete::Delete,
|
||||
};
|
||||
use activitystreams_kinds::{activity::DeleteType, public};
|
||||
use anyhow::anyhow;
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub_lib::{
|
||||
data::Data,
|
||||
|
@ -45,6 +44,8 @@ use url::Url;
|
|||
#[async_trait::async_trait(?Send)]
|
||||
impl ActivityHandler for Delete {
|
||||
type DataType = LemmyContext;
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn verify(
|
||||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -65,6 +66,7 @@ impl ActivityHandler for Delete {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn receive(
|
||||
self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -112,6 +114,8 @@ impl Delete {
|
|||
unparsed: Default::default(),
|
||||
})
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(actor, community, object, summary, context))]
|
||||
pub(in crate::activities::deletion) async fn send(
|
||||
actor: &ApubPerson,
|
||||
community: &ApubCommunity,
|
||||
|
@ -127,6 +131,7 @@ impl Delete {
|
|||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(actor, object, reason, context))]
|
||||
pub(in crate::activities) async fn receive_remove_action(
|
||||
actor: &ObjectId<ApubPerson>,
|
||||
object: &Url,
|
||||
|
@ -139,7 +144,9 @@ pub(in crate::activities) async fn receive_remove_action(
|
|||
match DeletableObjects::read_from_db(object, context).await? {
|
||||
DeletableObjects::Community(community) => {
|
||||
if community.local {
|
||||
return Err(anyhow!("Only local admin can remove community").into());
|
||||
return Err(LemmyError::from_message(
|
||||
"Only local admin can remove community".into(),
|
||||
));
|
||||
}
|
||||
let form = ModRemoveCommunityForm {
|
||||
mod_person_id: actor.id,
|
||||
|
@ -201,6 +208,7 @@ pub(in crate::activities) async fn receive_remove_action(
|
|||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl GetCommunity for Delete {
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn get_community(
|
||||
&self,
|
||||
context: &LemmyContext,
|
||||
|
|
|
@ -20,6 +20,7 @@ use url::Url;
|
|||
pub mod delete;
|
||||
pub mod undo_delete;
|
||||
|
||||
#[tracing::instrument(skip(actor, community, object, deleted, context))]
|
||||
pub async fn send_apub_delete(
|
||||
actor: &ApubPerson,
|
||||
community: &ApubCommunity,
|
||||
|
@ -36,6 +37,7 @@ pub async fn send_apub_delete(
|
|||
|
||||
// TODO: remove reason is actually optional in lemmy. we set an empty string in that case, but its
|
||||
// ugly
|
||||
#[tracing::instrument(skip(actor, community, object, reason, removed, context))]
|
||||
pub async fn send_apub_remove(
|
||||
actor: &ApubPerson,
|
||||
community: &ApubCommunity,
|
||||
|
@ -58,6 +60,7 @@ pub enum DeletableObjects {
|
|||
}
|
||||
|
||||
impl DeletableObjects {
|
||||
#[tracing::instrument(skip(ap_id, context))]
|
||||
pub(crate) async fn read_from_db(
|
||||
ap_id: &Url,
|
||||
context: &LemmyContext,
|
||||
|
@ -83,6 +86,7 @@ impl DeletableObjects {
|
|||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(object, actor, community, is_mod_action, context))]
|
||||
pub(in crate::activities) async fn verify_delete_activity(
|
||||
object: &Url,
|
||||
actor: &ObjectId<ApubPerson>,
|
||||
|
@ -128,6 +132,7 @@ pub(in crate::activities) async fn verify_delete_activity(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(actor, object_id, community, is_mod_action, context))]
|
||||
async fn verify_delete_activity_post_or_comment(
|
||||
actor: &ObjectId<ApubPerson>,
|
||||
object_id: &Url,
|
||||
|
@ -149,6 +154,7 @@ async fn verify_delete_activity_post_or_comment(
|
|||
/// Write deletion or restoring of an object to the database, and send websocket message.
|
||||
/// TODO: we should do something similar for receive_remove_action(), but its much more complicated
|
||||
/// because of the mod log
|
||||
#[tracing::instrument(skip(object, actor, deleted, context))]
|
||||
async fn receive_delete_action(
|
||||
object: &Url,
|
||||
actor: &ObjectId<ApubPerson>,
|
||||
|
|
|
@ -11,7 +11,6 @@ use crate::{
|
|||
protocol::activities::deletion::{delete::Delete, undo_delete::UndoDelete},
|
||||
};
|
||||
use activitystreams_kinds::{activity::UndoType, public};
|
||||
use anyhow::anyhow;
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub_lib::{
|
||||
data::Data,
|
||||
|
@ -30,6 +29,8 @@ use url::Url;
|
|||
#[async_trait::async_trait(?Send)]
|
||||
impl ActivityHandler for UndoDelete {
|
||||
type DataType = LemmyContext;
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn verify(
|
||||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -51,6 +52,7 @@ impl ActivityHandler for UndoDelete {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn receive(
|
||||
self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -72,6 +74,7 @@ impl ActivityHandler for UndoDelete {
|
|||
}
|
||||
|
||||
impl UndoDelete {
|
||||
#[tracing::instrument(skip(actor, community, object, summary, context))]
|
||||
pub(in crate::activities::deletion) async fn send(
|
||||
actor: &ApubPerson,
|
||||
community: &ApubCommunity,
|
||||
|
@ -99,6 +102,7 @@ impl UndoDelete {
|
|||
send_activity_in_community(activity, &id, actor, community, vec![], context).await
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(object, context))]
|
||||
pub(in crate::activities) async fn receive_undo_remove_action(
|
||||
object: &Url,
|
||||
context: &LemmyContext,
|
||||
|
@ -107,7 +111,9 @@ impl UndoDelete {
|
|||
match DeletableObjects::read_from_db(object, context).await? {
|
||||
DeletableObjects::Community(community) => {
|
||||
if community.local {
|
||||
return Err(anyhow!("Only local admin can restore community").into());
|
||||
return Err(LemmyError::from_message(
|
||||
"Only local admin can restore community".into(),
|
||||
));
|
||||
}
|
||||
let deleted_community = blocking(context.pool(), move |conn| {
|
||||
Community::update_removed(conn, community.id, false)
|
||||
|
@ -136,6 +142,7 @@ impl UndoDelete {
|
|||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl GetCommunity for UndoDelete {
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn get_community(
|
||||
&self,
|
||||
context: &LemmyContext,
|
||||
|
|
|
@ -15,6 +15,7 @@ use lemmy_utils::LemmyError;
|
|||
use lemmy_websocket::LemmyContext;
|
||||
|
||||
impl AcceptFollowCommunity {
|
||||
#[tracing::instrument(skip(follow, context))]
|
||||
pub async fn send(
|
||||
follow: FollowCommunity,
|
||||
context: &LemmyContext,
|
||||
|
@ -45,6 +46,8 @@ impl AcceptFollowCommunity {
|
|||
#[async_trait::async_trait(?Send)]
|
||||
impl ActivityHandler for AcceptFollowCommunity {
|
||||
type DataType = LemmyContext;
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn verify(
|
||||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -56,6 +59,7 @@ impl ActivityHandler for AcceptFollowCommunity {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn receive(
|
||||
self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
|
|
@ -40,6 +40,8 @@ impl FollowCommunity {
|
|||
unparsed: Default::default(),
|
||||
})
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(actor, community, context))]
|
||||
pub async fn send(
|
||||
actor: &ApubPerson,
|
||||
community: &ApubCommunity,
|
||||
|
@ -64,6 +66,8 @@ impl FollowCommunity {
|
|||
#[async_trait::async_trait(?Send)]
|
||||
impl ActivityHandler for FollowCommunity {
|
||||
type DataType = LemmyContext;
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn verify(
|
||||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -76,6 +80,7 @@ impl ActivityHandler for FollowCommunity {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn receive(
|
||||
self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
|
|
@ -19,6 +19,7 @@ use lemmy_utils::LemmyError;
|
|||
use lemmy_websocket::LemmyContext;
|
||||
|
||||
impl UndoFollowCommunity {
|
||||
#[tracing::instrument(skip(actor, community, context))]
|
||||
pub async fn send(
|
||||
actor: &ApubPerson,
|
||||
community: &ApubCommunity,
|
||||
|
@ -43,6 +44,8 @@ impl UndoFollowCommunity {
|
|||
#[async_trait::async_trait(?Send)]
|
||||
impl ActivityHandler for UndoFollowCommunity {
|
||||
type DataType = LemmyContext;
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn verify(
|
||||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -55,6 +58,7 @@ impl ActivityHandler for UndoFollowCommunity {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn receive(
|
||||
self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
|
|
@ -6,7 +6,6 @@ use crate::{
|
|||
objects::{community::ApubCommunity, person::ApubPerson},
|
||||
};
|
||||
use activitystreams_kinds::public;
|
||||
use anyhow::anyhow;
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub_lib::{
|
||||
activity_queue::send_activity,
|
||||
|
@ -36,6 +35,7 @@ pub mod voting;
|
|||
|
||||
/// Checks that the specified Url actually identifies a Person (by fetching it), and that the person
|
||||
/// doesn't have a site ban.
|
||||
#[tracing::instrument(skip(person_id, context))]
|
||||
async fn verify_person(
|
||||
person_id: &ObjectId<ApubPerson>,
|
||||
context: &LemmyContext,
|
||||
|
@ -43,13 +43,17 @@ async fn verify_person(
|
|||
) -> Result<(), LemmyError> {
|
||||
let person = person_id.dereference(context, request_counter).await?;
|
||||
if person.banned {
|
||||
return Err(anyhow!("Person {} is banned", person_id).into());
|
||||
return Err(LemmyError::from_message(format!(
|
||||
"Person {} is banned",
|
||||
person_id
|
||||
)));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Fetches the person and community to verify their type, then checks if person is banned from site
|
||||
/// or community.
|
||||
#[tracing::instrument(skip(person_id, community, context))]
|
||||
pub(crate) async fn verify_person_in_community(
|
||||
person_id: &ObjectId<ApubPerson>,
|
||||
community: &ApubCommunity,
|
||||
|
@ -58,14 +62,18 @@ pub(crate) async fn verify_person_in_community(
|
|||
) -> Result<(), LemmyError> {
|
||||
let person = person_id.dereference(context, request_counter).await?;
|
||||
if person.banned {
|
||||
return Err(anyhow!("Person is banned from site").into());
|
||||
return Err(LemmyError::from_message(
|
||||
"Person is banned from site".to_string(),
|
||||
));
|
||||
}
|
||||
let person_id = person.id;
|
||||
let community_id = community.id;
|
||||
let is_banned =
|
||||
move |conn: &'_ _| CommunityPersonBanView::get(conn, person_id, community_id).is_ok();
|
||||
if blocking(context.pool(), is_banned).await? {
|
||||
return Err(anyhow!("Person is banned from community").into());
|
||||
return Err(LemmyError::from_message(
|
||||
"Person is banned from community".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -80,6 +88,7 @@ fn verify_activity(id: &Url, actor: &Url, settings: &Settings) -> Result<(), Lem
|
|||
/// Verify that the actor is a community mod. This check is only run if the community is local,
|
||||
/// because in case of remote communities, admins can also perform mod actions. As admin status
|
||||
/// is not federated, we cant verify their actions remotely.
|
||||
#[tracing::instrument(skip(actor_id, community, context))]
|
||||
pub(crate) async fn verify_mod_action(
|
||||
actor_id: &ObjectId<ApubPerson>,
|
||||
community: &ApubCommunity,
|
||||
|
@ -98,7 +107,7 @@ pub(crate) async fn verify_mod_action(
|
|||
})
|
||||
.await?;
|
||||
if !is_mod_or_admin {
|
||||
return Err(anyhow!("Not a mod").into());
|
||||
return Err(LemmyError::from_message("Not a mod".into()));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
@ -111,21 +120,23 @@ fn verify_add_remove_moderator_target(
|
|||
community: &ApubCommunity,
|
||||
) -> Result<(), LemmyError> {
|
||||
if target != &generate_moderators_url(&community.actor_id)?.into() {
|
||||
return Err(anyhow!("Unkown target url").into());
|
||||
return Err(LemmyError::from_message("Unkown target url".into()));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn verify_is_public(to: &[Url], cc: &[Url]) -> Result<(), LemmyError> {
|
||||
if ![to, cc].iter().any(|set| set.contains(&public())) {
|
||||
return Err(anyhow!("Object is not public").into());
|
||||
return Err(LemmyError::from_message("Object is not public".into()));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn check_community_deleted_or_removed(community: &Community) -> Result<(), LemmyError> {
|
||||
if community.deleted || community.removed {
|
||||
Err(anyhow!("New post or comment cannot be created in deleted or removed community").into())
|
||||
Err(LemmyError::from_message(
|
||||
"New post or comment cannot be created in deleted or removed community".into(),
|
||||
))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
@ -146,6 +157,7 @@ where
|
|||
Url::parse(&id)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(context, activity, activity_id, actor, inboxes, sensitive))]
|
||||
async fn send_lemmy_activity<T: Serialize>(
|
||||
context: &LemmyContext,
|
||||
activity: &T,
|
||||
|
|
|
@ -13,7 +13,6 @@ use crate::{
|
|||
protocol::activities::{create_or_update::post::CreateOrUpdatePost, CreateOrUpdateType},
|
||||
};
|
||||
use activitystreams_kinds::public;
|
||||
use anyhow::anyhow;
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub_lib::{
|
||||
data::Data,
|
||||
|
@ -47,6 +46,8 @@ impl CreateOrUpdatePost {
|
|||
unparsed: Default::default(),
|
||||
})
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(post, actor, kind, context))]
|
||||
pub async fn send(
|
||||
post: ApubPost,
|
||||
actor: &ApubPerson,
|
||||
|
@ -70,6 +71,8 @@ impl CreateOrUpdatePost {
|
|||
#[async_trait::async_trait(?Send)]
|
||||
impl ActivityHandler for CreateOrUpdatePost {
|
||||
type DataType = LemmyContext;
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn verify(
|
||||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -92,7 +95,9 @@ impl ActivityHandler for CreateOrUpdatePost {
|
|||
let is_stickied_or_locked =
|
||||
self.object.stickied == Some(true) || self.object.comments_enabled == Some(false);
|
||||
if community.local && is_stickied_or_locked {
|
||||
return Err(anyhow!("New post cannot be stickied or locked").into());
|
||||
return Err(LemmyError::from_message(
|
||||
"New post cannot be stickied or locked".into(),
|
||||
));
|
||||
}
|
||||
}
|
||||
CreateOrUpdateType::Update => {
|
||||
|
@ -109,6 +114,7 @@ impl ActivityHandler for CreateOrUpdatePost {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn receive(
|
||||
self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -127,6 +133,7 @@ impl ActivityHandler for CreateOrUpdatePost {
|
|||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl GetCommunity for CreateOrUpdatePost {
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn get_community(
|
||||
&self,
|
||||
context: &LemmyContext,
|
||||
|
|
|
@ -18,6 +18,7 @@ use lemmy_utils::LemmyError;
|
|||
use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
|
||||
|
||||
impl CreateOrUpdatePrivateMessage {
|
||||
#[tracing::instrument(skip(private_message, actor, kind, context))]
|
||||
pub async fn send(
|
||||
private_message: ApubPrivateMessage,
|
||||
actor: &ApubPerson,
|
||||
|
@ -46,9 +47,12 @@ impl CreateOrUpdatePrivateMessage {
|
|||
send_lemmy_activity(context, &create_or_update, &id, actor, inbox, true).await
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl ActivityHandler for CreateOrUpdatePrivateMessage {
|
||||
type DataType = LemmyContext;
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn verify(
|
||||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -61,6 +65,7 @@ impl ActivityHandler for CreateOrUpdatePrivateMessage {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn receive(
|
||||
self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
|
|
@ -36,6 +36,8 @@ impl DeletePrivateMessage {
|
|||
unparsed: Default::default(),
|
||||
})
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(actor, pm, context))]
|
||||
pub async fn send(
|
||||
actor: &ApubPerson,
|
||||
pm: &ApubPrivateMessage,
|
||||
|
@ -57,6 +59,8 @@ impl DeletePrivateMessage {
|
|||
#[async_trait::async_trait(?Send)]
|
||||
impl ActivityHandler for DeletePrivateMessage {
|
||||
type DataType = LemmyContext;
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn verify(
|
||||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -68,6 +72,7 @@ impl ActivityHandler for DeletePrivateMessage {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn receive(
|
||||
self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
|
|
@ -22,6 +22,7 @@ use lemmy_utils::LemmyError;
|
|||
use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
|
||||
|
||||
impl UndoDeletePrivateMessage {
|
||||
#[tracing::instrument(skip(actor, pm, context))]
|
||||
pub async fn send(
|
||||
actor: &ApubPerson,
|
||||
pm: &ApubPrivateMessage,
|
||||
|
@ -54,6 +55,8 @@ impl UndoDeletePrivateMessage {
|
|||
#[async_trait::async_trait(?Send)]
|
||||
impl ActivityHandler for UndoDeletePrivateMessage {
|
||||
type DataType = LemmyContext;
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn verify(
|
||||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -67,6 +70,7 @@ impl ActivityHandler for UndoDeletePrivateMessage {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn receive(
|
||||
self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
|
|
@ -21,6 +21,7 @@ use crate::{
|
|||
pub mod undo_vote;
|
||||
pub mod vote;
|
||||
|
||||
#[tracing::instrument(skip(vote_type, actor, comment, context))]
|
||||
async fn vote_comment(
|
||||
vote_type: &VoteType,
|
||||
actor: ApubPerson,
|
||||
|
@ -45,6 +46,7 @@ async fn vote_comment(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(vote_type, actor, post, context))]
|
||||
async fn vote_post(
|
||||
vote_type: &VoteType,
|
||||
actor: ApubPerson,
|
||||
|
@ -68,6 +70,7 @@ async fn vote_post(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(actor, comment, context))]
|
||||
async fn undo_vote_comment(
|
||||
actor: ApubPerson,
|
||||
comment: &ApubComment,
|
||||
|
@ -84,6 +87,7 @@ async fn undo_vote_comment(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(actor, post, context))]
|
||||
async fn undo_vote_post(
|
||||
actor: ApubPerson,
|
||||
post: &ApubPost,
|
||||
|
|
|
@ -28,6 +28,7 @@ use lemmy_utils::LemmyError;
|
|||
use lemmy_websocket::LemmyContext;
|
||||
|
||||
impl UndoVote {
|
||||
#[tracing::instrument(skip(object, actor, community_id, kind, context))]
|
||||
pub async fn send(
|
||||
object: &PostOrComment,
|
||||
actor: &ApubPerson,
|
||||
|
@ -63,6 +64,8 @@ impl UndoVote {
|
|||
#[async_trait::async_trait(?Send)]
|
||||
impl ActivityHandler for UndoVote {
|
||||
type DataType = LemmyContext;
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn verify(
|
||||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -77,6 +80,7 @@ impl ActivityHandler for UndoVote {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn receive(
|
||||
self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -97,6 +101,7 @@ impl ActivityHandler for UndoVote {
|
|||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl GetCommunity for UndoVote {
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn get_community(
|
||||
&self,
|
||||
context: &LemmyContext,
|
||||
|
|
|
@ -46,6 +46,7 @@ impl Vote {
|
|||
})
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(object, actor, community_id, kind, context))]
|
||||
pub async fn send(
|
||||
object: &PostOrComment,
|
||||
actor: &ApubPerson,
|
||||
|
@ -69,6 +70,8 @@ impl Vote {
|
|||
#[async_trait::async_trait(?Send)]
|
||||
impl ActivityHandler for Vote {
|
||||
type DataType = LemmyContext;
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn verify(
|
||||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -81,6 +84,7 @@ impl ActivityHandler for Vote {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn receive(
|
||||
self,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -97,6 +101,7 @@ impl ActivityHandler for Vote {
|
|||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl GetCommunity for Vote {
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn get_community(
|
||||
&self,
|
||||
context: &LemmyContext,
|
||||
|
|
|
@ -88,6 +88,7 @@ pub enum AnnouncableActivities {
|
|||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl GetCommunity for AnnouncableActivities {
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn get_community(
|
||||
&self,
|
||||
context: &LemmyContext,
|
||||
|
|
|
@ -29,6 +29,7 @@ impl ApubObject for ApubCommunityModerators {
|
|||
None
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(_object_id, data))]
|
||||
async fn read_from_apub_id(
|
||||
_object_id: Url,
|
||||
data: &Self::DataType,
|
||||
|
@ -46,10 +47,12 @@ impl ApubObject for ApubCommunityModerators {
|
|||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, _data))]
|
||||
async fn delete(self, _data: &Self::DataType) -> Result<(), LemmyError> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, data))]
|
||||
async fn into_apub(self, data: &Self::DataType) -> Result<Self::ApubType, LemmyError> {
|
||||
let ordered_items = self
|
||||
.0
|
||||
|
@ -67,6 +70,7 @@ impl ApubObject for ApubCommunityModerators {
|
|||
unimplemented!()
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(group_moderators, expected_domain, _context))]
|
||||
async fn verify(
|
||||
group_moderators: &GroupModerators,
|
||||
expected_domain: &Url,
|
||||
|
@ -77,6 +81,7 @@ impl ApubObject for ApubCommunityModerators {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(apub, data))]
|
||||
async fn from_apub(
|
||||
apub: Self::ApubType,
|
||||
data: &Self::DataType,
|
||||
|
|
|
@ -33,6 +33,7 @@ impl ApubObject for ApubCommunityOutbox {
|
|||
None
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(_object_id, data))]
|
||||
async fn read_from_apub_id(
|
||||
_object_id: Url,
|
||||
data: &Self::DataType,
|
||||
|
@ -58,6 +59,7 @@ impl ApubObject for ApubCommunityOutbox {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, data))]
|
||||
async fn into_apub(self, data: &Self::DataType) -> Result<Self::ApubType, LemmyError> {
|
||||
let mut ordered_items = vec![];
|
||||
for post in self.0 {
|
||||
|
@ -80,6 +82,7 @@ impl ApubObject for ApubCommunityOutbox {
|
|||
unimplemented!()
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(group_outbox, expected_domain, _context))]
|
||||
async fn verify(
|
||||
group_outbox: &GroupOutbox,
|
||||
expected_domain: &Url,
|
||||
|
@ -90,6 +93,7 @@ impl ApubObject for ApubCommunityOutbox {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(apub, data))]
|
||||
async fn from_apub(
|
||||
apub: Self::ApubType,
|
||||
data: &Self::DataType,
|
||||
|
|
|
@ -33,6 +33,7 @@ impl ApubObject for PostOrComment {
|
|||
}
|
||||
|
||||
// TODO: this can probably be implemented using a single sql query
|
||||
#[tracing::instrument(skip(object_id, data))]
|
||||
async fn read_from_apub_id(
|
||||
object_id: Url,
|
||||
data: &Self::DataType,
|
||||
|
@ -46,6 +47,7 @@ impl ApubObject for PostOrComment {
|
|||
})
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, data))]
|
||||
async fn delete(self, data: &Self::DataType) -> Result<(), LemmyError> {
|
||||
match self {
|
||||
PostOrComment::Post(p) => p.delete(data).await,
|
||||
|
@ -61,6 +63,7 @@ impl ApubObject for PostOrComment {
|
|||
unimplemented!()
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(apub, expected_domain, data))]
|
||||
async fn verify(
|
||||
apub: &Self::ApubType,
|
||||
expected_domain: &Url,
|
||||
|
@ -73,6 +76,7 @@ impl ApubObject for PostOrComment {
|
|||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(apub, context))]
|
||||
async fn from_apub(
|
||||
apub: PageOrNote,
|
||||
context: &LemmyContext,
|
||||
|
|
|
@ -4,7 +4,6 @@ use crate::{
|
|||
protocol::objects::{group::Group, note::Note, page::Page, person::Person},
|
||||
EndpointType,
|
||||
};
|
||||
use anyhow::anyhow;
|
||||
use chrono::NaiveDateTime;
|
||||
use lemmy_apub_lib::{object_id::ObjectId, traits::ApubObject};
|
||||
use lemmy_utils::LemmyError;
|
||||
|
@ -19,6 +18,7 @@ use url::Url;
|
|||
/// http://lemmy_beta:8551/u/lemmy_alpha, or @lemmy_beta@lemmy_beta:8551
|
||||
/// http://lemmy_gamma:8561/post/3
|
||||
/// http://lemmy_delta:8571/comment/2
|
||||
#[tracing::instrument(skip(query, context))]
|
||||
pub async fn search_by_apub_id(
|
||||
query: &str,
|
||||
context: &LemmyContext,
|
||||
|
@ -61,7 +61,7 @@ pub async fn search_by_apub_id(
|
|||
.await?,
|
||||
))
|
||||
}
|
||||
_ => Err(anyhow!("invalid query").into()),
|
||||
_ => Err(LemmyError::from_message("invalid query".into())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -105,6 +105,7 @@ impl ApubObject for SearchableObjects {
|
|||
// a single query.
|
||||
// we could skip this and always return an error, but then it would always fetch objects
|
||||
// over http, and not be able to mark objects as deleted that were deleted by remote server.
|
||||
#[tracing::instrument(skip(object_id, context))]
|
||||
async fn read_from_apub_id(
|
||||
object_id: Url,
|
||||
context: &LemmyContext,
|
||||
|
@ -128,6 +129,7 @@ impl ApubObject for SearchableObjects {
|
|||
Ok(None)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, data))]
|
||||
async fn delete(self, data: &Self::DataType) -> Result<(), LemmyError> {
|
||||
match self {
|
||||
SearchableObjects::Person(p) => p.delete(data).await,
|
||||
|
@ -145,6 +147,7 @@ impl ApubObject for SearchableObjects {
|
|||
unimplemented!()
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(apub, expected_domain, data))]
|
||||
async fn verify(
|
||||
apub: &Self::ApubType,
|
||||
expected_domain: &Url,
|
||||
|
@ -167,6 +170,7 @@ impl ApubObject for SearchableObjects {
|
|||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(apub, context))]
|
||||
async fn from_apub(
|
||||
apub: Self::ApubType,
|
||||
context: &LemmyContext,
|
||||
|
|
|
@ -35,6 +35,7 @@ impl ApubObject for UserOrCommunity {
|
|||
})
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(object_id, data))]
|
||||
async fn read_from_apub_id(
|
||||
object_id: Url,
|
||||
data: &Self::DataType,
|
||||
|
@ -48,6 +49,7 @@ impl ApubObject for UserOrCommunity {
|
|||
})
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, data))]
|
||||
async fn delete(self, data: &Self::DataType) -> Result<(), LemmyError> {
|
||||
match self {
|
||||
UserOrCommunity::User(p) => p.delete(data).await,
|
||||
|
@ -63,6 +65,7 @@ impl ApubObject for UserOrCommunity {
|
|||
unimplemented!()
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(apub, expected_domain, data))]
|
||||
async fn verify(
|
||||
apub: &Self::ApubType,
|
||||
expected_domain: &Url,
|
||||
|
@ -79,6 +82,7 @@ impl ApubObject for UserOrCommunity {
|
|||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(apub, data))]
|
||||
async fn from_apub(
|
||||
apub: Self::ApubType,
|
||||
data: &Self::DataType,
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::{generate_local_apub_endpoint, EndpointType};
|
||||
use anyhow::anyhow;
|
||||
use itertools::Itertools;
|
||||
use lemmy_apub_lib::{
|
||||
object_id::ObjectId,
|
||||
|
@ -34,6 +33,7 @@ pub struct WebfingerResponse {
|
|||
///
|
||||
/// TODO: later provide a method in ApubObject to generate the endpoint, so that we dont have to
|
||||
/// pass in EndpointType
|
||||
#[tracing::instrument(skip(identifier, endpoint_type, context))]
|
||||
pub async fn webfinger_resolve<Kind>(
|
||||
identifier: &str,
|
||||
endpoint_type: EndpointType,
|
||||
|
@ -61,6 +61,7 @@ where
|
|||
|
||||
/// Turns a person id like `@name@example.com` into an apub ID, like `https://example.com/user/name`,
|
||||
/// using webfinger.
|
||||
#[tracing::instrument(skip(identifier, context))]
|
||||
pub(crate) async fn webfinger_resolve_actor<Kind>(
|
||||
identifier: &str,
|
||||
context: &LemmyContext,
|
||||
|
@ -109,5 +110,8 @@ where
|
|||
return object.map(|o| o.actor_id().into());
|
||||
}
|
||||
}
|
||||
Err(anyhow!("Failed to resolve actor for {}", identifier).into())
|
||||
Err(LemmyError::from_message(format!(
|
||||
"Failed to resolve actor for {}",
|
||||
identifier
|
||||
)))
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ pub(crate) struct CommentQuery {
|
|||
}
|
||||
|
||||
/// Return the ActivityPub json representation of a local comment over HTTP.
|
||||
#[tracing::instrument(skip(info, context))]
|
||||
pub(crate) async fn get_apub_comment(
|
||||
info: Path<CommentQuery>,
|
||||
context: web::Data<LemmyContext>,
|
||||
|
|
|
@ -36,6 +36,7 @@ pub(crate) struct CommunityQuery {
|
|||
}
|
||||
|
||||
/// Return the ActivityPub json representation of a local community over HTTP.
|
||||
#[tracing::instrument(skip(info, context))]
|
||||
pub(crate) async fn get_apub_community_http(
|
||||
info: web::Path<CommunityQuery>,
|
||||
context: web::Data<LemmyContext>,
|
||||
|
@ -56,6 +57,7 @@ pub(crate) async fn get_apub_community_http(
|
|||
}
|
||||
|
||||
/// Handler for all incoming receive to community inboxes.
|
||||
#[tracing::instrument(skip(request, payload, _path, context))]
|
||||
pub async fn community_inbox(
|
||||
request: HttpRequest,
|
||||
payload: Payload,
|
||||
|
@ -121,6 +123,7 @@ pub(crate) async fn get_apub_community_outbox(
|
|||
Ok(create_apub_response(&outbox.into_apub(&outbox_data).await?))
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(info, context))]
|
||||
pub(crate) async fn get_apub_community_moderators(
|
||||
info: web::Path<CommunityQuery>,
|
||||
context: web::Data<LemmyContext>,
|
||||
|
|
|
@ -13,7 +13,7 @@ use actix_web::{
|
|||
HttpRequest,
|
||||
HttpResponse,
|
||||
};
|
||||
use anyhow::{anyhow, Context};
|
||||
use anyhow::Context;
|
||||
use futures::StreamExt;
|
||||
use http::StatusCode;
|
||||
use lemmy_api_common::blocking;
|
||||
|
@ -38,6 +38,7 @@ mod person;
|
|||
mod post;
|
||||
pub mod routes;
|
||||
|
||||
#[tracing::instrument(skip(request, payload, context))]
|
||||
pub async fn shared_inbox(
|
||||
request: HttpRequest,
|
||||
payload: Payload,
|
||||
|
@ -75,6 +76,7 @@ pub(crate) struct ActivityCommonFields {
|
|||
}
|
||||
|
||||
// TODO: move most of this code to library
|
||||
#[tracing::instrument(skip(request, activity, activity_data, context))]
|
||||
async fn receive_activity<'a, T>(
|
||||
request: HttpRequest,
|
||||
activity: T,
|
||||
|
@ -149,6 +151,7 @@ pub struct ActivityQuery {
|
|||
}
|
||||
|
||||
/// Return the ActivityPub json representation of a local activity over HTTP.
|
||||
#[tracing::instrument(skip(info, context))]
|
||||
pub(crate) async fn get_activity(
|
||||
info: web::Path<ActivityQuery>,
|
||||
context: web::Data<LemmyContext>,
|
||||
|
@ -178,13 +181,10 @@ fn assert_activity_not_local(id: &Url, hostname: &str) -> Result<(), LemmyError>
|
|||
let activity_domain = id.domain().context(location_info!())?;
|
||||
|
||||
if activity_domain == hostname {
|
||||
return Err(
|
||||
anyhow!(
|
||||
"Error: received activity which was sent by local instance: {:?}",
|
||||
id
|
||||
)
|
||||
.into(),
|
||||
);
|
||||
return Err(LemmyError::from_message(format!(
|
||||
"Error: received activity which was sent by local instance: {:?}",
|
||||
id
|
||||
)));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ pub struct PersonQuery {
|
|||
}
|
||||
|
||||
/// Return the ActivityPub json representation of a local person over HTTP.
|
||||
#[tracing::instrument(skip(info, context))]
|
||||
pub(crate) async fn get_apub_person_http(
|
||||
info: web::Path<PersonQuery>,
|
||||
context: web::Data<LemmyContext>,
|
||||
|
@ -47,6 +48,7 @@ pub(crate) async fn get_apub_person_http(
|
|||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(request, payload, _path, context))]
|
||||
pub async fn person_inbox(
|
||||
request: HttpRequest,
|
||||
payload: Payload,
|
||||
|
@ -69,6 +71,7 @@ pub(in crate::http) async fn receive_person_inbox(
|
|||
receive_activity(request, activity, activity_data, context).await
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(info, context))]
|
||||
pub(crate) async fn get_apub_person_outbox(
|
||||
info: web::Path<PersonQuery>,
|
||||
context: web::Data<LemmyContext>,
|
||||
|
|
|
@ -17,6 +17,7 @@ pub(crate) struct PostQuery {
|
|||
}
|
||||
|
||||
/// Return the ActivityPub json representation of a local post over HTTP.
|
||||
#[tracing::instrument(skip(info, context))]
|
||||
pub(crate) async fn get_apub_post(
|
||||
info: web::Path<PostQuery>,
|
||||
context: web::Data<LemmyContext>,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::fetcher::post_or_comment::PostOrComment;
|
||||
use anyhow::{anyhow, Context};
|
||||
use anyhow::Context;
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_db_schema::{newtypes::DbUrl, source::activity::Activity, DbPool};
|
||||
use lemmy_utils::{location_info, settings::structs::Settings, LemmyError};
|
||||
|
@ -27,6 +27,7 @@ pub mod protocol;
|
|||
///
|
||||
/// `use_strict_allowlist` should be true only when parsing a remote community, or when parsing a
|
||||
/// post/comment in a local community.
|
||||
#[tracing::instrument(skip(settings))]
|
||||
pub(crate) fn check_is_apub_id_valid(
|
||||
apub_id: &Url,
|
||||
use_strict_allowlist: bool,
|
||||
|
@ -39,24 +40,28 @@ pub(crate) fn check_is_apub_id_valid(
|
|||
return if domain == local_instance {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(
|
||||
anyhow!(
|
||||
"Trying to connect with {}, but federation is disabled",
|
||||
domain
|
||||
)
|
||||
.into(),
|
||||
)
|
||||
Err(LemmyError::from_message(format!(
|
||||
"Trying to connect with {}, but federation is disabled",
|
||||
domain
|
||||
)))
|
||||
};
|
||||
}
|
||||
|
||||
let host = apub_id.host_str().context(location_info!())?;
|
||||
let host_as_ip = host.parse::<IpAddr>();
|
||||
if host == "localhost" || host_as_ip.is_ok() {
|
||||
return Err(anyhow!("invalid hostname {}: {}", host, apub_id).into());
|
||||
return Err(LemmyError::from_message(format!(
|
||||
"invalid hostname {}: {}",
|
||||
host, apub_id
|
||||
)));
|
||||
}
|
||||
|
||||
if apub_id.scheme() != settings.get_protocol_string() {
|
||||
return Err(anyhow!("invalid apub id scheme {}: {}", apub_id.scheme(), apub_id).into());
|
||||
return Err(LemmyError::from_message(format!(
|
||||
"invalid apub id scheme {}: {}",
|
||||
apub_id.scheme(),
|
||||
apub_id
|
||||
)));
|
||||
}
|
||||
|
||||
// TODO: might be good to put the part above in one method, and below in another
|
||||
|
@ -64,7 +69,10 @@ pub(crate) fn check_is_apub_id_valid(
|
|||
// -> no that doesnt make sense, we still need the code below for blocklist and strict allowlist
|
||||
if let Some(blocked) = settings.to_owned().federation.blocked_instances {
|
||||
if blocked.contains(&domain) {
|
||||
return Err(anyhow!("{} is in federation blocklist", domain).into());
|
||||
return Err(LemmyError::from_message(format!(
|
||||
"{} is in federation blocklist",
|
||||
domain
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,7 +85,10 @@ pub(crate) fn check_is_apub_id_valid(
|
|||
allowed.push(local_instance);
|
||||
|
||||
if !allowed.contains(&domain) {
|
||||
return Err(anyhow!("{} not in federation allowlist", domain).into());
|
||||
return Err(LemmyError::from_message(format!(
|
||||
"{} not in federation allowlist",
|
||||
domain
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -143,6 +154,7 @@ fn generate_moderators_url(community_id: &DbUrl) -> Result<DbUrl, LemmyError> {
|
|||
|
||||
/// Store a sent or received activity in the database, for logging purposes. These records are not
|
||||
/// persistent.
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn insert_activity(
|
||||
ap_id: &Url,
|
||||
activity: serde_json::Value,
|
||||
|
|
|
@ -34,6 +34,7 @@ pub struct MentionsAndAddresses {
|
|||
/// This takes a comment, and builds a list of to_addresses, inboxes,
|
||||
/// and mention tags, so they know where to be sent to.
|
||||
/// Addresses are the persons / addresses that go in the cc field.
|
||||
#[tracing::instrument(skip(comment, community_id, context))]
|
||||
pub async fn collect_non_local_mentions(
|
||||
comment: &ApubComment,
|
||||
community_id: ObjectId<ApubCommunity>,
|
||||
|
@ -88,6 +89,7 @@ pub async fn collect_non_local_mentions(
|
|||
|
||||
/// Returns the apub ID of the person this comment is responding to. Meaning, in case this is a
|
||||
/// top-level comment, the creator of the post, otherwise the creator of the parent comment.
|
||||
#[tracing::instrument(skip(pool, comment))]
|
||||
async fn get_comment_parent_creator(
|
||||
pool: &DbPool,
|
||||
comment: &Comment,
|
||||
|
|
|
@ -12,7 +12,6 @@ use crate::{
|
|||
PostOrComment,
|
||||
};
|
||||
use activitystreams_kinds::{object::NoteType, public};
|
||||
use anyhow::anyhow;
|
||||
use chrono::NaiveDateTime;
|
||||
use html2md::parse_html;
|
||||
use lemmy_api_common::blocking;
|
||||
|
@ -65,6 +64,7 @@ impl ApubObject for ApubComment {
|
|||
None
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(object_id, context))]
|
||||
async fn read_from_apub_id(
|
||||
object_id: Url,
|
||||
context: &LemmyContext,
|
||||
|
@ -78,6 +78,7 @@ impl ApubObject for ApubComment {
|
|||
)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn delete(self, context: &LemmyContext) -> Result<(), LemmyError> {
|
||||
if !self.deleted {
|
||||
blocking(context.pool(), move |conn| {
|
||||
|
@ -88,6 +89,7 @@ impl ApubObject for ApubComment {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn into_apub(self, context: &LemmyContext) -> Result<Note, LemmyError> {
|
||||
let creator_id = self.creator_id;
|
||||
let creator = blocking(context.pool(), move |conn| Person::read(conn, creator_id)).await??;
|
||||
|
@ -136,6 +138,7 @@ impl ApubObject for ApubComment {
|
|||
Ok(Tombstone::new(self.ap_id.clone().into()))
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(note, expected_domain, context))]
|
||||
async fn verify(
|
||||
note: &Note,
|
||||
expected_domain: &Url,
|
||||
|
@ -160,7 +163,7 @@ impl ApubObject for ApubComment {
|
|||
)
|
||||
.await?;
|
||||
if post.locked {
|
||||
return Err(anyhow!("Post is locked").into());
|
||||
return Err(LemmyError::from_message("Post is locked".into()));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -168,6 +171,7 @@ impl ApubObject for ApubComment {
|
|||
/// Converts a `Note` to `Comment`.
|
||||
///
|
||||
/// If the parent community, post and comment(s) are not known locally, these are also fetched.
|
||||
#[tracing::instrument(skip(note, context))]
|
||||
async fn from_apub(
|
||||
note: Note,
|
||||
context: &LemmyContext,
|
||||
|
|
|
@ -55,6 +55,7 @@ impl ApubObject for ApubCommunity {
|
|||
Some(self.last_refreshed_at)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(object_id, context))]
|
||||
async fn read_from_apub_id(
|
||||
object_id: Url,
|
||||
context: &LemmyContext,
|
||||
|
@ -68,6 +69,7 @@ impl ApubObject for ApubCommunity {
|
|||
)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn delete(self, context: &LemmyContext) -> Result<(), LemmyError> {
|
||||
blocking(context.pool(), move |conn| {
|
||||
Community::update_deleted(conn, self.id, true)
|
||||
|
@ -76,6 +78,7 @@ impl ApubObject for ApubCommunity {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, _context))]
|
||||
async fn into_apub(self, _context: &LemmyContext) -> Result<Group, LemmyError> {
|
||||
let source = self.description.clone().map(|bio| Source {
|
||||
content: bio,
|
||||
|
@ -115,6 +118,7 @@ impl ApubObject for ApubCommunity {
|
|||
Ok(Tombstone::new(self.actor_id()))
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(group, expected_domain, context))]
|
||||
async fn verify(
|
||||
group: &Group,
|
||||
expected_domain: &Url,
|
||||
|
@ -125,6 +129,7 @@ impl ApubObject for ApubCommunity {
|
|||
}
|
||||
|
||||
/// Converts a `Group` to `Community`, inserts it into the database and updates moderators.
|
||||
#[tracing::instrument(skip(group, context))]
|
||||
async fn from_apub(
|
||||
group: Group,
|
||||
context: &LemmyContext,
|
||||
|
@ -181,6 +186,7 @@ impl ActorType for ApubCommunity {
|
|||
|
||||
impl ApubCommunity {
|
||||
/// For a given community, returns the inboxes of all followers.
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
pub(crate) async fn get_follower_inboxes(
|
||||
&self,
|
||||
context: &LemmyContext,
|
||||
|
|
|
@ -57,6 +57,7 @@ impl ApubObject for ApubPerson {
|
|||
Some(self.last_refreshed_at)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(object_id, context))]
|
||||
async fn read_from_apub_id(
|
||||
object_id: Url,
|
||||
context: &LemmyContext,
|
||||
|
@ -70,6 +71,7 @@ impl ApubObject for ApubPerson {
|
|||
)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn delete(self, context: &LemmyContext) -> Result<(), LemmyError> {
|
||||
blocking(context.pool(), move |conn| {
|
||||
DbPerson::update_deleted(conn, self.id, true)
|
||||
|
@ -78,6 +80,7 @@ impl ApubObject for ApubPerson {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, _pool))]
|
||||
async fn into_apub(self, _pool: &LemmyContext) -> Result<Person, LemmyError> {
|
||||
let kind = if self.bot_account {
|
||||
UserTypes::Service
|
||||
|
@ -118,6 +121,7 @@ impl ApubObject for ApubPerson {
|
|||
unimplemented!()
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(person, expected_domain, context))]
|
||||
async fn verify(
|
||||
person: &Person,
|
||||
expected_domain: &Url,
|
||||
|
@ -135,6 +139,7 @@ impl ApubObject for ApubPerson {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(person, context))]
|
||||
async fn from_apub(
|
||||
person: Person,
|
||||
context: &LemmyContext,
|
||||
|
|
|
@ -60,6 +60,7 @@ impl ApubObject for ApubPost {
|
|||
None
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(object_id, context))]
|
||||
async fn read_from_apub_id(
|
||||
object_id: Url,
|
||||
context: &LemmyContext,
|
||||
|
@ -73,6 +74,7 @@ impl ApubObject for ApubPost {
|
|||
)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn delete(self, context: &LemmyContext) -> Result<(), LemmyError> {
|
||||
if !self.deleted {
|
||||
blocking(context.pool(), move |conn| {
|
||||
|
@ -84,6 +86,7 @@ impl ApubObject for ApubPost {
|
|||
}
|
||||
|
||||
// Turn a Lemmy post into an ActivityPub page that can be sent out over the network.
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn into_apub(self, context: &LemmyContext) -> Result<Page, LemmyError> {
|
||||
let creator_id = self.creator_id;
|
||||
let creator = blocking(context.pool(), move |conn| Person::read(conn, creator_id)).await??;
|
||||
|
@ -125,6 +128,7 @@ impl ApubObject for ApubPost {
|
|||
Ok(Tombstone::new(self.ap_id.clone().into()))
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(page, expected_domain, context))]
|
||||
async fn verify(
|
||||
page: &Page,
|
||||
expected_domain: &Url,
|
||||
|
@ -146,6 +150,7 @@ impl ApubObject for ApubPost {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(page, context))]
|
||||
async fn from_apub(
|
||||
page: Page,
|
||||
context: &LemmyContext,
|
||||
|
|
|
@ -2,7 +2,6 @@ use crate::protocol::{
|
|||
objects::chat_message::{ChatMessage, ChatMessageType},
|
||||
Source,
|
||||
};
|
||||
use anyhow::anyhow;
|
||||
use chrono::NaiveDateTime;
|
||||
use html2md::parse_html;
|
||||
use lemmy_api_common::blocking;
|
||||
|
@ -53,6 +52,7 @@ impl ApubObject for ApubPrivateMessage {
|
|||
None
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(object_id, context))]
|
||||
async fn read_from_apub_id(
|
||||
object_id: Url,
|
||||
context: &LemmyContext,
|
||||
|
@ -71,6 +71,7 @@ impl ApubObject for ApubPrivateMessage {
|
|||
unimplemented!()
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn into_apub(self, context: &LemmyContext) -> Result<ChatMessage, LemmyError> {
|
||||
let creator_id = self.creator_id;
|
||||
let creator = blocking(context.pool(), move |conn| Person::read(conn, creator_id)).await??;
|
||||
|
@ -101,6 +102,7 @@ impl ApubObject for ApubPrivateMessage {
|
|||
unimplemented!()
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(note, expected_domain, context))]
|
||||
async fn verify(
|
||||
note: &ChatMessage,
|
||||
expected_domain: &Url,
|
||||
|
@ -114,11 +116,14 @@ impl ApubObject for ApubPrivateMessage {
|
|||
.dereference(context, request_counter)
|
||||
.await?;
|
||||
if person.banned {
|
||||
return Err(anyhow!("Person is banned from site").into());
|
||||
return Err(LemmyError::from_message(
|
||||
"Person is banned from site".into(),
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(note, context))]
|
||||
async fn from_apub(
|
||||
note: ChatMessage,
|
||||
context: &LemmyContext,
|
||||
|
|
|
@ -3,7 +3,6 @@ use crate::{
|
|||
objects::person::ApubPerson,
|
||||
protocol::Unparsed,
|
||||
};
|
||||
use anyhow::anyhow;
|
||||
use lemmy_apub_lib::object_id::ObjectId;
|
||||
use lemmy_utils::LemmyError;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -38,7 +37,7 @@ impl TryFrom<i16> for VoteType {
|
|||
match value {
|
||||
1 => Ok(VoteType::Like),
|
||||
-1 => Ok(VoteType::Dislike),
|
||||
_ => Err(anyhow!("invalid vote value").into()),
|
||||
_ => Err(LemmyError::from_message("invalid vote value".into())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ use crate::{
|
|||
protocol::{ImageObject, Source, Unparsed},
|
||||
};
|
||||
use activitystreams_kinds::object::PageType;
|
||||
use anyhow::anyhow;
|
||||
use chrono::{DateTime, FixedOffset};
|
||||
use lemmy_apub_lib::{
|
||||
data::Data,
|
||||
|
@ -73,7 +72,7 @@ impl Page {
|
|||
break Ok(c);
|
||||
}
|
||||
} else {
|
||||
return Err(anyhow!("No community found in cc").into());
|
||||
return Err(LemmyError::from_message("No community found in cc".into()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue