Add a way to delete articles

Fixes #116
This commit is contained in:
Bat
2018-09-01 16:28:47 +01:00
parent 70ef4d6a74
commit cea548b821
12 changed files with 103 additions and 53 deletions
+8 -3
View File
@@ -1,4 +1,4 @@
use activitypub::activity::{Announce, Create, Like, Undo};
use activitypub::{activity::{Announce, Create, Delete, Like, Undo}, object::Tombstone};
use diesel::PgConnection;
use failure::Error;
use serde_json;
@@ -32,6 +32,11 @@ pub trait Inbox {
Err(InboxError::InvalidType)?
}
},
"Delete" => {
let act: Delete = serde_json::from_value(act.clone())?;
Post::delete_id(act.delete_props.object_object::<Tombstone>()?.object_props.id_string()?, conn);
Ok(())
},
"Follow" => {
Follow::from_activity(conn, serde_json::from_value(act.clone())?, actor_id);
Ok(())
@@ -44,11 +49,11 @@ pub trait Inbox {
let act: Undo = serde_json::from_value(act.clone())?;
match act.undo_props.object["type"].as_str().unwrap() {
"Like" => {
likes::Like::delete_activity(conn, Id::new(act.undo_props.object_object::<Like>()?.object_props.id_string()?));
likes::Like::delete_id(act.undo_props.object_object::<Like>()?.object_props.id_string()?, conn);
Ok(())
},
"Announce" => {
Reshare::delete_activity(conn, Id::new(act.undo_props.object_object::<Announce>()?.object_props.id_string()?));
Reshare::delete_id(act.undo_props.object_object::<Announce>()?.object_props.id_string()?, conn);
Ok(())
}
_ => Err(InboxError::CantUndo)?
+1
View File
@@ -68,6 +68,7 @@ fn main() {
routes::posts::new,
routes::posts::new_auth,
routes::posts::create,
routes::posts::delete,
routes::reshares::create,
routes::reshares::create_auth,
+1 -1
View File
@@ -1,7 +1,7 @@
use rocket::{State, response::{Redirect, Flash}};
use workerpool::{Pool, thunk::*};
use plume_common::activity_pub::{broadcast, inbox::Notify};
use plume_common::activity_pub::{broadcast, inbox::{Notify, Deletable}};
use plume_common::utils;
use plume_models::{
blogs::Blog,
+24 -3
View File
@@ -8,7 +8,7 @@ use std::{collections::HashMap, borrow::Cow};
use validator::{Validate, ValidationError, ValidationErrors};
use workerpool::{Pool, thunk::*};
use plume_common::activity_pub::{broadcast, ActivityStream, ApRequest};
use plume_common::activity_pub::{broadcast, ActivityStream, ApRequest, inbox::Deletable};
use plume_common::utils;
use plume_models::{
blogs::*,
@@ -53,10 +53,11 @@ fn details_response(blog: String, slug: String, conn: DbConn, user: Option<User>
"has_liked": user.clone().map(|u| u.has_liked(&*conn, &post)).unwrap_or(false),
"n_reshares": post.get_reshares(&*conn).len(),
"has_reshared": user.clone().map(|u| u.has_reshared(&*conn, &post)).unwrap_or(false),
"account": user,
"account": &user,
"date": &post.creation_date.timestamp(),
"previous": query.and_then(|q| q.responding_to.map(|r| Comment::get(&*conn, r).expect("Error retrieving previous comment").to_json(&*conn, &vec![]))),
"user_fqn": user.map(|u| u.get_fqn(&*conn)).unwrap_or(String::new())
"user_fqn": user.clone().map(|u| u.get_fqn(&*conn)).unwrap_or(String::new()),
"is_author": user.map(|u| post.get_authors(&*conn).into_iter().any(|a| u.id == a.id)).unwrap_or(false)
}))
})
})
@@ -176,3 +177,23 @@ fn create(blog_name: String, data: LenientForm<NewPostForm>, user: User, conn: D
})))
}
}
#[post("/~/<blog_name>/<slug>/delete")]
fn delete(blog_name: String, slug: String, conn: DbConn, user: User, worker: State<Pool<ThunkWorker<()>>>) -> Redirect {
let post = Blog::find_by_fqn(&*conn, blog_name.clone())
.and_then(|blog| Post::find_by_slug(&*conn, slug.clone(), blog.id));
if let Some(post) = post {
if !post.get_authors(&*conn).into_iter().any(|a| a.id == user.id) {
Redirect::to(uri!(details: blog = blog_name.clone(), slug = slug.clone()))
} else {
let audience = user.get_followers(&*conn);
let delete_activity = post.delete(&*conn);
worker.execute(Thunk::of(move || broadcast(&user, delete_activity, audience)));
Redirect::to(uri!(super::blogs::details: name = blog_name))
}
} else {
Redirect::to(uri!(super::blogs::details: name = blog_name))
}
}
+1 -1
View File
@@ -1,7 +1,7 @@
use rocket::{State, response::{Redirect, Flash}};
use workerpool::{Pool, thunk::*};
use plume_common::activity_pub::{broadcast, inbox::Notify};
use plume_common::activity_pub::{broadcast, inbox::{Deletable, Notify}};
use plume_common::utils;
use plume_models::{
blogs::Blog,
+1 -1
View File
@@ -215,7 +215,7 @@ fn create_admin(instance: Instance, conn: DbConn) {
fn check_native_deps() {
let mut not_found = Vec::new();
if !try_run("psql") {
not_found.push(("PostgreSQL", "sudo apt install postgres"));
not_found.push(("PostgreSQL", "sudo apt install postgresql"));
}
if !try_run("gettext") {
not_found.push(("GetText", "sudo apt install gettext"))