From eca458b0e56339b7a0783b418431238d1e261fec Mon Sep 17 00:00:00 2001 From: Trinity Pointard Date: Sat, 20 Oct 2018 15:03:59 +0200 Subject: [PATCH 1/2] Add support for blog deletion fix #181 --- plume-models/src/blogs.rs | 12 ++++++++++-- src/main.rs | 1 + src/routes/blogs.rs | 13 +++++++++++++ templates/blogs/details.html.tera | 7 +++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/plume-models/src/blogs.rs b/plume-models/src/blogs.rs index 09497ab0..0965f216 100644 --- a/plume-models/src/blogs.rs +++ b/plume-models/src/blogs.rs @@ -17,13 +17,14 @@ use webfinger::*; use {BASE_URL, USE_HTTPS, Connection}; use plume_common::activity_pub::{ ap_accept_header, ApSignature, ActivityStream, Id, IntoId, PublicKey, - inbox::WithInbox, + inbox::{Deletable, WithInbox}, sign }; use safe_string::SafeString; use instance::*; -use users::User; +use posts::Post; use schema::blogs; +use users::User; pub type CustomGroup = CustomObject; @@ -273,6 +274,13 @@ impl Blog { json["fqn"] = json!(self.get_fqn(conn)); json } + + pub fn delete(&self, conn: &Connection) { + for post in Post::get_for_blog(conn, &self) { + post.delete(conn); + } + diesel::delete(self).execute(conn).expect("Blog::delete: blog deletion error"); + } } impl IntoId for Blog { diff --git a/src/main.rs b/src/main.rs index cdd38b6b..8a1cec2d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -66,6 +66,7 @@ fn main() { routes::blogs::new, routes::blogs::new_auth, routes::blogs::create, + routes::blogs::delete, routes::blogs::atom_feed, routes::comments::create, diff --git a/src/routes/blogs.rs b/src/routes/blogs.rs index e18ebbb8..a5212d45 100644 --- a/src/routes/blogs.rs +++ b/src/routes/blogs.rs @@ -129,6 +129,19 @@ fn create(conn: DbConn, data: LenientForm, user: User) -> Result/delete")] +fn delete(conn: DbConn, name: String, user: Option) -> Result>{ + let blog = Blog::find_local(&*conn, name).ok_or(None)?; + if user.map(|u| u.is_author_in(&*conn, blog.clone())).unwrap_or(false) { + blog.delete(&conn); + Ok(Redirect::to(uri!(super::instance::index))) + } else { + Err(Some(Template::render("errors/403", json!({// TODO actually return 403 error code + "error_message": "You are not allowed to delete this blog." + })))) + } +} + #[get("/~//outbox")] fn outbox(name: String, conn: DbConn) -> Option> { let blog = Blog::find_local(&*conn, name)?; diff --git a/templates/blogs/details.html.tera b/templates/blogs/details.html.tera index 63d7cdd4..93b70d6e 100644 --- a/templates/blogs/details.html.tera +++ b/templates/blogs/details.html.tera @@ -40,4 +40,11 @@ {{ macros::paginate(page=page, total=n_pages) }} + {% if is_author %} +

{{ "Danger zone" | _ }}

+

{{ "Be very careful, any action taken here can't be cancelled." | _ }} +

+ +
+ {% endif %} {% endblock content %} From d47aff70f7b82c90d7a85743fc2394c9a712c6c8 Mon Sep 17 00:00:00 2001 From: Trinity Pointard Date: Sun, 21 Oct 2018 12:09:22 +0200 Subject: [PATCH 2/2] Add new string to translate for blog deletion --- po/en.po | 3 +++ po/fr.po | 3 +++ po/gl.po | 3 +++ po/nb.po | 3 +++ po/pl.po | 3 +++ po/plume.pot | 3 +++ 6 files changed, 18 insertions(+) diff --git a/po/en.po b/po/en.po index 7586ad98..ec68bff0 100644 --- a/po/en.po +++ b/po/en.po @@ -434,6 +434,9 @@ msgstr "" msgid "Delete this article" msgstr "" +msgid "Delete this blog" +msgstr "" + msgid "And connected to" msgstr "" diff --git a/po/fr.po b/po/fr.po index c858f2d5..435ac9c3 100644 --- a/po/fr.po +++ b/po/fr.po @@ -445,6 +445,9 @@ msgstr "Lire les règles détaillées" msgid "Delete this article" msgstr "Supprimer cet article" +msgid "Delete this blog" +msgstr "Supprimer ce blog" + msgid "And connected to" msgstr "Et connectée à" diff --git a/po/gl.po b/po/gl.po index fd219f78..8098f336 100644 --- a/po/gl.po +++ b/po/gl.po @@ -433,6 +433,9 @@ msgstr "Lea o detalle das normas" msgid "Delete this article" msgstr "Borrar este artigo" +msgid "Delete this blog" +msgstr "Borrar este blog" + msgid "And connected to" msgstr "E conectada a" diff --git a/po/nb.po b/po/nb.po index b6369909..04f7feb8 100644 --- a/po/nb.po +++ b/po/nb.po @@ -442,6 +442,9 @@ msgstr "Les reglene" msgid "Delete this article" msgstr "Siste artikler" +msgid "Delete this blog" +msgstr "" + msgid "And connected to" msgstr "" diff --git a/po/pl.po b/po/pl.po index 9e28d738..94ff56ad 100644 --- a/po/pl.po +++ b/po/pl.po @@ -446,6 +446,9 @@ msgstr "Przeczytaj szczegółowe zasady" msgid "Delete this article" msgstr "Usuń ten artykuł" +msgid "Delete this blog" +msgstr "" + msgid "And connected to" msgstr "Połączony z" diff --git a/po/plume.pot b/po/plume.pot index 423338ed..75bc55a1 100644 --- a/po/plume.pot +++ b/po/plume.pot @@ -424,6 +424,9 @@ msgstr "" msgid "Delete this article" msgstr "" +msgid "Delete this blog" +msgstr "" + msgid "And connected to" msgstr ""