Remove searcher from arguments of Post::delete() and dependented methods

pull/870/head
Kitaiti Makoto 3 years ago
parent 2a8cc5f3ba
commit fc8ee1c3bc

@ -1,6 +1,6 @@
use crate::{
ap_url, instance::*, medias::Media, posts::Post, safe_string::SafeString, schema::blogs,
search::Searcher, users::User, Connection, Error, PlumeRocket, Result, CONFIG, ITEMS_PER_PAGE,
users::User, Connection, Error, PlumeRocket, Result, CONFIG, ITEMS_PER_PAGE,
};
use activitypub::{
actor::Group,
@ -317,9 +317,9 @@ impl Blog {
.and_then(|c| c.url().ok())
}
pub fn delete(&self, conn: &Connection, searcher: &Searcher) -> Result<()> {
pub fn delete(&self, conn: &Connection) -> Result<()> {
for post in Post::get_for_blog(conn, &self)? {
post.delete(conn, searcher)?;
post.delete(conn)?;
}
diesel::delete(self)
.execute(conn)

@ -1,7 +1,7 @@
use crate::{
ap_url, blogs::Blog, instance::Instance, medias::Media, mentions::Mention, post_authors::*,
safe_string::SafeString, schema::posts, search::Searcher, tags::*, timeline::*, users::User,
Connection, Error, PlumeRocket, PostEvent::*, Result, CONFIG, POST_CHAN,
safe_string::SafeString, schema::posts, tags::*, timeline::*, users::User, Connection, Error,
PlumeRocket, PostEvent::*, Result, CONFIG, POST_CHAN,
};
use activitypub::{
activity::{Create, Delete, Update},
@ -93,7 +93,7 @@ impl Post {
Ok(post)
}
pub fn delete(&self, conn: &Connection, _searcher: &Searcher) -> Result<()> {
pub fn delete(&self, conn: &Connection) -> Result<()> {
for m in Mention::list_for_post(&conn, self.id)? {
m.delete(conn)?;
}
@ -703,7 +703,7 @@ impl AsObject<User, Delete, &PlumeRocket> for Post {
.into_iter()
.any(|a| actor.id == a.id);
if can_delete {
self.delete(&c.conn, &c.searcher).map(|_| ())
self.delete(&c.conn).map(|_| ())
} else {
Err(Error::Unauthorized)
}

@ -1,8 +1,8 @@
use crate::{
ap_url, blocklisted_emails::BlocklistedEmail, blogs::Blog, db_conn::DbConn, follows::Follow,
instance::*, medias::Media, notifications::Notification, post_authors::PostAuthor, posts::Post,
safe_string::SafeString, schema::users, search::Searcher, timeline::Timeline, Connection,
Error, PlumeRocket, Result, CONFIG, ITEMS_PER_PAGE,
safe_string::SafeString, schema::users, timeline::Timeline, Connection, Error, PlumeRocket,
Result, CONFIG, ITEMS_PER_PAGE,
};
use activitypub::{
activity::Delete,
@ -129,14 +129,14 @@ impl User {
.map_err(Error::from)
}
pub fn delete(&self, conn: &Connection, searcher: &Searcher) -> Result<()> {
pub fn delete(&self, conn: &Connection) -> Result<()> {
use crate::schema::post_authors;
for blog in Blog::find_for_author(conn, self)?
.iter()
.filter(|b| b.count_authors(conn).map(|c| c <= 1).unwrap_or(false))
{
blog.delete(conn, searcher)?;
blog.delete(conn)?;
}
// delete the posts if they is the only author
let all_their_posts_ids: Vec<i32> = post_authors::table
@ -156,7 +156,7 @@ impl User {
.unwrap_or(&0)
> &0;
if !has_other_authors {
Post::get(conn, post_id)?.delete(conn, searcher)?;
Post::get(conn, post_id)?.delete(conn)?;
}
}
@ -1037,7 +1037,7 @@ impl AsObject<User, Delete, &PlumeRocket> for User {
fn activity(self, c: &PlumeRocket, actor: User, _id: &str) -> Result<()> {
if self.id == actor.id {
self.delete(&c.conn, &c.searcher).map(|_| ())
self.delete(&c.conn).map(|_| ())
} else {
Err(Error::Unauthorized)
}
@ -1227,9 +1227,7 @@ pub(crate) mod tests {
let inserted = fill_database(conn);
assert!(User::get(conn, inserted[0].id).is_ok());
inserted[0]
.delete(conn, &get_searcher(&CONFIG.search_tokenizers))
.unwrap();
inserted[0].delete(conn).unwrap();
assert!(User::get(conn, inserted[0].id).is_err());
Ok(())
});
@ -1319,7 +1317,7 @@ pub(crate) mod tests {
let users = fill_database(conn);
let ap_repr = users[0].to_activity(conn).unwrap();
users[0].delete(conn, &*r.searcher).unwrap();
users[0].delete(conn).unwrap();
let user = User::from_activity(&r, ap_repr).unwrap();
assert_eq!(user.username, users[0].username);

@ -230,7 +230,7 @@ pub fn delete(auth: Authorization<Write, Post>, rockets: PlumeRocket, id: i32) -
let author = User::get(&*rockets.conn, auth.0.user_id)?;
if let Ok(post) = Post::get(&*rockets.conn, id) {
if post.is_author(&*rockets.conn, author.id).unwrap_or(false) {
post.delete(&*rockets.conn, &rockets.searcher)?;
post.delete(&*rockets.conn)?;
}
}
Ok(Json(()))

@ -153,8 +153,7 @@ pub fn delete(name: String, rockets: PlumeRocket) -> RespondOrRedirect {
.and_then(|u| u.is_author_in(&*conn, &blog).ok())
.unwrap_or(false)
{
blog.delete(&conn, &rockets.searcher)
.expect("blog::expect: deletion error");
blog.delete(&conn).expect("blog::expect: deletion error");
Flash::success(
Redirect::to(uri!(super::instance::index)),
i18n!(rockets.intl.catalog, "Your blog was deleted."),

@ -21,7 +21,6 @@ use plume_models::{
instance::*,
posts::Post,
safe_string::SafeString,
search::Searcher,
timeline::Timeline,
users::{Role, User},
Connection, Error, PlumeRocket, CONFIG,
@ -331,7 +330,6 @@ pub fn edit_users(
}
let conn = &rockets.conn;
let searcher = &*rockets.searcher;
let worker = &*rockets.worker;
match form.action {
UserActions::Admin => {
@ -351,7 +349,7 @@ pub fn edit_users(
}
UserActions::Ban => {
for u in form.ids.clone() {
ban(u, conn, searcher, worker)?;
ban(u, conn, worker)?;
}
}
}
@ -362,14 +360,9 @@ pub fn edit_users(
))
}
fn ban(
id: i32,
conn: &Connection,
searcher: &Searcher,
worker: &ScheduledThreadPool,
) -> Result<(), ErrorPage> {
fn ban(id: i32, conn: &Connection, worker: &ScheduledThreadPool) -> Result<(), ErrorPage> {
let u = User::get(&*conn, id)?;
u.delete(&*conn, searcher)?;
u.delete(&*conn)?;
if Instance::get_local()
.map(|i| u.instance_id == i.id)
.unwrap_or(false)

@ -421,7 +421,7 @@ pub fn delete(
) -> Result<Flash<Redirect>, ErrorPage> {
let account = User::find_by_fqn(&rockets, &name)?;
if user.id == account.id {
account.delete(&*rockets.conn, &rockets.searcher)?;
account.delete(&*rockets.conn)?;
let target = User::one_by_instance(&*rockets.conn)?;
let delete_act = account.delete_activity(&*rockets.conn)?;

Loading…
Cancel
Save