From f1d5865a169c4efdb3526d9ccf697e2f70e701c8 Mon Sep 17 00:00:00 2001
From: Bat
Date: Sat, 8 Sep 2018 20:07:55 +0100
Subject: [PATCH] Instance (un)block endpoint
And hide the block button for the local instance
---
plume-models/src/instance.rs | 7 +++++--
src/main.rs | 1 +
src/routes/instance.rs | 9 +++++++++
templates/instance/list.html.tera | 16 +++++++++-------
4 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/plume-models/src/instance.rs b/plume-models/src/instance.rs
index 0697fae6..331ecca3 100644
--- a/plume-models/src/instance.rs
+++ b/plume-models/src/instance.rs
@@ -68,8 +68,11 @@ impl Instance {
get!(instances);
find_by!(instances, find_by_domain, public_domain as String);
- pub fn block(&self) {
- unimplemented!()
+ pub fn toggle_block(&self, conn: &PgConnection) {
+ diesel::update(self)
+ .set(instances::blocked.eq(!self.blocked))
+ .get_result::(conn)
+ .expect("Couldn't block/unblock instance");
}
pub fn has_admin(&self, conn: &PgConnection) -> bool {
diff --git a/src/main.rs b/src/main.rs
index 8491ebb2..05b5f734 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -65,6 +65,7 @@ fn main() {
routes::instance::admin,
routes::instance::admin_instances,
routes::instance::admin_instances_paginated,
+ routes::instance::toggle_block,
routes::instance::update_settings,
routes::instance::shared_inbox,
routes::instance::nodeinfo,
diff --git a/src/routes/instance.rs b/src/routes/instance.rs
index 1fa6f40b..ff580882 100644
--- a/src/routes/instance.rs
+++ b/src/routes/instance.rs
@@ -154,6 +154,15 @@ fn admin_instances_paginated(admin: Admin, conn: DbConn, page: Page) -> Template
}))
}
+#[get("/admin/instances//block")]
+fn toggle_block(admin: Admin, conn: DbConn, id: i32) -> Redirect {
+ if let Some(inst) = Instance::get(&*conn, id) {
+ inst.toggle_block(&*conn);
+ }
+
+ Redirect::to(uri!(admin_instances))
+}
+
#[post("/inbox", data = "")]
fn shared_inbox(conn: DbConn, data: String) -> String {
let act: serde_json::Value = serde_json::from_str(&data[..]).unwrap();
diff --git a/templates/instance/list.html.tera b/templates/instance/list.html.tera
index c534a7df..cabddcdb 100644
--- a/templates/instance/list.html.tera
+++ b/templates/instance/list.html.tera
@@ -17,13 +17,15 @@ Administration of {{ instance.name }}
{{ instance.name }}
{{ instance.public_domain }}
-
- {% if instance.blocked %}
- Unblock
- {% else %}
- Block
- {% endif %}
-
+ {% if not instance.local %}
+
+ {% if instance.blocked %}
+ Unblock
+ {% else %}
+ Block
+ {% endif %}
+
+ {% endif %}
{% endfor %}