Add admin interface to manage interface
This commit is contained in:
parent
6c80002e43
commit
c1e0b6c306
@ -52,6 +52,14 @@ impl Instance {
|
||||
.expect("Error loading remote instances infos")
|
||||
}
|
||||
|
||||
pub fn page(conn: &PgConnection, (min, max): (i32, i32)) -> Vec<Instance> {
|
||||
instances::table.order(instances::public_domain.asc())
|
||||
.offset(min.into())
|
||||
.limit((max - min).into())
|
||||
.load::<Instance>(conn)
|
||||
.expect("Error loading a page of instances")
|
||||
}
|
||||
|
||||
pub fn local_id(conn: &PgConnection) -> i32 {
|
||||
Instance::get_local(conn).unwrap().id
|
||||
}
|
||||
|
@ -63,6 +63,8 @@ fn main() {
|
||||
routes::instance::paginated_federated,
|
||||
routes::instance::federated,
|
||||
routes::instance::admin,
|
||||
routes::instance::admin_instances,
|
||||
routes::instance::admin_instances_paginated,
|
||||
routes::instance::update_settings,
|
||||
routes::instance::shared_inbox,
|
||||
routes::instance::nodeinfo,
|
||||
|
@ -137,6 +137,23 @@ fn update_settings(conn: DbConn, admin: Admin, form: LenientForm<InstanceSetting
|
||||
})))
|
||||
}
|
||||
|
||||
#[get("/admin/instances")]
|
||||
fn admin_instances(admin: Admin, conn: DbConn) -> Template {
|
||||
admin_instances_paginated(admin, conn, Page::first())
|
||||
}
|
||||
|
||||
#[get("/admin/instances?<page>")]
|
||||
fn admin_instances_paginated(admin: Admin, conn: DbConn, page: Page) -> Template {
|
||||
let instances = Instance::page(&*conn, page.limits());
|
||||
Template::render("instance/list", json!({
|
||||
"account": admin.0.to_json(&*conn),
|
||||
"instances": instances,
|
||||
"instance": Instance::get_local(&*conn),
|
||||
"page": page.page,
|
||||
"n_pages": Page::total(Instance::count(&*conn) as i32),
|
||||
}))
|
||||
}
|
||||
|
||||
#[post("/inbox", data = "<data>")]
|
||||
fn shared_inbox(conn: DbConn, data: String) -> String {
|
||||
let act: serde_json::Value = serde_json::from_str(&data[..]).unwrap();
|
||||
|
@ -8,7 +8,8 @@ Administration of {{ instance.name }}
|
||||
{% block content %}
|
||||
<h1>{{ "Administration" | _ }}</h1>
|
||||
|
||||
<h2>{{ "Instance settings" | _ }}</h2>
|
||||
{{ macros::tabs(links=['/admin', '/admin/instances'], titles=['Configuration', 'Instances'], selected=1) }}
|
||||
|
||||
<form method="post">
|
||||
{{ macros::input(name="name", label="Name", errors=errors, form=form, props='minlenght="1"', default=instance) }}
|
||||
|
||||
|
31
templates/instance/list.html.tera
Normal file
31
templates/instance/list.html.tera
Normal file
@ -0,0 +1,31 @@
|
||||
{% extends "base" %}
|
||||
{% import "macros" as macros %}
|
||||
|
||||
{% block title %}
|
||||
Administration of {{ instance.name }}
|
||||
{% endblock title %}
|
||||
|
||||
{% block content %}
|
||||
<h1>{{ "Instances" | _ }}</h1>
|
||||
|
||||
{{ macros::tabs(links=['/admin', '/admin/instances'], titles=['Configuration', 'Instances'], selected=2) }}
|
||||
|
||||
<div class="list">
|
||||
{% for instance in instances %}
|
||||
<div class="flex">
|
||||
<p class="grow">
|
||||
<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>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{{ macros::paginate(page=page, total=n_pages) }}
|
||||
{% endblock content %}
|
Loading…
Reference in New Issue
Block a user