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);
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::<Instance>(conn)
.expect("Couldn't block/unblock instance");
}
pub fn has_admin(&self, conn: &PgConnection) -> bool {

View file

@ -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,

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>")]
fn shared_inbox(conn: DbConn, data: String) -> String {
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>
<small>{{ instance.public_domain }}</small>
</p>
<a href="/admin/instances/{{ instance.id }}/block">
{% if instance.blocked %}
Unblock
{% else %}
Block
{% endif %}
</a>
{% if not instance.local %}
<a href="/admin/instances/{{ instance.id }}/block">
{% if instance.blocked %}
Unblock
{% else %}
Block
{% endif %}
</a>
{% endif %}
</div>
{% endfor %}
</div>