Remove searcher from arguments of Post::delete() and dependented methods
This commit is contained in:
parent
2a8cc5f3ba
commit
fc8ee1c3bc
@ -1,6 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
ap_url, instance::*, medias::Media, posts::Post, safe_string::SafeString, schema::blogs,
|
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::{
|
use activitypub::{
|
||||||
actor::Group,
|
actor::Group,
|
||||||
@ -317,9 +317,9 @@ impl Blog {
|
|||||||
.and_then(|c| c.url().ok())
|
.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)? {
|
for post in Post::get_for_blog(conn, &self)? {
|
||||||
post.delete(conn, searcher)?;
|
post.delete(conn)?;
|
||||||
}
|
}
|
||||||
diesel::delete(self)
|
diesel::delete(self)
|
||||||
.execute(conn)
|
.execute(conn)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
ap_url, blogs::Blog, instance::Instance, medias::Media, mentions::Mention, post_authors::*,
|
ap_url, blogs::Blog, instance::Instance, medias::Media, mentions::Mention, post_authors::*,
|
||||||
safe_string::SafeString, schema::posts, search::Searcher, tags::*, timeline::*, users::User,
|
safe_string::SafeString, schema::posts, tags::*, timeline::*, users::User, Connection, Error,
|
||||||
Connection, Error, PlumeRocket, PostEvent::*, Result, CONFIG, POST_CHAN,
|
PlumeRocket, PostEvent::*, Result, CONFIG, POST_CHAN,
|
||||||
};
|
};
|
||||||
use activitypub::{
|
use activitypub::{
|
||||||
activity::{Create, Delete, Update},
|
activity::{Create, Delete, Update},
|
||||||
@ -93,7 +93,7 @@ impl Post {
|
|||||||
Ok(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)? {
|
for m in Mention::list_for_post(&conn, self.id)? {
|
||||||
m.delete(conn)?;
|
m.delete(conn)?;
|
||||||
}
|
}
|
||||||
@ -703,7 +703,7 @@ impl AsObject<User, Delete, &PlumeRocket> for Post {
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.any(|a| actor.id == a.id);
|
.any(|a| actor.id == a.id);
|
||||||
if can_delete {
|
if can_delete {
|
||||||
self.delete(&c.conn, &c.searcher).map(|_| ())
|
self.delete(&c.conn).map(|_| ())
|
||||||
} else {
|
} else {
|
||||||
Err(Error::Unauthorized)
|
Err(Error::Unauthorized)
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
ap_url, blocklisted_emails::BlocklistedEmail, blogs::Blog, db_conn::DbConn, follows::Follow,
|
ap_url, blocklisted_emails::BlocklistedEmail, blogs::Blog, db_conn::DbConn, follows::Follow,
|
||||||
instance::*, medias::Media, notifications::Notification, post_authors::PostAuthor, posts::Post,
|
instance::*, medias::Media, notifications::Notification, post_authors::PostAuthor, posts::Post,
|
||||||
safe_string::SafeString, schema::users, search::Searcher, timeline::Timeline, Connection,
|
safe_string::SafeString, schema::users, timeline::Timeline, Connection, Error, PlumeRocket,
|
||||||
Error, PlumeRocket, Result, CONFIG, ITEMS_PER_PAGE,
|
Result, CONFIG, ITEMS_PER_PAGE,
|
||||||
};
|
};
|
||||||
use activitypub::{
|
use activitypub::{
|
||||||
activity::Delete,
|
activity::Delete,
|
||||||
@ -129,14 +129,14 @@ impl User {
|
|||||||
.map_err(Error::from)
|
.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;
|
use crate::schema::post_authors;
|
||||||
|
|
||||||
for blog in Blog::find_for_author(conn, self)?
|
for blog in Blog::find_for_author(conn, self)?
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|b| b.count_authors(conn).map(|c| c <= 1).unwrap_or(false))
|
.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
|
// delete the posts if they is the only author
|
||||||
let all_their_posts_ids: Vec<i32> = post_authors::table
|
let all_their_posts_ids: Vec<i32> = post_authors::table
|
||||||
@ -156,7 +156,7 @@ impl User {
|
|||||||
.unwrap_or(&0)
|
.unwrap_or(&0)
|
||||||
> &0;
|
> &0;
|
||||||
if !has_other_authors {
|
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<()> {
|
fn activity(self, c: &PlumeRocket, actor: User, _id: &str) -> Result<()> {
|
||||||
if self.id == actor.id {
|
if self.id == actor.id {
|
||||||
self.delete(&c.conn, &c.searcher).map(|_| ())
|
self.delete(&c.conn).map(|_| ())
|
||||||
} else {
|
} else {
|
||||||
Err(Error::Unauthorized)
|
Err(Error::Unauthorized)
|
||||||
}
|
}
|
||||||
@ -1227,9 +1227,7 @@ pub(crate) mod tests {
|
|||||||
let inserted = fill_database(conn);
|
let inserted = fill_database(conn);
|
||||||
|
|
||||||
assert!(User::get(conn, inserted[0].id).is_ok());
|
assert!(User::get(conn, inserted[0].id).is_ok());
|
||||||
inserted[0]
|
inserted[0].delete(conn).unwrap();
|
||||||
.delete(conn, &get_searcher(&CONFIG.search_tokenizers))
|
|
||||||
.unwrap();
|
|
||||||
assert!(User::get(conn, inserted[0].id).is_err());
|
assert!(User::get(conn, inserted[0].id).is_err());
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
@ -1319,7 +1317,7 @@ pub(crate) mod tests {
|
|||||||
let users = fill_database(conn);
|
let users = fill_database(conn);
|
||||||
|
|
||||||
let ap_repr = users[0].to_activity(conn).unwrap();
|
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();
|
let user = User::from_activity(&r, ap_repr).unwrap();
|
||||||
|
|
||||||
assert_eq!(user.username, users[0].username);
|
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)?;
|
let author = User::get(&*rockets.conn, auth.0.user_id)?;
|
||||||
if let Ok(post) = Post::get(&*rockets.conn, id) {
|
if let Ok(post) = Post::get(&*rockets.conn, id) {
|
||||||
if post.is_author(&*rockets.conn, author.id).unwrap_or(false) {
|
if post.is_author(&*rockets.conn, author.id).unwrap_or(false) {
|
||||||
post.delete(&*rockets.conn, &rockets.searcher)?;
|
post.delete(&*rockets.conn)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Json(()))
|
Ok(Json(()))
|
||||||
|
@ -153,8 +153,7 @@ pub fn delete(name: String, rockets: PlumeRocket) -> RespondOrRedirect {
|
|||||||
.and_then(|u| u.is_author_in(&*conn, &blog).ok())
|
.and_then(|u| u.is_author_in(&*conn, &blog).ok())
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
{
|
{
|
||||||
blog.delete(&conn, &rockets.searcher)
|
blog.delete(&conn).expect("blog::expect: deletion error");
|
||||||
.expect("blog::expect: deletion error");
|
|
||||||
Flash::success(
|
Flash::success(
|
||||||
Redirect::to(uri!(super::instance::index)),
|
Redirect::to(uri!(super::instance::index)),
|
||||||
i18n!(rockets.intl.catalog, "Your blog was deleted."),
|
i18n!(rockets.intl.catalog, "Your blog was deleted."),
|
||||||
|
@ -21,7 +21,6 @@ use plume_models::{
|
|||||||
instance::*,
|
instance::*,
|
||||||
posts::Post,
|
posts::Post,
|
||||||
safe_string::SafeString,
|
safe_string::SafeString,
|
||||||
search::Searcher,
|
|
||||||
timeline::Timeline,
|
timeline::Timeline,
|
||||||
users::{Role, User},
|
users::{Role, User},
|
||||||
Connection, Error, PlumeRocket, CONFIG,
|
Connection, Error, PlumeRocket, CONFIG,
|
||||||
@ -331,7 +330,6 @@ pub fn edit_users(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let conn = &rockets.conn;
|
let conn = &rockets.conn;
|
||||||
let searcher = &*rockets.searcher;
|
|
||||||
let worker = &*rockets.worker;
|
let worker = &*rockets.worker;
|
||||||
match form.action {
|
match form.action {
|
||||||
UserActions::Admin => {
|
UserActions::Admin => {
|
||||||
@ -351,7 +349,7 @@ pub fn edit_users(
|
|||||||
}
|
}
|
||||||
UserActions::Ban => {
|
UserActions::Ban => {
|
||||||
for u in form.ids.clone() {
|
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(
|
fn ban(id: i32, conn: &Connection, worker: &ScheduledThreadPool) -> Result<(), ErrorPage> {
|
||||||
id: i32,
|
|
||||||
conn: &Connection,
|
|
||||||
searcher: &Searcher,
|
|
||||||
worker: &ScheduledThreadPool,
|
|
||||||
) -> Result<(), ErrorPage> {
|
|
||||||
let u = User::get(&*conn, id)?;
|
let u = User::get(&*conn, id)?;
|
||||||
u.delete(&*conn, searcher)?;
|
u.delete(&*conn)?;
|
||||||
if Instance::get_local()
|
if Instance::get_local()
|
||||||
.map(|i| u.instance_id == i.id)
|
.map(|i| u.instance_id == i.id)
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
|
@ -421,7 +421,7 @@ pub fn delete(
|
|||||||
) -> Result<Flash<Redirect>, ErrorPage> {
|
) -> Result<Flash<Redirect>, ErrorPage> {
|
||||||
let account = User::find_by_fqn(&rockets, &name)?;
|
let account = User::find_by_fqn(&rockets, &name)?;
|
||||||
if user.id == account.id {
|
if user.id == account.id {
|
||||||
account.delete(&*rockets.conn, &rockets.searcher)?;
|
account.delete(&*rockets.conn)?;
|
||||||
|
|
||||||
let target = User::one_by_instance(&*rockets.conn)?;
|
let target = User::one_by_instance(&*rockets.conn)?;
|
||||||
let delete_act = account.delete_activity(&*rockets.conn)?;
|
let delete_act = account.delete_activity(&*rockets.conn)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user