Možnost odvolat ban
Tento commit je obsažen v:
rodič
e5539b870c
revize
8a73452cc0
80
src/error.rs
80
src/error.rs
@ -22,7 +22,7 @@ pub enum NekrochanError {
|
|||||||
CapcodeFormatError,
|
CapcodeFormatError,
|
||||||
#[error("E-mail nesmí mít více než 256 znaků.")]
|
#[error("E-mail nesmí mít více než 256 znaků.")]
|
||||||
EmailFormatError,
|
EmailFormatError,
|
||||||
#[error("Obsah nesmí mít více než 4000 znaků")]
|
#[error("Obsah nesmí mít více než 10000 znaků.")]
|
||||||
ContentFormatError,
|
ContentFormatError,
|
||||||
#[error("Nástěnka /{}/ neexistuje.", .0)]
|
#[error("Nástěnka /{}/ neexistuje.", .0)]
|
||||||
BoardNotFound(String),
|
BoardNotFound(String),
|
||||||
@ -30,6 +30,8 @@ pub enum NekrochanError {
|
|||||||
AccountNotFound(String),
|
AccountNotFound(String),
|
||||||
#[error("Příspěvek /{}/{} neexistuje.", .0, .1)]
|
#[error("Příspěvek /{}/{} neexistuje.", .0, .1)]
|
||||||
PostNotFound(String, i32),
|
PostNotFound(String, i32),
|
||||||
|
#[error("Žádný takový ban pro tuto IP adresu neexistuje.")]
|
||||||
|
BanNotFound,
|
||||||
#[error("Nedostatečná oprávnění.")]
|
#[error("Nedostatečná oprávnění.")]
|
||||||
InsufficientPermissionError,
|
InsufficientPermissionError,
|
||||||
#[error("Nesprávné přihlašovací údaje.")]
|
#[error("Nesprávné přihlašovací údaje.")]
|
||||||
@ -70,6 +72,10 @@ pub enum NekrochanError {
|
|||||||
FileLimitError(usize),
|
FileLimitError(usize),
|
||||||
#[error("Nesprávné heslo pro příspěvek #{}.", .0)]
|
#[error("Nesprávné heslo pro příspěvek #{}.", .0)]
|
||||||
IncorrectPasswordError(i32),
|
IncorrectPasswordError(i32),
|
||||||
|
#[error("Tento ban už byl odvolán.")]
|
||||||
|
AlreadyAppealedError,
|
||||||
|
#[error("Tento ban nelze odvolat.")]
|
||||||
|
UnappealableError,
|
||||||
// 500
|
// 500
|
||||||
#[error("Nadnástěnka nebyla inicializována.")]
|
#[error("Nadnástěnka nebyla inicializována.")]
|
||||||
OverboardError,
|
OverboardError,
|
||||||
@ -193,41 +199,45 @@ impl From<tokio::task::JoinError> for NekrochanError {
|
|||||||
impl ResponseError for NekrochanError {
|
impl ResponseError for NekrochanError {
|
||||||
fn status_code(&self) -> StatusCode {
|
fn status_code(&self) -> StatusCode {
|
||||||
match self {
|
match self {
|
||||||
NekrochanError::FileError(_, _) => StatusCode::BAD_REQUEST,
|
NekrochanError::FileError(_, _)
|
||||||
NekrochanError::UsernameFormatError => StatusCode::BAD_REQUEST,
|
| NekrochanError::UsernameFormatError
|
||||||
NekrochanError::PasswordFormatError => StatusCode::BAD_REQUEST,
|
| NekrochanError::PasswordFormatError
|
||||||
NekrochanError::IdFormatError => StatusCode::BAD_REQUEST,
|
| NekrochanError::IdFormatError
|
||||||
NekrochanError::BoardNameFormatError => StatusCode::BAD_REQUEST,
|
| NekrochanError::BoardNameFormatError
|
||||||
NekrochanError::DescriptionFormatError => StatusCode::BAD_REQUEST,
|
| NekrochanError::DescriptionFormatError
|
||||||
NekrochanError::PostNameFormatError => StatusCode::BAD_REQUEST,
|
| NekrochanError::PostNameFormatError
|
||||||
NekrochanError::CapcodeFormatError => StatusCode::BAD_REQUEST,
|
| NekrochanError::CapcodeFormatError
|
||||||
NekrochanError::EmailFormatError => StatusCode::BAD_REQUEST,
|
| NekrochanError::EmailFormatError
|
||||||
NekrochanError::ContentFormatError => StatusCode::BAD_REQUEST,
|
| NekrochanError::ContentFormatError
|
||||||
NekrochanError::BoardNotFound(_) => StatusCode::NOT_FOUND,
|
| NekrochanError::ReplyReplyError
|
||||||
NekrochanError::AccountNotFound(_) => StatusCode::NOT_FOUND,
|
| NekrochanError::NoContentError
|
||||||
NekrochanError::PostNotFound(_, _) => StatusCode::NOT_FOUND,
|
| NekrochanError::NoFileError
|
||||||
NekrochanError::InsufficientPermissionError => StatusCode::FORBIDDEN,
|
| NekrochanError::EmptyPostError
|
||||||
NekrochanError::IncorrectCredentialError => StatusCode::UNAUTHORIZED,
|
| NekrochanError::RequiredCaptchaError
|
||||||
NekrochanError::InvalidPageError => StatusCode::NOT_FOUND,
|
| NekrochanError::SolvedCaptchaError
|
||||||
NekrochanError::InvalidAuthError => StatusCode::NOT_FOUND,
|
| NekrochanError::NoPostsError
|
||||||
NekrochanError::NotLoggedInError => StatusCode::UNAUTHORIZED,
|
| NekrochanError::FileLimitError(_)
|
||||||
NekrochanError::OwnerDeletionError => StatusCode::FORBIDDEN,
|
| NekrochanError::AlreadyAppealedError
|
||||||
|
| NekrochanError::UnappealableError => StatusCode::BAD_REQUEST,
|
||||||
|
NekrochanError::BoardNotFound(_)
|
||||||
|
| NekrochanError::AccountNotFound(_)
|
||||||
|
| NekrochanError::PostNotFound(_, _)
|
||||||
|
| NekrochanError::BanNotFound
|
||||||
|
| NekrochanError::InvalidPageError
|
||||||
|
| NekrochanError::InvalidAuthError => StatusCode::NOT_FOUND,
|
||||||
|
NekrochanError::InsufficientPermissionError
|
||||||
|
| NekrochanError::ReplyLimitError
|
||||||
|
| NekrochanError::ThreadLockError
|
||||||
|
| NekrochanError::BoardLockError(_)
|
||||||
|
| NekrochanError::OwnerDeletionError => StatusCode::FORBIDDEN,
|
||||||
|
NekrochanError::IncorrectCredentialError
|
||||||
|
| NekrochanError::NotLoggedInError
|
||||||
|
| NekrochanError::IncorrectCaptchaError
|
||||||
|
| NekrochanError::IncorrectPasswordError(_) => StatusCode::UNAUTHORIZED,
|
||||||
NekrochanError::HeaderError(_) => StatusCode::BAD_GATEWAY,
|
NekrochanError::HeaderError(_) => StatusCode::BAD_GATEWAY,
|
||||||
NekrochanError::BoardLockError(_) => StatusCode::FORBIDDEN,
|
NekrochanError::OverboardError | NekrochanError::InternalError => {
|
||||||
NekrochanError::ThreadLockError => StatusCode::FORBIDDEN,
|
StatusCode::INTERNAL_SERVER_ERROR
|
||||||
NekrochanError::ReplyReplyError => StatusCode::BAD_REQUEST,
|
}
|
||||||
NekrochanError::ReplyLimitError => StatusCode::FORBIDDEN,
|
|
||||||
NekrochanError::NoContentError => StatusCode::BAD_REQUEST,
|
|
||||||
NekrochanError::NoFileError => StatusCode::BAD_REQUEST,
|
|
||||||
NekrochanError::EmptyPostError => StatusCode::BAD_REQUEST,
|
|
||||||
NekrochanError::RequiredCaptchaError => StatusCode::BAD_REQUEST,
|
|
||||||
NekrochanError::IncorrectCaptchaError => StatusCode::UNAUTHORIZED,
|
|
||||||
NekrochanError::SolvedCaptchaError => StatusCode::BAD_REQUEST,
|
|
||||||
NekrochanError::NoPostsError => StatusCode::BAD_REQUEST,
|
|
||||||
NekrochanError::FileLimitError(_) => StatusCode::BAD_REQUEST,
|
|
||||||
NekrochanError::IncorrectPasswordError(_) => StatusCode::UNAUTHORIZED,
|
|
||||||
NekrochanError::OverboardError => StatusCode::INTERNAL_SERVER_ERROR,
|
|
||||||
NekrochanError::InternalError => StatusCode::INTERNAL_SERVER_ERROR,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,6 +71,7 @@ async fn run() -> Result<(), Error> {
|
|||||||
.service(web::actions::user_post_actions::user_post_actions)
|
.service(web::actions::user_post_actions::user_post_actions)
|
||||||
.service(web::actions::staff_post_actions::staff_post_actions)
|
.service(web::actions::staff_post_actions::staff_post_actions)
|
||||||
.service(web::actions::report_posts::report_posts)
|
.service(web::actions::report_posts::report_posts)
|
||||||
|
.service(web::actions::appeal_ban::appeal_ban)
|
||||||
.service(web::login::login_get)
|
.service(web::login::login_get)
|
||||||
.service(web::login::login_post)
|
.service(web::login::login_post)
|
||||||
.service(web::logout::logout)
|
.service(web::logout::logout)
|
||||||
|
54
src/web/actions/appeal_ban.rs
Normální soubor
54
src/web/actions/appeal_ban.rs
Normální soubor
@ -0,0 +1,54 @@
|
|||||||
|
use actix_web::{post, web::Data, HttpRequest, HttpResponse};
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
use super::ActionTemplate;
|
||||||
|
use crate::{
|
||||||
|
ctx::Ctx,
|
||||||
|
db::models::Ban,
|
||||||
|
error::NekrochanError,
|
||||||
|
qsform::QsForm,
|
||||||
|
web::{
|
||||||
|
tcx::{ip_from_req, TemplateCtx},
|
||||||
|
template_response,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct AppealBanForm {
|
||||||
|
pub id: i32,
|
||||||
|
pub appeal: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[post("/actions/appeal-ban")]
|
||||||
|
pub async fn appeal_ban(
|
||||||
|
ctx: Data<Ctx>,
|
||||||
|
req: HttpRequest,
|
||||||
|
QsForm(form): QsForm<AppealBanForm>,
|
||||||
|
) -> Result<HttpResponse, NekrochanError> {
|
||||||
|
let tcx = TemplateCtx::new(&ctx, &req).await?;
|
||||||
|
let (ip, _) = ip_from_req(&req)?;
|
||||||
|
|
||||||
|
let ban = Ban::read_by_id(&ctx, form.id)
|
||||||
|
.await?
|
||||||
|
.ok_or(NekrochanError::BanNotFound)?;
|
||||||
|
|
||||||
|
if !ban.ip_range.contains(ip) {
|
||||||
|
return Err(NekrochanError::BanNotFound);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ban.appeal.is_some() {
|
||||||
|
return Err(NekrochanError::AlreadyAppealedError);
|
||||||
|
}
|
||||||
|
|
||||||
|
if !ban.appealable {
|
||||||
|
return Err(NekrochanError::UnappealableError);
|
||||||
|
}
|
||||||
|
|
||||||
|
let appeal = form.appeal.trim().into();
|
||||||
|
ban.update_appeal(&ctx, appeal).await?;
|
||||||
|
|
||||||
|
template_response(&ActionTemplate {
|
||||||
|
tcx,
|
||||||
|
response: "Ban byl úspěšně odvolán.".into(),
|
||||||
|
})
|
||||||
|
}
|
@ -159,7 +159,7 @@ pub async fn create_post(
|
|||||||
return Err(NekrochanError::NoContentError);
|
return Err(NekrochanError::NoContentError);
|
||||||
}
|
}
|
||||||
|
|
||||||
if content_nomarkup.len() > 4000 {
|
if content_nomarkup.len() > 10000 {
|
||||||
return Err(NekrochanError::ContentFormatError);
|
return Err(NekrochanError::ContentFormatError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ use super::tcx::TemplateCtx;
|
|||||||
use crate::{ctx::Ctx, db::models::Post};
|
use crate::{ctx::Ctx, db::models::Post};
|
||||||
|
|
||||||
pub mod create_post;
|
pub mod create_post;
|
||||||
|
pub mod appeal_ban;
|
||||||
pub mod report_posts;
|
pub mod report_posts;
|
||||||
pub mod staff_post_actions;
|
pub mod staff_post_actions;
|
||||||
pub mod user_post_actions;
|
pub mod user_post_actions;
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
{% else %}
|
{% else %}
|
||||||
<b>Můžeš se pokusit svůj ban odvolat:</b>
|
<b>Můžeš se pokusit svůj ban odvolat:</b>
|
||||||
<form method="post" action="/actions/appeal-ban">
|
<form method="post" action="/actions/appeal-ban">
|
||||||
|
<input name="id" type="hidden" value="{{ ban.id }}" />
|
||||||
<table class="form-table">
|
<table class="form-table">
|
||||||
<tr>
|
<tr>
|
||||||
<td class="label">Odvolání</td>
|
<td class="label">Odvolání</td>
|
||||||
|
Načítá se…
Odkázat v novém úkolu
Zablokovat Uživatele