* Remove sustaining member newsletter, and its settings This removes the concept of sustaining memberships from the system, and logic related to or dependent on it. This does not remove the monthly_dues column from the users table (todo). * Remove unused newsletter setting Since nothing accesses the mailchimp_sustaining_members_id setting, it's safe to remove. * Use destroy rather than delete to ensure settings cache is cleared We have a callback in Settings::Base to clear the cache after commit, I assume it's useful to trigger that. This requires destroy, not delete, to be called.
37 lines
986 B
Ruby
37 lines
986 B
Ruby
module IncomingWebhooks
|
|
class MailchimpUnsubscribesController < ApplicationController
|
|
skip_before_action :verify_authenticity_token
|
|
|
|
class InvalidListID < StandardError; end
|
|
|
|
LIST_MAPPINGS = {
|
|
mailchimp_newsletter_id: :email_newsletter,
|
|
mailchimp_tag_moderators_id: :email_tag_mod_newsletter,
|
|
mailchimp_community_moderators_id: :email_community_mod_newsletter
|
|
}.freeze
|
|
|
|
def index
|
|
head :ok
|
|
end
|
|
|
|
def create
|
|
not_authorized unless valid_secret?
|
|
user = User.find_by!(email: params.dig(:data, :email))
|
|
user.notification_setting.update(email_type => false)
|
|
end
|
|
|
|
private
|
|
|
|
def valid_secret?
|
|
params[:secret] == Settings::General.mailchimp_incoming_webhook_secret
|
|
end
|
|
|
|
def email_type
|
|
list_id = params.dig(:data, :list_id)
|
|
key = LIST_MAPPINGS.keys.detect { |k| Settings::General.public_send(k) == list_id }
|
|
raise InvalidListID unless key
|
|
|
|
LIST_MAPPINGS[key]
|
|
end
|
|
end
|
|
end
|