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

prevent notification emails from being sent to user's with invalid email #316

Merged
merged 4 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions app/workers/notification_email_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class NotificationEmailWorker

def perform(user_id, digest)
user = ::User.find user_id

return unless user.valid_email

digest_number = SubscriptionPreference.email_digests[digest]

# Ensure there are categories delivered at this frequency
Expand Down
13 changes: 13 additions & 0 deletions db/migrate/20240402094638_add_valid_email_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20231107211623) do
ActiveRecord::Schema.define(version: 20240402094638) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down
1 change: 1 addition & 0 deletions lib/tasks/db.rake
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ namespace :panoptes do
credited_name varchar(255),
admin bool,
banned bool,
valid_email bool,
confirmed_at timestamp(6)
) server panoptes;

Expand Down
1 change: 1 addition & 0 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
admin false
banned false
created_at Time.now - 1.year
valid_email true
confirmed_at Time.now - 364.days

factory :moderator do
Expand Down
10 changes: 10 additions & 0 deletions spec/workers/notification_email_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,15 @@
worker.perform user.id, :daily
end
end

context 'when user email is invalid' do
it 'should not attempt to deliver email' do
user.update(valid_email: false)
mail = double deliver_now!: true
expect(NotificationMailer).not_to receive(:notify)
expect(mail).not_to receive :deliver_now!
worker.perform user.id, :daily
end
end
end
end
Loading