Admin edit comment

This commit is contained in:
Pascal Engélibert 2022-10-22 17:56:24 +02:00
commit dd6b8c76ba
Signed by: tuxmain
GPG key ID: 3504BC6D362F7DCA
6 changed files with 204 additions and 76 deletions

View file

@ -1,4 +1,4 @@
use crate::{config::Config, db::*};
use crate::{config::Config, db::*, queries::*};
use log::error;
use std::{net::IpAddr, str::FromStr};
@ -30,13 +30,18 @@ pub fn approve_comment(comment_id: CommentId, dbs: &Dbs) -> Result<(), sled::Err
Ok(())
}
pub fn remove_pending_comment(
comment_id: CommentId,
dbs: &Dbs,
) -> Result<Option<Comment>, sled::Error> {
pub fn remove_comment(comment_id: CommentId, dbs: &Dbs) -> Result<Option<Comment>, sled::Error> {
if let Some(comment) = dbs.comment.remove(&comment_id)? {
dbs.comment_pending
.remove(&(comment.topic_hash.clone(), comment.post_time, comment_id))?;
dbs.comment_pending.remove(&(
comment.topic_hash.clone(),
comment.post_time,
comment_id.clone(),
))?;
dbs.comment_approved.remove(&(
comment.topic_hash.clone(),
comment.post_time,
comment_id,
))?;
return Ok(Some(comment));
}
Ok(None)
@ -163,6 +168,30 @@ pub fn get_client_addr<State>(
))
}
pub fn check_comment(config: &Config, comment: &CommentForm, errors: &mut Vec<String>) {
if comment.author.len() > config.comment_author_max_len {
errors.push(format!(
"Author name length is {} but maximum is {}.",
comment.author.len(),
config.comment_author_max_len
));
}
if comment.email.len() > config.comment_email_max_len {
errors.push(format!(
"E-mail length is {} but maximum is {}.",
comment.email.len(),
config.comment_email_max_len
));
}
if comment.text.len() > config.comment_text_max_len {
errors.push(format!(
"Comment length is {} but maximum is {}.",
comment.text.len(),
config.comment_text_max_len
));
}
}
#[cfg(test)]
mod test {
use super::*;