|
|
@ -1,19 +1,9 @@
|
|
|
|
use crate::{
|
|
|
|
|
|
|
|
activities::receive::verify_activity_domains_valid,
|
|
|
|
|
|
|
|
inbox::verify_is_addressed_to_public,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
use activitystreams::{
|
|
|
|
|
|
|
|
activity::{ActorAndObjectRefExt, Delete, Remove, Undo},
|
|
|
|
|
|
|
|
base::{AnyBase, ExtendsExt},
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
use anyhow::Context;
|
|
|
|
|
|
|
|
use lemmy_api_structs::{blocking, community::CommunityResponse};
|
|
|
|
use lemmy_api_structs::{blocking, community::CommunityResponse};
|
|
|
|
use lemmy_db_queries::{source::community::Community_, ApubObject};
|
|
|
|
use lemmy_db_queries::source::community::Community_;
|
|
|
|
use lemmy_db_schema::source::community::Community;
|
|
|
|
use lemmy_db_schema::source::community::Community;
|
|
|
|
use lemmy_db_views_actor::community_view::CommunityView;
|
|
|
|
use lemmy_db_views_actor::community_view::CommunityView;
|
|
|
|
use lemmy_utils::{location_info, LemmyError};
|
|
|
|
use lemmy_utils::LemmyError;
|
|
|
|
use lemmy_websocket::{messages::SendCommunityRoomMessage, LemmyContext, UserOperation};
|
|
|
|
use lemmy_websocket::{messages::SendCommunityRoomMessage, LemmyContext, UserOperation};
|
|
|
|
use url::Url;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub(crate) async fn receive_delete_community(
|
|
|
|
pub(crate) async fn receive_delete_community(
|
|
|
|
context: &LemmyContext,
|
|
|
|
context: &LemmyContext,
|
|
|
@ -45,23 +35,8 @@ pub(crate) async fn receive_delete_community(
|
|
|
|
|
|
|
|
|
|
|
|
pub(crate) async fn receive_remove_community(
|
|
|
|
pub(crate) async fn receive_remove_community(
|
|
|
|
context: &LemmyContext,
|
|
|
|
context: &LemmyContext,
|
|
|
|
activity: AnyBase,
|
|
|
|
community: Community,
|
|
|
|
expected_domain: &Url,
|
|
|
|
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
let remove = Remove::from_any_base(activity)?.context(location_info!())?;
|
|
|
|
|
|
|
|
verify_activity_domains_valid(&remove, expected_domain, true)?;
|
|
|
|
|
|
|
|
verify_is_addressed_to_public(&remove)?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let community_uri = remove
|
|
|
|
|
|
|
|
.object()
|
|
|
|
|
|
|
|
.to_owned()
|
|
|
|
|
|
|
|
.single_xsd_any_uri()
|
|
|
|
|
|
|
|
.context(location_info!())?;
|
|
|
|
|
|
|
|
let community = blocking(context.pool(), move |conn| {
|
|
|
|
|
|
|
|
Community::read_from_apub_id(conn, &community_uri.into())
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.await??;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let removed_community = blocking(context.pool(), move |conn| {
|
|
|
|
let removed_community = blocking(context.pool(), move |conn| {
|
|
|
|
Community::update_removed(conn, community.id, true)
|
|
|
|
Community::update_removed(conn, community.id, true)
|
|
|
|
})
|
|
|
|
})
|
|
|
@ -88,16 +63,8 @@ pub(crate) async fn receive_remove_community(
|
|
|
|
|
|
|
|
|
|
|
|
pub(crate) async fn receive_undo_delete_community(
|
|
|
|
pub(crate) async fn receive_undo_delete_community(
|
|
|
|
context: &LemmyContext,
|
|
|
|
context: &LemmyContext,
|
|
|
|
undo: Undo,
|
|
|
|
|
|
|
|
community: Community,
|
|
|
|
community: Community,
|
|
|
|
expected_domain: &Url,
|
|
|
|
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
verify_is_addressed_to_public(&undo)?;
|
|
|
|
|
|
|
|
let inner = undo.object().to_owned().one().context(location_info!())?;
|
|
|
|
|
|
|
|
let delete = Delete::from_any_base(inner)?.context(location_info!())?;
|
|
|
|
|
|
|
|
verify_activity_domains_valid(&delete, expected_domain, true)?;
|
|
|
|
|
|
|
|
verify_is_addressed_to_public(&delete)?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let deleted_community = blocking(context.pool(), move |conn| {
|
|
|
|
let deleted_community = blocking(context.pool(), move |conn| {
|
|
|
|
Community::update_deleted(conn, community.id, false)
|
|
|
|
Community::update_deleted(conn, community.id, false)
|
|
|
|
})
|
|
|
|
})
|
|
|
@ -124,26 +91,8 @@ pub(crate) async fn receive_undo_delete_community(
|
|
|
|
|
|
|
|
|
|
|
|
pub(crate) async fn receive_undo_remove_community(
|
|
|
|
pub(crate) async fn receive_undo_remove_community(
|
|
|
|
context: &LemmyContext,
|
|
|
|
context: &LemmyContext,
|
|
|
|
undo: Undo,
|
|
|
|
community: Community,
|
|
|
|
expected_domain: &Url,
|
|
|
|
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
verify_is_addressed_to_public(&undo)?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let inner = undo.object().to_owned().one().context(location_info!())?;
|
|
|
|
|
|
|
|
let remove = Remove::from_any_base(inner)?.context(location_info!())?;
|
|
|
|
|
|
|
|
verify_activity_domains_valid(&remove, &expected_domain, true)?;
|
|
|
|
|
|
|
|
verify_is_addressed_to_public(&remove)?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let community_uri = remove
|
|
|
|
|
|
|
|
.object()
|
|
|
|
|
|
|
|
.to_owned()
|
|
|
|
|
|
|
|
.single_xsd_any_uri()
|
|
|
|
|
|
|
|
.context(location_info!())?;
|
|
|
|
|
|
|
|
let community = blocking(context.pool(), move |conn| {
|
|
|
|
|
|
|
|
Community::read_from_apub_id(conn, &community_uri.into())
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.await??;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let removed_community = blocking(context.pool(), move |conn| {
|
|
|
|
let removed_community = blocking(context.pool(), move |conn| {
|
|
|
|
Community::update_removed(conn, community.id, false)
|
|
|
|
Community::update_removed(conn, community.id, false)
|
|
|
|
})
|
|
|
|
})
|
|
|
|