Files
nairobi/app/controllers/admin/emails_download_controller.rb
Bertocq bdbb32e824 Move newsletter User scope outside UserSegments
Why:

UserSegments are not only used for Newsletters or Email downloads, but
also for internal Global Notifications. We don't want to have that scope
hardcoded inside UserSegments as users that have opted-out from the
newsletter should still be recipients of global notifications.

How:

Removing the scope from the UserSegments `all_users` method that acts as
base for all the other segments. Including that `newsletter` scope only
on the places that is relevant:
* When listing recipients for a newsletter
* When downloading a listing emails that can be newsletter recipients

Also updated relevant tests
2018-02-21 11:45:38 +01:00

19 lines
455 B
Ruby

class Admin::EmailsDownloadController < Admin::BaseController
def index
end
def generate_csv
users_segment = params[:users_segment]
filename = t("admin.segment_recipient.#{users_segment}")
csv_file = users_segment_emails_csv(users_segment)
send_data csv_file, filename: "#{filename}.csv"
end
private
def users_segment_emails_csv(users_segment)
UserSegments.send(users_segment).newsletter.pluck(:email).to_csv
end
end