use actix_web::{web, web::Data};
use captcha::Captcha;
-use lemmy_api_common::{comment::*, community::*, person::*, post::*, site::*, websocket::*};
-use lemmy_utils::{ConnectionId, LemmyError};
+use lemmy_api_common::{
+ comment::*,
+ community::*,
+ person::*,
+ post::*,
+ private_message::*,
+ site::*,
+ websocket::*,
+};
+use lemmy_utils::{error::LemmyError, utils::check_slurs, ConnectionId};
use lemmy_websocket::{serialize_websocket_message, LemmyContext, UserOperation};
use serde::Deserialize;
mod post;
mod post_report;
mod private_message;
+mod private_message_report;
mod site;
mod websocket;
UserOperation::GetCaptcha => do_websocket_operation::<GetCaptcha>(context, id, op, data).await,
UserOperation::GetReplies => do_websocket_operation::<GetReplies>(context, id, op, data).await,
UserOperation::AddAdmin => do_websocket_operation::<AddAdmin>(context, id, op, data).await,
+ UserOperation::GetUnreadRegistrationApplicationCount => {
+ do_websocket_operation::<GetUnreadRegistrationApplicationCount>(context, id, op, data).await
+ }
+ UserOperation::ListRegistrationApplications => {
+ do_websocket_operation::<ListRegistrationApplications>(context, id, op, data).await
+ }
+ UserOperation::ApproveRegistrationApplication => {
+ do_websocket_operation::<ApproveRegistrationApplication>(context, id, op, data).await
+ }
UserOperation::BanPerson => do_websocket_operation::<BanPerson>(context, id, op, data).await,
+ UserOperation::GetBannedPersons => {
+ do_websocket_operation::<GetBannedPersons>(context, id, op, data).await
+ }
UserOperation::BlockPerson => {
do_websocket_operation::<BlockPerson>(context, id, op, data).await
}
UserOperation::MarkPersonMentionAsRead => {
do_websocket_operation::<MarkPersonMentionAsRead>(context, id, op, data).await
}
+ UserOperation::MarkCommentReplyAsRead => {
+ do_websocket_operation::<MarkCommentReplyAsRead>(context, id, op, data).await
+ }
UserOperation::MarkAllAsRead => {
do_websocket_operation::<MarkAllAsRead>(context, id, op, data).await
}
do_websocket_operation::<PasswordReset>(context, id, op, data).await
}
UserOperation::PasswordChange => {
- do_websocket_operation::<PasswordChange>(context, id, op, data).await
+ do_websocket_operation::<PasswordChangeAfterReset>(context, id, op, data).await
}
UserOperation::UserJoin => do_websocket_operation::<UserJoin>(context, id, op, data).await,
UserOperation::PostJoin => do_websocket_operation::<PostJoin>(context, id, op, data).await,
UserOperation::GetUnreadCount => {
do_websocket_operation::<GetUnreadCount>(context, id, op, data).await
}
+ UserOperation::VerifyEmail => {
+ do_websocket_operation::<VerifyEmail>(context, id, op, data).await
+ }
// Private Message ops
UserOperation::MarkPrivateMessageAsRead => {
do_websocket_operation::<MarkPrivateMessageAsRead>(context, id, op, data).await
}
+ UserOperation::CreatePrivateMessageReport => {
+ do_websocket_operation::<CreatePrivateMessageReport>(context, id, op, data).await
+ }
+ UserOperation::ResolvePrivateMessageReport => {
+ do_websocket_operation::<ResolvePrivateMessageReport>(context, id, op, data).await
+ }
+ UserOperation::ListPrivateMessageReports => {
+ do_websocket_operation::<ListPrivateMessageReports>(context, id, op, data).await
+ }
// Site ops
UserOperation::GetModlog => do_websocket_operation::<GetModlog>(context, id, op, data).await,
- UserOperation::GetSiteConfig => {
- do_websocket_operation::<GetSiteConfig>(context, id, op, data).await
+ UserOperation::PurgePerson => {
+ do_websocket_operation::<PurgePerson>(context, id, op, data).await
}
- UserOperation::SaveSiteConfig => {
- do_websocket_operation::<SaveSiteConfig>(context, id, op, data).await
+ UserOperation::PurgeCommunity => {
+ do_websocket_operation::<PurgeCommunity>(context, id, op, data).await
+ }
+ UserOperation::PurgePost => do_websocket_operation::<PurgePost>(context, id, op, data).await,
+ UserOperation::PurgeComment => {
+ do_websocket_operation::<PurgeComment>(context, id, op, data).await
}
UserOperation::Search => do_websocket_operation::<Search>(context, id, op, data).await,
UserOperation::ResolveObject => {
UserOperation::TransferCommunity => {
do_websocket_operation::<TransferCommunity>(context, id, op, data).await
}
- UserOperation::TransferSite => {
- do_websocket_operation::<TransferSite>(context, id, op, data).await
- }
+ UserOperation::LeaveAdmin => do_websocket_operation::<LeaveAdmin>(context, id, op, data).await,
// Community ops
UserOperation::FollowCommunity => {
UserOperation::CreatePostLike => {
do_websocket_operation::<CreatePostLike>(context, id, op, data).await
}
+ UserOperation::MarkPostAsRead => {
+ do_websocket_operation::<MarkPostAsRead>(context, id, op, data).await
+ }
UserOperation::SavePost => do_websocket_operation::<SavePost>(context, id, op, data).await,
UserOperation::CreatePostReport => {
do_websocket_operation::<CreatePostReport>(context, id, op, data).await
}
// Comment ops
- UserOperation::MarkCommentAsRead => {
- do_websocket_operation::<MarkCommentAsRead>(context, id, op, data).await
- }
UserOperation::SaveComment => {
do_websocket_operation::<SaveComment>(context, id, op, data).await
}
base64::encode(concat_letters)
}
+/// Check size of report and remove whitespace
+pub(crate) fn check_report_reason(reason: &str, context: &LemmyContext) -> Result<(), LemmyError> {
+ check_slurs(reason, &context.settings().slur_regex())?;
+ if reason.is_empty() {
+ return Err(LemmyError::from_message("report_reason_required"));
+ }
+ if reason.chars().count() > 1000 {
+ return Err(LemmyError::from_message("report_too_long"));
+ }
+ Ok(())
+}
+
#[cfg(test)]
mod tests {
- use lemmy_api_common::check_validator_time;
- use lemmy_db_queries::{
- establish_unpooled_connection,
- source::{local_user::LocalUser_, secret::Secret_},
- Crud,
- };
- use lemmy_db_schema::source::{
- local_user::{LocalUser, LocalUserForm},
- person::{Person, PersonForm},
- secret::Secret,
+ use lemmy_api_common::utils::check_validator_time;
+ use lemmy_db_schema::{
+ source::{
+ local_user::{LocalUser, LocalUserForm},
+ person::{Person, PersonForm},
+ secret::Secret,
+ },
+ traits::Crud,
+ utils::establish_unpooled_connection,
};
- use lemmy_utils::{claims::Claims, settings::structs::Settings};
+ use lemmy_utils::{claims::Claims, settings::SETTINGS};
#[test]
fn test_should_not_validate_user_token_after_password_change() {
let conn = establish_unpooled_connection();
let secret = Secret::init(&conn).unwrap();
- let settings = Settings::init().unwrap();
+ let settings = &SETTINGS.to_owned();
let new_person = PersonForm {
name: "Gerry9812".into(),
+ public_key: Some("pubkey".to_string()),
..PersonForm::default()
};
let inserted_person = Person::create(&conn, &new_person).unwrap();
let local_user_form = LocalUserForm {
- person_id: inserted_person.id,
- password_encrypted: "123456".to_string(),
+ person_id: Some(inserted_person.id),
+ password_encrypted: Some("123456".to_string()),
..LocalUserForm::default()
};