Implement user ban
This commit is contained in:
parent
2f53cb9122
commit
1f2bd105b6
|
@ -100,6 +100,10 @@ impl User {
|
||||||
find_by!(users, find_by_name, username as String, instance_id as i32);
|
find_by!(users, find_by_name, username as String, instance_id as i32);
|
||||||
find_by!(users, find_by_ap_url, ap_url as String);
|
find_by!(users, find_by_ap_url, ap_url as String);
|
||||||
|
|
||||||
|
pub fn delete(&self, conn: &PgConnection) {
|
||||||
|
diesel::delete(self).execute(conn).expect("Couldn't remove user from DB");
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_instance(&self, conn: &PgConnection) -> Instance {
|
pub fn get_instance(&self, conn: &PgConnection) -> Instance {
|
||||||
Instance::get(conn, self.instance_id).expect("Couldn't find instance")
|
Instance::get(conn, self.instance_id).expect("Couldn't find instance")
|
||||||
}
|
}
|
||||||
|
@ -297,6 +301,15 @@ impl User {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_local_page(conn: &PgConnection, (min, max): (i32, i32)) -> Vec<User> {
|
||||||
|
users::table.filter(users::instance_id.eq(1))
|
||||||
|
.order(users::username.asc())
|
||||||
|
.offset(min.into())
|
||||||
|
.limit((max - min).into())
|
||||||
|
.load::<User>(conn)
|
||||||
|
.expect("Error getting local users page")
|
||||||
|
}
|
||||||
|
|
||||||
pub fn outbox(&self, conn: &PgConnection) -> ActivityStream<OrderedCollection> {
|
pub fn outbox(&self, conn: &PgConnection) -> ActivityStream<OrderedCollection> {
|
||||||
let acts = self.get_activities(conn);
|
let acts = self.get_activities(conn);
|
||||||
let n_acts = acts.len();
|
let n_acts = acts.len();
|
||||||
|
|
|
@ -66,6 +66,9 @@ 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::admin_users,
|
||||||
|
routes::instance::admin_users_paginated,
|
||||||
|
routes::instance::ban,
|
||||||
routes::instance::toggle_block,
|
routes::instance::toggle_block,
|
||||||
routes::instance::update_settings,
|
routes::instance::update_settings,
|
||||||
routes::instance::shared_inbox,
|
routes::instance::shared_inbox,
|
||||||
|
|
|
@ -163,6 +163,30 @@ fn toggle_block(_admin: Admin, conn: DbConn, id: i32) -> Redirect {
|
||||||
Redirect::to(uri!(admin_instances))
|
Redirect::to(uri!(admin_instances))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[get("/admin/users")]
|
||||||
|
fn admin_users(admin: Admin, conn: DbConn) -> Template {
|
||||||
|
admin_users_paginated(admin, conn, Page::first())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/admin/users?<page>")]
|
||||||
|
fn admin_users_paginated(admin: Admin, conn: DbConn, page: Page) -> Template {
|
||||||
|
let users = User::get_local_page(&*conn, page.limits()).into_iter()
|
||||||
|
.map(|u| u.to_json(&*conn)).collect::<Vec<serde_json::Value>>();
|
||||||
|
|
||||||
|
Template::render("instance/users", json!({
|
||||||
|
"account": admin.0.to_json(&*conn),
|
||||||
|
"users": users,
|
||||||
|
"page": page.page,
|
||||||
|
"n_pages": Page::total(User::count_local(&*conn) as i32)
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/admin/users/<id>/ban")]
|
||||||
|
fn ban(_admin: Admin, conn: DbConn, id: i32) -> Redirect {
|
||||||
|
User::get(&*conn, id).map(|u| u.delete(&*conn));
|
||||||
|
Redirect::to(uri!(admin_users))
|
||||||
|
}
|
||||||
|
|
||||||
#[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();
|
||||||
|
|
|
@ -8,7 +8,7 @@ Administration of {{ instance.name }}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>{{ "Administration" | _ }}</h1>
|
<h1>{{ "Administration" | _ }}</h1>
|
||||||
|
|
||||||
{{ macros::tabs(links=['/admin', '/admin/instances'], titles=['Configuration', 'Instances'], selected=1) }}
|
{{ macros::tabs(links=['/admin', '/admin/instances', '/admin/users'], titles=['Configuration', 'Instances', 'Users'], selected=1) }}
|
||||||
|
|
||||||
<form method="post">
|
<form method="post">
|
||||||
{{ macros::input(name="name", label="Name", errors=errors, form=form, props='minlenght="1"', default=instance) }}
|
{{ macros::input(name="name", label="Name", errors=errors, form=form, props='minlenght="1"', default=instance) }}
|
||||||
|
|
|
@ -8,7 +8,7 @@ Administration of {{ instance.name }}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>{{ "Instances" | _ }}</h1>
|
<h1>{{ "Instances" | _ }}</h1>
|
||||||
|
|
||||||
{{ macros::tabs(links=['/admin', '/admin/instances'], titles=['Configuration', 'Instances'], selected=2) }}
|
{{ macros::tabs(links=['/admin', '/admin/instances', '/admin/users'], titles=['Configuration', 'Instances', 'Users'], selected=2) }}
|
||||||
|
|
||||||
<div class="list">
|
<div class="list">
|
||||||
{% for instance in instances %}
|
{% for instance in instances %}
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
{% extends "base" %}
|
||||||
|
{% import "macros" as macros %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
Users
|
||||||
|
{% endblock title %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h1>{{ "Users" | _ }}</h1>
|
||||||
|
|
||||||
|
{{ macros::tabs(links=['/admin', '/admin/instances', '/admin/users'], titles=['Configuration', 'Instances', 'Users'], selected=3) }}
|
||||||
|
|
||||||
|
<div class="list">
|
||||||
|
{% for user in users %}
|
||||||
|
<div class="flex">
|
||||||
|
<img src="{{ user.avatar }}" class="avatar small" alt="{{ user.name }}">
|
||||||
|
<p class="grow">
|
||||||
|
<a href="/@/{{ user.fqn }}">{{ user.name }}</a>
|
||||||
|
<small>@{{ user.username }}</small>
|
||||||
|
</p>
|
||||||
|
{% if not user.is_admin %}
|
||||||
|
<a href="/admin/users/{{ user.id }}/ban">
|
||||||
|
Ban
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{{ macros::paginate(page=page, total=n_pages) }}
|
||||||
|
{% endblock content %}
|
Loading…
Reference in New Issue