Skip to content

Commit

Permalink
Merge pull request #696 from alphagov/remove-email-subscription
Browse files Browse the repository at this point in the history
Remove EmailSubscription model
  • Loading branch information
KludgeKML authored Sep 13, 2023
2 parents 20ef1e4 + 14ab0c0 commit 15eee2e
Show file tree
Hide file tree
Showing 12 changed files with 9 additions and 560 deletions.
49 changes: 0 additions & 49 deletions app/controllers/internal/email_subscriptions_controller.rb

This file was deleted.

27 changes: 3 additions & 24 deletions app/controllers/internal/oidc_users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,43 +45,22 @@ def authorise_sso_user!
end

def update_email_alert_api_address(user)
# if the user has linked their notifications account to their
# GOV.UK account we don't need to update their
# `user.email_subscriptions`, because we can update the subscriber
# directly.
GdsApi.email_alert_api.change_subscriber(
id: email_alert_api_subscriber_id(user),
new_address: user.email,
on_conflict: "merge",
)
rescue GdsApi::HTTPNotFound
# but for users who haven't linked their notifications account to
# their GOV.UK account, we do need to update any account-linked
# subscriptions they have (eg, brexit checker users who haven't
# touched notifications since registering through the checker).
#
# this branch can be removed once we have no GOV.UK accounts which
# have subscriptions but are *not* linked to the corresponding
# notifications account.
user.email_subscriptions.find_each do |subscription|
if subscription.activated? && !subscription.check_if_still_active!
subscription.destroy!
next
end

subscription.reactivate_if_confirmed!
rescue EmailSubscription::SubscriberListNotFound
subscription.destroy!
end
# No linked email-alert-api account, nothing to do
nil
end

def end_email_alert_api_subscriptions(user)
GdsApi.email_alert_api.unsubscribe_subscriber(
email_alert_api_subscriber_id(user),
)
rescue GdsApi::HTTPNotFound
# if there is no linked notifications account, there is nothing to
# do
# No linked email-alert-api account, nothing to do
nil
end

Expand Down
65 changes: 0 additions & 65 deletions app/models/email_subscription.rb

This file was deleted.

2 changes: 0 additions & 2 deletions app/models/oidc_user.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
class OidcUser < ApplicationRecord
has_many :email_subscriptions, dependent: :destroy

validates :sub, presence: true

before_destroy :create_tombstone
Expand Down
2 changes: 0 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

get "/attributes", to: "attributes#show"
patch "/attributes", to: "attributes#update"

resources :email_subscriptions, only: %i[show update destroy], param: :subscription_name, path: "email-subscriptions"
end

namespace :personalisation do
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20230824083133_drop_email_subscriptions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class DropEmailSubscriptions < ActiveRecord::Migration[7.0]
def up
drop_table :email_subscriptions
end
end
13 changes: 1 addition & 12 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions spec/factories/email_subscription_factory.rb

This file was deleted.

121 changes: 0 additions & 121 deletions spec/models/email_subscription_spec.rb

This file was deleted.

Loading

0 comments on commit 15eee2e

Please sign in to comment.