Merge pull request #282 from Plume-org/blog-deletion
Add support for blog deletion
This commit is contained in:
commit
9187aefda0
@ -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<ApSignature, Group>;
|
||||
|
||||
@ -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 {
|
||||
|
3
po/en.po
3
po/en.po
@ -434,6 +434,9 @@ msgstr ""
|
||||
msgid "Delete this article"
|
||||
msgstr ""
|
||||
|
||||
msgid "Delete this blog"
|
||||
msgstr ""
|
||||
|
||||
msgid "And connected to"
|
||||
msgstr ""
|
||||
|
||||
|
3
po/fr.po
3
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 à"
|
||||
|
||||
|
3
po/gl.po
3
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"
|
||||
|
||||
|
3
po/nb.po
3
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 ""
|
||||
|
||||
|
3
po/pl.po
3
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"
|
||||
|
||||
|
@ -424,6 +424,9 @@ msgstr ""
|
||||
msgid "Delete this article"
|
||||
msgstr ""
|
||||
|
||||
msgid "Delete this blog"
|
||||
msgstr ""
|
||||
|
||||
msgid "And connected to"
|
||||
msgstr ""
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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")]
|
||||
fn outbox(name: String, conn: DbConn) -> Option<ActivityStream<OrderedCollection>> {
|
||||
let blog = Blog::find_local(&*conn, name)?;
|
||||
|
@ -40,4 +40,11 @@
|
||||
</div>
|
||||
{{ macros::paginate(page=page, total=n_pages) }}
|
||||
</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 %}
|
||||
|
Loading…
Reference in New Issue
Block a user