From fc8ee1c3bc808bffde53ffd0793233c7681edb6c Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Thu, 7 Jan 2021 22:51:46 +0900 Subject: [PATCH] Remove searcher from arguments of Post::delete() and dependented methods --- plume-models/src/blogs.rs | 6 +++--- plume-models/src/posts.rs | 8 ++++---- plume-models/src/users.rs | 18 ++++++++---------- src/api/posts.rs | 2 +- src/routes/blogs.rs | 3 +-- src/routes/instance.rs | 13 +++---------- src/routes/user.rs | 2 +- 7 files changed, 21 insertions(+), 31 deletions(-) diff --git a/plume-models/src/blogs.rs b/plume-models/src/blogs.rs index 8df4a9dc..e524c282 100644 --- a/plume-models/src/blogs.rs +++ b/plume-models/src/blogs.rs @@ -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) diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs index 1aafa693..6fe25254 100644 --- a/plume-models/src/posts.rs +++ b/plume-models/src/posts.rs @@ -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 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) } diff --git a/plume-models/src/users.rs b/plume-models/src/users.rs index 753774f8..d3b73684 100644 --- a/plume-models/src/users.rs +++ b/plume-models/src/users.rs @@ -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 = 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 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); diff --git a/src/api/posts.rs b/src/api/posts.rs index ad483a12..fca56108 100644 --- a/src/api/posts.rs +++ b/src/api/posts.rs @@ -230,7 +230,7 @@ pub fn delete(auth: Authorization, 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(())) diff --git a/src/routes/blogs.rs b/src/routes/blogs.rs index 0c08c536..8696e82d 100644 --- a/src/routes/blogs.rs +++ b/src/routes/blogs.rs @@ -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."), diff --git a/src/routes/instance.rs b/src/routes/instance.rs index 83bc46b6..bec1b092 100644 --- a/src/routes/instance.rs +++ b/src/routes/instance.rs @@ -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) diff --git a/src/routes/user.rs b/src/routes/user.rs index f64fd42c..2a9f2080 100644 --- a/src/routes/user.rs +++ b/src/routes/user.rs @@ -421,7 +421,7 @@ pub fn delete( ) -> Result, 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)?;