"eslint": "^8.25.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^27.0.6",
- "lemmy-js-client": "0.17.0-rc.61",
+ "lemmy-js-client": "0.17.2-rc.1",
"node-fetch": "^2.6.1",
"prettier": "^2.7.1",
"ts-jest": "^27.0.3",
use lemmy_api_common::{
comment::{CommentReportResponse, CreateCommentReport},
context::LemmyContext,
- utils::{check_community_ban, get_local_user_view_from_jwt},
+ utils::{check_community_ban, get_local_user_view_from_jwt, send_new_report_email_to_admins},
websocket::UserOperation,
};
use lemmy_db_schema::{
let comment_report_view = CommentReportView::read(context.pool(), report.id, person_id).await?;
+ // Email the admins
+ if local_site.reports_email_admins {
+ send_new_report_email_to_admins(
+ &comment_report_view.creator.name,
+ &comment_report_view.comment_creator.name,
+ context.pool(),
+ context.settings(),
+ )
+ .await?;
+ }
+
let res = CommentReportResponse {
comment_report_view,
};
use lemmy_api_common::{
context::LemmyContext,
post::{CreatePostReport, PostReportResponse},
- utils::{check_community_ban, get_local_user_view_from_jwt},
+ utils::{check_community_ban, get_local_user_view_from_jwt, send_new_report_email_to_admins},
websocket::UserOperation,
};
use lemmy_db_schema::{
let post_report_view = PostReportView::read(context.pool(), report.id, person_id).await?;
+ // Email the admins
+ if local_site.reports_email_admins {
+ send_new_report_email_to_admins(
+ &post_report_view.creator.name,
+ &post_report_view.post_creator.name,
+ context.pool(),
+ context.settings(),
+ )
+ .await?;
+ }
+
let res = PostReportResponse { post_report_view };
context
use lemmy_api_common::{
context::LemmyContext,
private_message::{CreatePrivateMessageReport, PrivateMessageReportResponse},
- utils::get_local_user_view_from_jwt,
+ utils::{get_local_user_view_from_jwt, send_new_report_email_to_admins},
websocket::UserOperation,
};
use lemmy_db_schema::{
let private_message_report_view =
PrivateMessageReportView::read(context.pool(), report.id).await?;
+ // Email the admins
+ if local_site.reports_email_admins {
+ send_new_report_email_to_admins(
+ &private_message_report_view.creator.name,
+ &private_message_report_view.private_message_creator.name,
+ context.pool(),
+ context.settings(),
+ )
+ .await?;
+ }
+
let res = PrivateMessageReportResponse {
private_message_report_view,
};
pub blocked_instances: Option<Vec<String>>,
pub taglines: Option<Vec<String>>,
pub registration_mode: Option<RegistrationMode>,
+ pub reports_email_admins: Option<bool>,
pub auth: Sensitive<String>,
}
Ok(())
}
+/// Send a report to all admins
+pub async fn send_new_report_email_to_admins(
+ reporter_username: &str,
+ reported_username: &str,
+ pool: &DbPool,
+ settings: &Settings,
+) -> Result<(), LemmyError> {
+ // Collect the admins with emails
+ let admins = LocalUserSettingsView::list_admins_with_emails(pool).await?;
+
+ let reports_link = &format!("{}/reports", settings.get_protocol_and_hostname(),);
+
+ for admin in &admins {
+ let email = &admin.local_user.email.clone().expect("email");
+ let lang = get_interface_language_from_settings(admin);
+ let subject = lang.new_report_subject(&settings.hostname, reporter_username, reported_username);
+ let body = lang.new_report_body(reports_link);
+ send_email(&subject, email, &admin.person.name, &body, settings)?;
+ }
+ Ok(())
+}
+
pub async fn check_registration_application(
local_user_view: &LocalUserView,
local_site: &LocalSite,
.federation_worker_count(data.federation_worker_count)
.captcha_enabled(data.captcha_enabled)
.captcha_difficulty(data.captcha_difficulty.clone())
+ .reports_email_admins(data.reports_email_admins)
.build();
let update_local_site = LocalSite::update(context.pool(), &local_site_form)
captcha_enabled -> Bool,
captcha_difficulty -> Text,
registration_mode -> RegistrationModeType,
+ reports_email_admins -> Bool,
published -> Timestamp,
updated -> Nullable<Timestamp>,
}
pub captcha_enabled: bool,
pub captcha_difficulty: String,
pub registration_mode: RegistrationMode,
+ pub reports_email_admins: bool,
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
}
pub captcha_enabled: Option<bool>,
pub captcha_difficulty: Option<String>,
pub registration_mode: Option<RegistrationMode>,
+ pub reports_email_admins: Option<bool>,
}
#[derive(Clone, TypedBuilder)]
pub captcha_enabled: Option<bool>,
pub captcha_difficulty: Option<String>,
pub registration_mode: Option<RegistrationMode>,
+ pub reports_email_admins: Option<bool>,
pub updated: Option<Option<chrono::NaiveDateTime>>,
}
-Subproject commit 21808b45ea3ef7fa91654d4f6738b5144da6bfe7
+Subproject commit 2b95e1fa2f6ecb50a5b0575b1362b9f81a60e9b7
--- /dev/null
+alter table local_site drop column reports_email_admins;
--- /dev/null
+-- Adding a field to email admins for new reports
+alter table local_site add column reports_email_admins boolean not null default false;