Use User::delete_activity07() instead of delete_activity()
This commit is contained in:
parent
fd341bdb22
commit
effdc44943
@ -4,21 +4,16 @@ use crate::{
|
|||||||
safe_string::SafeString, schema::users, timeline::Timeline, Connection, Error, Result,
|
safe_string::SafeString, schema::users, timeline::Timeline, Connection, Error, Result,
|
||||||
UserEvent::*, CONFIG, ITEMS_PER_PAGE, USER_CHAN,
|
UserEvent::*, CONFIG, ITEMS_PER_PAGE, USER_CHAN,
|
||||||
};
|
};
|
||||||
use activitypub::{
|
use activitypub::{actor::Person, object::Image, Activity, CustomObject, Endpoint};
|
||||||
activity::Delete,
|
|
||||||
actor::Person,
|
|
||||||
object::{Image, Tombstone},
|
|
||||||
Activity, CustomObject, Endpoint,
|
|
||||||
};
|
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
activity::Delete as Delete07,
|
activity::Delete,
|
||||||
actor::{ApActor, AsApActor},
|
actor::{ApActor, AsApActor},
|
||||||
actor::{ApActor as ApActor07, Endpoints as Endpoints07, Person as Person07},
|
actor::{ApActor as ApActor07, Endpoints as Endpoints07, Person as Person07},
|
||||||
base::{AnyBase, Base},
|
base::{AnyBase, Base},
|
||||||
collection::{OrderedCollection as OrderedCollection07, OrderedCollectionPage},
|
collection::{OrderedCollection as OrderedCollection07, OrderedCollectionPage},
|
||||||
iri_string::types::IriString,
|
iri_string::types::IriString,
|
||||||
markers::Activity as Activity07,
|
markers::Activity as Activity07,
|
||||||
object::{kind::ImageType, AsObject as _, Image as Image07, Tombstone as Tombstone07},
|
object::{kind::ImageType, AsObject as _, Image as Image07, Tombstone},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
use chrono::{NaiveDateTime, Utc};
|
use chrono::{NaiveDateTime, Utc};
|
||||||
@ -917,34 +912,11 @@ impl User {
|
|||||||
Ok(CustomPerson07::new(actor, ap_signature))
|
Ok(CustomPerson07::new(actor, ap_signature))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete_activity(&self, conn: &Connection) -> Result<Delete> {
|
pub fn delete_activity07(&self, conn: &Connection) -> Result<Delete> {
|
||||||
let mut del = Delete::default();
|
let mut tombstone = Tombstone::new();
|
||||||
|
|
||||||
let mut tombstone = Tombstone::default();
|
|
||||||
tombstone.object_props.set_id_string(self.ap_url.clone())?;
|
|
||||||
|
|
||||||
del.delete_props
|
|
||||||
.set_actor_link(Id::new(self.ap_url.clone()))?;
|
|
||||||
del.delete_props.set_object_object(tombstone)?;
|
|
||||||
del.object_props
|
|
||||||
.set_id_string(format!("{}#delete", self.ap_url))?;
|
|
||||||
del.object_props
|
|
||||||
.set_to_link_vec(vec![Id::new(PUBLIC_VISIBILITY)])?;
|
|
||||||
del.object_props.set_cc_link_vec(
|
|
||||||
self.get_followers(conn)?
|
|
||||||
.into_iter()
|
|
||||||
.map(|f| Id::new(f.ap_url))
|
|
||||||
.collect(),
|
|
||||||
)?;
|
|
||||||
|
|
||||||
Ok(del)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn delete_activity07(&self, conn: &Connection) -> Result<Delete07> {
|
|
||||||
let mut tombstone = Tombstone07::new();
|
|
||||||
tombstone.set_id(self.ap_url.parse()?);
|
tombstone.set_id(self.ap_url.parse()?);
|
||||||
|
|
||||||
let mut del = Delete07::new(
|
let mut del = Delete::new(
|
||||||
self.ap_url.parse::<IriString>()?,
|
self.ap_url.parse::<IriString>()?,
|
||||||
Base::retract(tombstone)?.into_generic()?,
|
Base::retract(tombstone)?.into_generic()?,
|
||||||
);
|
);
|
||||||
@ -1192,7 +1164,7 @@ impl AsActor<&DbConn> for User {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsObject<User, Delete07, &DbConn> for User {
|
impl AsObject<User, Delete, &DbConn> for User {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Output = ();
|
type Output = ();
|
||||||
|
|
||||||
@ -1700,32 +1672,6 @@ pub(crate) mod tests {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn delete_activity() {
|
|
||||||
let conn = db();
|
|
||||||
conn.test_transaction::<_, Error, _>(|| {
|
|
||||||
let users = fill_database(&conn);
|
|
||||||
let user = &users[1];
|
|
||||||
let act = user.delete_activity(&conn)?;
|
|
||||||
|
|
||||||
let expected = json!({
|
|
||||||
"actor": "https://plu.me/@/user/",
|
|
||||||
"cc": [],
|
|
||||||
"id": "https://plu.me/@/user/#delete",
|
|
||||||
"object": {
|
|
||||||
"id": "https://plu.me/@/user/",
|
|
||||||
"type": "Tombstone",
|
|
||||||
},
|
|
||||||
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
|
||||||
"type": "Delete",
|
|
||||||
});
|
|
||||||
|
|
||||||
assert_json_eq!(to_value(act)?, expected);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn delete_activity07() {
|
fn delete_activity07() {
|
||||||
let conn = db();
|
let conn = db();
|
||||||
|
@ -11,7 +11,7 @@ use validator::{Validate, ValidationErrors};
|
|||||||
use crate::inbox;
|
use crate::inbox;
|
||||||
use crate::routes::{errors::ErrorPage, rocket_uri_macro_static_files, Page, RespondOrRedirect};
|
use crate::routes::{errors::ErrorPage, rocket_uri_macro_static_files, Page, RespondOrRedirect};
|
||||||
use crate::template_utils::{IntoContext, Ructe};
|
use crate::template_utils::{IntoContext, Ructe};
|
||||||
use plume_common::activity_pub::{broadcast, inbox::FromId};
|
use plume_common::activity_pub::{broadcast07, inbox::FromId};
|
||||||
use plume_models::{
|
use plume_models::{
|
||||||
admin::*,
|
admin::*,
|
||||||
blocklisted_emails::*,
|
blocklisted_emails::*,
|
||||||
@ -382,8 +382,8 @@ fn ban(id: i32, conn: &Connection, worker: &ScheduledThreadPool) -> Result<(), E
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let target = User::one_by_instance(&*conn)?;
|
let target = User::one_by_instance(&*conn)?;
|
||||||
let delete_act = u.delete_activity(&*conn)?;
|
let delete_act = u.delete_activity07(&*conn)?;
|
||||||
worker.execute(move || broadcast(&u, delete_act, target, CONFIG.proxy().cloned()));
|
worker.execute(move || broadcast07(&u, delete_act, target, CONFIG.proxy().cloned()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -18,7 +18,7 @@ use crate::routes::{
|
|||||||
};
|
};
|
||||||
use crate::template_utils::{IntoContext, Ructe};
|
use crate::template_utils::{IntoContext, Ructe};
|
||||||
use crate::utils::requires_login;
|
use crate::utils::requires_login;
|
||||||
use plume_common::activity_pub::{broadcast, ActivityStream, ApRequest, Id};
|
use plume_common::activity_pub::{broadcast, broadcast07, ActivityStream, ApRequest, Id};
|
||||||
use plume_common::utils::md_to_html;
|
use plume_common::utils::md_to_html;
|
||||||
use plume_models::{
|
use plume_models::{
|
||||||
blogs::Blog,
|
blogs::Blog,
|
||||||
@ -386,10 +386,10 @@ pub fn delete(
|
|||||||
account.delete(&conn)?;
|
account.delete(&conn)?;
|
||||||
|
|
||||||
let target = User::one_by_instance(&conn)?;
|
let target = User::one_by_instance(&conn)?;
|
||||||
let delete_act = account.delete_activity(&conn)?;
|
let delete_act = account.delete_activity07(&conn)?;
|
||||||
rockets
|
rockets
|
||||||
.worker
|
.worker
|
||||||
.execute(move || broadcast(&account, delete_act, target, CONFIG.proxy().cloned()));
|
.execute(move || broadcast07(&account, delete_act, target, CONFIG.proxy().cloned()));
|
||||||
|
|
||||||
if let Some(cookie) = cookies.get_private(AUTH_COOKIE) {
|
if let Some(cookie) = cookies.get_private(AUTH_COOKIE) {
|
||||||
cookies.remove_private(cookie);
|
cookies.remove_private(cookie);
|
||||||
|
Loading…
Reference in New Issue
Block a user