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

Add valid_email check to mailer #312

Closed
lcjohnso opened this issue Dec 6, 2023 · 2 comments
Closed

Add valid_email check to mailer #312

lcjohnso opened this issue Dec 6, 2023 · 2 comments
Assignees

Comments

@lcjohnso
Copy link
Member

lcjohnso commented Dec 6, 2023

Current Behavior: Talk sends notification digests to users with invalid email addresses. When these emails bounce, the email_verify app will update the valid_email property on the Panoptes user table, but the Talk mailer does not reflect on or respect this property.

Desired Behavior: Talk checks a user's valid_email property before sending notification emails.

Possible Solution: Add valid_email as part of the foreign data wrapper for the shared Users table, add a check to the mailer / email worker to only send email to users where valid_email is true.

@zwolf
Copy link
Member

zwolf commented Mar 29, 2024

@Tooyosi The main goal here will be to get the various mailers to reflect on the user's valid_email setting to determine whether or not to send an email. First hurdle is that valid_email is not an attribute on the users table in the Talk database. Talk's db tables include several "foreign data wrappers", which means that the data, as accessed by postgres and ActiveRecord, is not actually stored in the Talk db, but "wraps" a table in the Panoptes db. This is a bit of an faff but means that the data isn't duplicated across multiple servers and that there are no sync issues. But it only includes specified attributes, so the first thing to do is to create a migration that will add valid_email to Talk's users table. A recent example of this for a different attr can be seen here: https://github.com/zooniverse/talk-api/pull/311/files#diff-161dff43d2f4e2474da8188b82b3172f798a135e31a6499bc407b8ffe276fa21R3

But it'll basically look like this (I happened to have already started this):

# frozen_string_literal: true

class AddValidEmailToUsers < ActiveRecord::Migration
  def up
    execute <<-SQL
      ALTER FOREIGN TABLE users ADD COLUMN valid_email boolean DEFAULT true;
    SQL
  end

  def down
    execute <<-SQL
      ALTER FOREIGN TABLE users DROP COLUMN IF EXISTS valid_email;
    SQL
  end
end

There's no data to update here since this just grants access to the existing column across the way at Panoptes' user table. You'll want to add it to the factory and a couple other places too, use the above PR as a reference.

So once that user attribute is available to check, you'll want to find the places that needs doing. I'm pretty sure the NotificationEmailWorker and DigestEmailWorker are the ones you want. It looks like some checks are already being done for notifications: https://github.com/zooniverse/talk-api/blob/master/app/workers/notification_email_worker.rb#L24

A return out of the worker's perform method prior to the email getting sent would work for this, too. Return if the user's valid_email is false and you've prevented an unnecessary send attempt. Spec would look similar to the other "does not attempt to deliver email" specs in the NotificationEmailWorker spec.

let me know when you have questions!

@lcjohnso
Copy link
Member Author

Closed by #316

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants