You've already forked AstralRinth
Initial work on site moderation improvements (#410)
This commit is contained in:
@@ -2,7 +2,7 @@ use super::ApiError;
|
||||
use crate::database;
|
||||
use crate::models::projects::ProjectStatus;
|
||||
use crate::util::auth::check_is_moderator_from_headers;
|
||||
use actix_web::{get, web, HttpRequest, HttpResponse};
|
||||
use actix_web::{delete, get, web, HttpRequest, HttpResponse};
|
||||
use serde::Deserialize;
|
||||
use sqlx::PgPool;
|
||||
|
||||
@@ -54,3 +54,38 @@ pub async fn get_projects(
|
||||
|
||||
Ok(HttpResponse::Ok().json(projects))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct BanUser {
|
||||
pub id: i64,
|
||||
}
|
||||
|
||||
#[get("ban")]
|
||||
pub async fn ban_user(
|
||||
req: HttpRequest,
|
||||
pool: web::Data<PgPool>,
|
||||
id: web::Query<BanUser>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
check_is_moderator_from_headers(req.headers(), &**pool).await?;
|
||||
|
||||
sqlx::query!("INSERT INTO banned_users (github_id) VALUES ($1);", id.id)
|
||||
.execute(&**pool)
|
||||
.await?;
|
||||
|
||||
Ok(HttpResponse::NoContent().body(""))
|
||||
}
|
||||
|
||||
#[delete("ban")]
|
||||
pub async fn unban_user(
|
||||
req: HttpRequest,
|
||||
pool: web::Data<PgPool>,
|
||||
id: web::Query<BanUser>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
check_is_moderator_from_headers(req.headers(), &**pool).await?;
|
||||
|
||||
sqlx::query!("DELETE FROM banned_users WHERE github_id = $1;", id.id)
|
||||
.execute(&**pool)
|
||||
.await?;
|
||||
|
||||
Ok(HttpResponse::NoContent().body(""))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user