Adding a site option to email admins for new reports. (#2730)

- Fixes #2551
pull/2735/head
Dessalines 1 year ago committed by GitHub
parent 166854b37e
commit ddb6268164
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -18,7 +18,7 @@
"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",

@ -3,7 +3,7 @@ use actix_web::web::Data;
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::{
@ -54,6 +54,17 @@ impl Perform for CreateCommentReport {
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,
};

@ -3,7 +3,7 @@ use actix_web::web::Data;
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::{
@ -56,6 +56,17 @@ impl Perform for CreatePostReport {
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

@ -3,7 +3,7 @@ use actix_web::web::Data;
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::{
@ -53,6 +53,17 @@ impl Perform for CreatePrivateMessageReport {
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,
};

@ -195,6 +195,7 @@ pub struct EditSite {
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>,
}

@ -483,6 +483,28 @@ pub async fn send_new_applicant_email_to_admins(
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,

@ -119,6 +119,7 @@ impl PerformCrud for EditSite {
.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)

@ -698,6 +698,7 @@ table! {
captcha_enabled -> Bool,
captcha_difficulty -> Text,
registration_mode -> RegistrationModeType,
reports_email_admins -> Bool,
published -> Timestamp,
updated -> Nullable<Timestamp>,
}

@ -31,6 +31,7 @@ pub struct LocalSite {
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>,
}
@ -62,6 +63,7 @@ pub struct LocalSiteInsertForm {
pub captcha_enabled: Option<bool>,
pub captcha_difficulty: Option<String>,
pub registration_mode: Option<RegistrationMode>,
pub reports_email_admins: Option<bool>,
}
#[derive(Clone, TypedBuilder)]
@ -89,6 +91,7 @@ pub struct LocalSiteUpdateForm {
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>>,
}

@ -1 +1 @@
Subproject commit 21808b45ea3ef7fa91654d4f6738b5144da6bfe7
Subproject commit 2b95e1fa2f6ecb50a5b0575b1362b9f81a60e9b7

@ -0,0 +1 @@
alter table local_site drop column reports_email_admins;

@ -0,0 +1,2 @@
-- Adding a field to email admins for new reports
alter table local_site add column reports_email_admins boolean not null default false;
Loading…
Cancel
Save