Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't send out new user email verifies to admins, if already verified. #5288

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions crates/api/src/local_user/verify_email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ pub async fn verify_email(
let site_view = SiteView::read_local(&mut context.pool()).await?;
let token = data.token.clone();
let verification = EmailVerification::read_for_token(&mut context.pool(), &token).await?;
let local_user_id = verification.local_user_id;
let local_user_view = LocalUserView::read(&mut context.pool(), local_user_id).await?;

// Check if their email has already been verified once, before this
let email_already_verified = local_user_view.local_user.email_verified;

let form = LocalUserUpdateForm {
// necessary in case this is a new signup
Expand All @@ -27,18 +32,16 @@ pub async fn verify_email(
email: Some(Some(verification.email)),
..Default::default()
};
let local_user_id = verification.local_user_id;

LocalUser::update(&mut context.pool(), local_user_id, &form).await?;

EmailVerification::delete_old_tokens_for_local_user(&mut context.pool(), local_user_id).await?;

// send out notification about registration application to admins if enabled
if site_view.local_site.application_email_admins {
let local_user = LocalUserView::read(&mut context.pool(), local_user_id).await?;

// Send out notification about registration application to admins if enabled, and the user hasn't
// already been verified.
if site_view.local_site.application_email_admins && !email_already_verified {
send_new_applicant_email_to_admins(
&local_user.person.name,
&local_user_view.person.name,
&mut context.pool(),
context.settings(),
)
Expand Down