forked from consuldemocracy/consuldemocracy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request consuldemocracy#2474 from consul/admin_newsletter_…
…email_refactor Admin newsletter email refactor
- Loading branch information
Showing
20 changed files
with
164 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module UserSegmentsHelper | ||
def user_segments_options | ||
UserSegments::SEGMENTS.collect do |user_segment_name| | ||
[t("admin.segment_recipient.#{user_segment_name}"), user_segment_name] | ||
end | ||
end | ||
|
||
def segment_name(user_segment) | ||
if user_segment && UserSegments.respond_to?(user_segment) | ||
I18n.t("admin.segment_recipient.#{user_segment}") | ||
else | ||
I18n.t("admin.segment_recipient.invalid_recipients_segment") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,28 @@ | ||
class Newsletter < ActiveRecord::Base | ||
enum segment_recipient: { all_users: 1, | ||
proposal_authors: 2, | ||
investment_authors: 3, | ||
feasible_and_undecided_investment_authors: 4, | ||
selected_investment_authors: 5, | ||
winner_investment_authors: 6 } | ||
|
||
validates :subject, presence: true | ||
validates :segment_recipient, presence: true | ||
validates :from, presence: true | ||
validates :body, presence: true | ||
validate :validate_segment_recipient | ||
|
||
validates_format_of :from, :with => /@/ | ||
|
||
def list_of_recipients | ||
UserSegments.send(segment_recipient) | ||
UserSegments.send(segment_recipient).newsletter if valid_segment_recipient? | ||
end | ||
|
||
def valid_segment_recipient? | ||
segment_recipient && UserSegments.respond_to?(segment_recipient) | ||
end | ||
|
||
def draft? | ||
sent_at.nil? | ||
end | ||
|
||
private | ||
|
||
def validate_segment_recipient | ||
errors.add(:segment_recipient, :invalid) unless valid_segment_recipient? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
section "Creating Newsletters" do | ||
newsletter_body = [ | ||
"We choose to go to the moon in this decade and do the other things, not because they are easy, but because they are hard, because that goal will serve to organize and measure the best of our energies and skills, because that challenge is one that we are willing to accept, one we are unwilling to postpone, and one which we intend to win.", | ||
"Spaceflights cannot be stopped. This is not the work of any one man or even a group of men. It is a historical process which mankind is carrying out in accordance with the natural laws of human development.", | ||
"Many say exploration is part of our destiny, but it’s actually our duty to future generations and their quest to ensure the survival of the human species." | ||
"We choose to go to the moon in this decade and do the other things, not because they are easy"\ | ||
", but because they are hard, because that goal will serve to organize and measure the best of"\ | ||
" our energies and skills, because that challenge is one that we are willing to accept, one we"\ | ||
" are unwilling to postpone, and one which we intend to win.", | ||
"Spaceflights cannot be stopped. This is not the work of any one man or even a group of men."\ | ||
" It is a historical process which mankind is carrying out in accordance with the natural laws"\ | ||
" of human development.", | ||
"Many say exploration is part of our destiny, but it’s actually our duty to future generations"\ | ||
" and their quest to ensure the survival of the human species." | ||
] | ||
|
||
5.times do |n| | ||
Newsletter.create!( | ||
subject: "Newsletter subject #{n}", | ||
segment_recipient: Newsletter.segment_recipients.values.sample, | ||
segment_recipient: UserSegments::SEGMENTS.sample, | ||
from: '[email protected]', | ||
body: newsletter_body.sample, | ||
sent_at: [Time.now, nil].sample | ||
|
5 changes: 5 additions & 0 deletions
5
db/migrate/20180220211105_change_newsletter_segment_recipient_to_string.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class ChangeNewsletterSegmentRecipientToString < ActiveRecord::Migration | ||
def change | ||
change_column :newsletters, :segment_recipient, :string, null: false | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.