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
50 lines
1.2 KiB
Ruby
50 lines
1.2 KiB
Ruby
class UserSegments
|
|
SEGMENTS = %w(all_users
|
|
proposal_authors
|
|
investment_authors
|
|
feasible_and_undecided_investment_authors
|
|
selected_investment_authors
|
|
winner_investment_authors)
|
|
|
|
def self.all_users
|
|
User.active
|
|
end
|
|
|
|
def self.proposal_authors
|
|
author_ids = Proposal.not_archived.not_retired.pluck(:author_id).uniq
|
|
author_ids(author_ids)
|
|
end
|
|
|
|
def self.investment_authors
|
|
author_ids = current_budget_investments.pluck(:author_id).uniq
|
|
author_ids(author_ids)
|
|
end
|
|
|
|
def self.feasible_and_undecided_investment_authors
|
|
author_ids = current_budget_investments.where(feasibility: %w(feasible undecided))
|
|
.pluck(:author_id).uniq
|
|
|
|
author_ids(author_ids)
|
|
end
|
|
|
|
def self.selected_investment_authors
|
|
author_ids = current_budget_investments.selected.pluck(:author_id).uniq
|
|
author_ids(author_ids)
|
|
end
|
|
|
|
def self.winner_investment_authors
|
|
author_ids = current_budget_investments.winners.pluck(:author_id).uniq
|
|
author_ids(author_ids)
|
|
end
|
|
|
|
private
|
|
|
|
def self.current_budget_investments
|
|
Budget.current.investments
|
|
end
|
|
|
|
def self.author_ids(author_ids)
|
|
all_users.where(id: author_ids)
|
|
end
|
|
end
|