2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-25 16:15:39 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
2018-03-25 17:30:42 +00:00
|
|
|
module QueryEmailSettings
|
2019-07-30 21:29:24 +00:00
|
|
|
Settings = %w[notify_payments notify_campaigns notify_events notify_payouts notify_recurring_donations].freeze
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
def self.fetch(np_id, user_id)
|
2019-07-30 21:29:24 +00:00
|
|
|
es = Psql.execute(%(
|
2018-03-25 17:30:42 +00:00
|
|
|
SELECT *
|
|
|
|
FROM email_settings
|
|
|
|
WHERE nonprofit_id=#{Qexpr.quote(np_id.to_i)}
|
|
|
|
AND user_id=#{Qexpr.quote(user_id.to_i)}
|
|
|
|
)).first
|
|
|
|
|
|
|
|
# If the user's event_settings table does not exist, return a hash with all settings true
|
|
|
|
if es.nil?
|
2019-07-30 21:29:24 +00:00
|
|
|
es = Psql.execute(%(
|
2018-03-25 17:30:42 +00:00
|
|
|
SELECT column_name
|
|
|
|
FROM information_schema.columns
|
|
|
|
WHERE table_name='email_settings'
|
2019-07-30 21:29:24 +00:00
|
|
|
)).map { |h| h['column_name'] }
|
|
|
|
.reject { |name| %w[id nonprofit_id user_id].include?(name) }
|
|
|
|
.each_with_object({}) { |name, h| h[name] = true; }
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
2019-07-30 21:29:24 +00:00
|
|
|
es
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
end
|