Instance (un)block endpoint

And hide the block button for the local instance
This commit is contained in:
Bat 2018-09-08 20:07:55 +01:00
parent c1e0b6c306
commit f1d5865a16
4 changed files with 24 additions and 9 deletions

View File

@ -68,8 +68,11 @@ impl Instance {
get!(instances); get!(instances);
find_by!(instances, find_by_domain, public_domain as String); find_by!(instances, find_by_domain, public_domain as String);
pub fn block(&self) { pub fn toggle_block(&self, conn: &PgConnection) {
unimplemented!() diesel::update(self)
.set(instances::blocked.eq(!self.blocked))
.get_result::<Instance>(conn)
.expect("Couldn't block/unblock instance");
} }
pub fn has_admin(&self, conn: &PgConnection) -> bool { pub fn has_admin(&self, conn: &PgConnection) -> bool {

View File

@ -65,6 +65,7 @@ fn main() {
routes::instance::admin, routes::instance::admin,
routes::instance::admin_instances, routes::instance::admin_instances,
routes::instance::admin_instances_paginated, routes::instance::admin_instances_paginated,
routes::instance::toggle_block,
routes::instance::update_settings, routes::instance::update_settings,
routes::instance::shared_inbox, routes::instance::shared_inbox,
routes::instance::nodeinfo, routes::instance::nodeinfo,

View File

@ -154,6 +154,15 @@ fn admin_instances_paginated(admin: Admin, conn: DbConn, page: Page) -> Template
})) }))
} }
#[get("/admin/instances/<id>/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 = "<data>")] #[post("/inbox", data = "<data>")]
fn shared_inbox(conn: DbConn, data: String) -> String { fn shared_inbox(conn: DbConn, data: String) -> String {
let act: serde_json::Value = serde_json::from_str(&data[..]).unwrap(); let act: serde_json::Value = serde_json::from_str(&data[..]).unwrap();

View File

@ -17,13 +17,15 @@ Administration of {{ instance.name }}
<a href="https://{{ instance.public_domain }}">{{ instance.name }}</a> <a href="https://{{ instance.public_domain }}">{{ instance.name }}</a>
<small>{{ instance.public_domain }}</small> <small>{{ instance.public_domain }}</small>
</p> </p>
<a href="/admin/instances/{{ instance.id }}/block"> {% if not instance.local %}
{% if instance.blocked %} <a href="/admin/instances/{{ instance.id }}/block">
Unblock {% if instance.blocked %}
{% else %} Unblock
Block {% else %}
{% endif %} Block
</a> {% endif %}
</a>
{% endif %}
</div> </div>
{% endfor %} {% endfor %}
</div> </div>