Skip to content

Commit

Permalink
Merge pull request consuldemocracy#1990 from AyuntamientoMadrid/propo…
Browse files Browse the repository at this point in the history
…sals-user-segment

Proposals authors user segment
  • Loading branch information
decabeza authored Apr 30, 2019
2 parents fc97b68 + 7b2f06b commit 4a41e00
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 43 deletions.
85 changes: 42 additions & 43 deletions app/views/admin/newsletters/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,55 @@

<% recipients_count = @newsletter.valid_segment_recipient? ? @newsletter.list_of_recipient_emails.count : 0 %>

<div class="small-12 column callout highlight">
<div class="small-12 medium-2 column">
<strong><%= t("admin.newsletters.show.sent_at") %></strong><br>
<% if @newsletter.draft? %>
<%= t("admin.newsletters.index.draft") %>
<% else %>
<%= l @newsletter.sent_at.to_date %>
<% end %>
</div>
<div class="small-12 medium-6 column">
<strong><%= t("admin.newsletters.show.from") %></strong><br>
<%= @newsletter.from %>
</div>
<div class="small-12 medium-4 column">
<strong><%= t("admin.newsletters.show.subject") %></strong><br>
<%= @newsletter.subject %>
</div>
<div class="small-12 column">
<strong><%= t("admin.newsletters.show.segment_recipient") %></strong><br>
<%= segment_name(@newsletter.segment_recipient) %>
<%= t("admin.newsletters.show.affected_users", n: recipients_count) %>
</div>

<div class="small-12 column">
<strong>
<%= t("admin.newsletters.show.sent_emails", count: @newsletter.activities.count) %>
</strong>
</div>
<div class="small-12 column callout highlight">
<div class="small-12 medium-2 column">
<strong><%= t("admin.newsletters.show.sent_at") %></strong><br>
<% if @newsletter.draft? %>
<%= t("admin.newsletters.index.draft") %>
<% else %>
<%= l @newsletter.sent_at.to_date %>
<% end %>
</div>
<div class="small-12 medium-6 column">
<strong><%= t("admin.newsletters.show.from") %></strong><br>
<%= @newsletter.from %>
</div>
<div class="small-12 medium-4 column">
<strong><%= t("admin.newsletters.show.subject") %></strong><br>
<%= @newsletter.subject %>
</div>
<div class="small-12 column">
<strong><%= t("admin.newsletters.show.segment_recipient") %></strong><br>
<%= segment_name(@newsletter.segment_recipient) %>
<%= t("admin.newsletters.show.affected_users", n: recipients_count) %>
</div>

<div class="small-12 column">
<strong><%= t("admin.newsletters.show.body") %></strong>
<p class="help-text" id="phase-description-help-text">
<%= t("admin.newsletters.show.body_help_text") %>
</p>
<strong>
<%= t("admin.newsletters.show.sent_emails", count: @newsletter.activities.count) %>
</strong>
</div>
</div>

<div class="small-12 column">
<strong><%= t("admin.newsletters.show.body") %></strong>
<p class="help-text" id="phase-description-help-text">
<%= t("admin.newsletters.show.body_help_text") %>
</p>
</div>

<div class="newsletter-body-content">
<%= render file: "app/views/layouts/_mailer_header.html.erb" %>
<div class="newsletter-body-content">
<%= render file: "app/views/layouts/_mailer_header.html.erb" %>

<table cellpadding="0" cellspacing="0" border="0" style="background: #fff; margin: 0 auto; max-width: 700px; width:100%;">
<tbody>
<tr>
<%= render file: "app/views/mailer/newsletter.html.erb" %>
</tr>
</tbody>
</table>
<table cellpadding="0" cellspacing="0" border="0" style="background: #fff; margin: 0 auto; max-width: 700px; width:100%;">
<tbody>
<tr>
<%= render file: "app/views/mailer/newsletter.html.erb" %>
</tr>
</tbody>
</table>

<%= render file: "app/views/layouts/_mailer_footer.html.erb" %>
</div>
<%= render file: "app/views/layouts/_mailer_footer.html.erb" %>
</div>

<% if @newsletter.draft? && @newsletter.valid_segment_recipient? %>
Expand Down
1 change: 1 addition & 0 deletions config/locales/en/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,7 @@ en:
segment_recipient:
all_users: All users
administrators: Administrators
all_proposal_authors: Proposal authors (including archived and retired)
proposal_authors: Proposal authors
investment_authors: Investment authors in the current budget
feasible_and_undecided_investment_authors: "Authors of some investment in the current budget that does not comply with: [valuation finished unfesasible]"
Expand Down
1 change: 1 addition & 0 deletions config/locales/es/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ es:
segment_recipient:
all_users: Todos los usuarios
administrators: Administradores
all_proposal_authors: Usuarios autores de propuestas (incluyendo archivadas y retiradas)
proposal_authors: Usuarios autores de propuestas
investment_authors: Usuarios autores de proyectos de gasto en los actuales presupuestos
feasible_and_undecided_investment_authors: "Usuarios autores de algún proyecto de gasto en los actuales presupuestos que no cumpla: [evaluación finalizada inviable]"
Expand Down
5 changes: 5 additions & 0 deletions lib/user_segments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class UserSegments
def self.segments
%w(all_users
administrators
all_proposal_authors
proposal_authors
investment_authors
feasible_and_undecided_investment_authors
Expand All @@ -20,6 +21,10 @@ def self.administrators
all_users.administrators
end

def self.all_proposal_authors
author_ids(Proposal.pluck(:author_id).uniq)
end

def self.proposal_authors
author_ids(Proposal.not_archived.not_retired.pluck(:author_id).uniq)
end
Expand Down
22 changes: 22 additions & 0 deletions spec/lib/user_segments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,28 @@
end
end

describe "#all_proposal_authors" do
it "returns users that have created a proposal even if is archived or retired" do
create(:proposal, author: user1)
create(:proposal, :archived, author: user2)
create(:proposal, retired_at: Time.current, author: user3)

all_proposal_authors = described_class.all_proposal_authors
expect(all_proposal_authors).to include user1
expect(all_proposal_authors).to include user2
expect(all_proposal_authors).to include user3
end

it "does not return duplicated users" do
create(:proposal, author: user1)
create(:proposal, :archived, author: user1)
create(:proposal, retired_at: Time.current, author: user1)

all_proposal_authors = described_class.all_proposal_authors
expect(all_proposal_authors).to contain_exactly(user1)
end
end

describe "#proposal_authors" do
it "returns users that have created a proposal" do
proposal = create(:proposal, author: user1)
Expand Down

0 comments on commit 4a41e00

Please sign in to comment.