Merge pull request #282 from Plume-org/blog-deletion

Add support for blog deletion
This commit is contained in:
Baptiste Gelez 2018-10-21 13:39:41 +01:00 committed by GitHub
commit 9187aefda0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 49 additions and 2 deletions

View File

@ -17,13 +17,14 @@ use webfinger::*;
use {BASE_URL, USE_HTTPS, Connection}; use {BASE_URL, USE_HTTPS, Connection};
use plume_common::activity_pub::{ use plume_common::activity_pub::{
ap_accept_header, ApSignature, ActivityStream, Id, IntoId, PublicKey, ap_accept_header, ApSignature, ActivityStream, Id, IntoId, PublicKey,
inbox::WithInbox, inbox::{Deletable, WithInbox},
sign sign
}; };
use safe_string::SafeString; use safe_string::SafeString;
use instance::*; use instance::*;
use users::User; use posts::Post;
use schema::blogs; use schema::blogs;
use users::User;
pub type CustomGroup = CustomObject<ApSignature, Group>; pub type CustomGroup = CustomObject<ApSignature, Group>;
@ -273,6 +274,13 @@ impl Blog {
json["fqn"] = json!(self.get_fqn(conn)); json["fqn"] = json!(self.get_fqn(conn));
json 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 { impl IntoId for Blog {

View File

@ -434,6 +434,9 @@ msgstr ""
msgid "Delete this article" msgid "Delete this article"
msgstr "" msgstr ""
msgid "Delete this blog"
msgstr ""
msgid "And connected to" msgid "And connected to"
msgstr "" msgstr ""

View File

@ -445,6 +445,9 @@ msgstr "Lire les règles détaillées"
msgid "Delete this article" msgid "Delete this article"
msgstr "Supprimer cet article" msgstr "Supprimer cet article"
msgid "Delete this blog"
msgstr "Supprimer ce blog"
msgid "And connected to" msgid "And connected to"
msgstr "Et connectée à" msgstr "Et connectée à"

View File

@ -433,6 +433,9 @@ msgstr "Lea o detalle das normas"
msgid "Delete this article" msgid "Delete this article"
msgstr "Borrar este artigo" msgstr "Borrar este artigo"
msgid "Delete this blog"
msgstr "Borrar este blog"
msgid "And connected to" msgid "And connected to"
msgstr "E conectada a" msgstr "E conectada a"

View File

@ -442,6 +442,9 @@ msgstr "Les reglene"
msgid "Delete this article" msgid "Delete this article"
msgstr "Siste artikler" msgstr "Siste artikler"
msgid "Delete this blog"
msgstr ""
msgid "And connected to" msgid "And connected to"
msgstr "" msgstr ""

View File

@ -446,6 +446,9 @@ msgstr "Przeczytaj szczegółowe zasady"
msgid "Delete this article" msgid "Delete this article"
msgstr "Usuń ten artykuł" msgstr "Usuń ten artykuł"
msgid "Delete this blog"
msgstr ""
msgid "And connected to" msgid "And connected to"
msgstr "Połączony z" msgstr "Połączony z"

View File

@ -424,6 +424,9 @@ msgstr ""
msgid "Delete this article" msgid "Delete this article"
msgstr "" msgstr ""
msgid "Delete this blog"
msgstr ""
msgid "And connected to" msgid "And connected to"
msgstr "" msgstr ""

View File

@ -66,6 +66,7 @@ fn main() {
routes::blogs::new, routes::blogs::new,
routes::blogs::new_auth, routes::blogs::new_auth,
routes::blogs::create, routes::blogs::create,
routes::blogs::delete,
routes::blogs::atom_feed, routes::blogs::atom_feed,
routes::comments::create, routes::comments::create,

View File

@ -129,6 +129,19 @@ fn create(conn: DbConn, data: LenientForm<NewBlogForm>, user: User) -> Result<Re
} }
} }
#[post("/~/<name>/delete")]
fn delete(conn: DbConn, name: String, user: Option<User>) -> Result<Redirect, Option<Template>>{
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("/~/<name>/outbox")] #[get("/~/<name>/outbox")]
fn outbox(name: String, conn: DbConn) -> Option<ActivityStream<OrderedCollection>> { fn outbox(name: String, conn: DbConn) -> Option<ActivityStream<OrderedCollection>> {
let blog = Blog::find_local(&*conn, name)?; let blog = Blog::find_local(&*conn, name)?;

View File

@ -40,4 +40,11 @@
</div> </div>
{{ macros::paginate(page=page, total=n_pages) }} {{ macros::paginate(page=page, total=n_pages) }}
</section> </section>
{% if is_author %}
<h2>{{ "Danger zone" | _ }}</h2>
<p>{{ "Be very careful, any action taken here can't be cancelled." | _ }}
<form method="post" action="/~/{{ blog.fqn }}/delete">
<input type="submit" class="inline-block button destructive" value="{{ "Delete this blog" | _ }}">
</form>
{% endif %}
{% endblock content %} {% endblock content %}