From 07d7a4dd72ff4824daa06a0651226a5cef4e8d15 Mon Sep 17 00:00:00 2001 From: decabeza Date: Tue, 30 Apr 2019 17:00:49 +0200 Subject: [PATCH 1/3] Add new user segment all_proposals_authors This segment include all proposals authors even if the proposals are archived or retired. --- config/locales/en/admin.yml | 1 + config/locales/es/admin.yml | 1 + lib/user_segments.rb | 5 +++++ spec/lib/user_segments_spec.rb | 22 ++++++++++++++++++++++ 4 files changed, 29 insertions(+) diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 82b80629f50..9e526426afc 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -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]" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 78c44d00e92..09b470d0bb6 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -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]" diff --git a/lib/user_segments.rb b/lib/user_segments.rb index 21ea13d87e0..6d780235b59 100644 --- a/lib/user_segments.rb +++ b/lib/user_segments.rb @@ -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 @@ -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 diff --git a/spec/lib/user_segments_spec.rb b/spec/lib/user_segments_spec.rb index 8e6d731627e..5c06f4f101d 100644 --- a/spec/lib/user_segments_spec.rb +++ b/spec/lib/user_segments_spec.rb @@ -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) From f584c352a2704a21c3f53d9de6097333efea71b2 Mon Sep 17 00:00:00 2001 From: decabeza Date: Tue, 30 Apr 2019 17:01:48 +0200 Subject: [PATCH 2/3] Removes unncesary div tag on admin newsletters show This prevent send button renders outside of the layout. --- app/views/admin/newsletters/show.html.erb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/views/admin/newsletters/show.html.erb b/app/views/admin/newsletters/show.html.erb index 450b12d1640..c4fe37ac584 100644 --- a/app/views/admin/newsletters/show.html.erb +++ b/app/views/admin/newsletters/show.html.erb @@ -54,7 +54,6 @@ <%= render file: "app/views/layouts/_mailer_footer.html.erb" %> - <% if @newsletter.draft? && @newsletter.valid_segment_recipient? %> <%= link_to t("admin.newsletters.show.send"), From 7b2f06bf4837869d914b9fa4c6f3e1bab26fc00c Mon Sep 17 00:00:00 2001 From: decabeza Date: Tue, 30 Apr 2019 17:02:21 +0200 Subject: [PATCH 3/3] Fix indentation on admin newsletters show --- app/views/admin/newsletters/show.html.erb | 86 +++++++++++------------ 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/app/views/admin/newsletters/show.html.erb b/app/views/admin/newsletters/show.html.erb index c4fe37ac584..666a27ce337 100644 --- a/app/views/admin/newsletters/show.html.erb +++ b/app/views/admin/newsletters/show.html.erb @@ -4,56 +4,56 @@ <% recipients_count = @newsletter.valid_segment_recipient? ? @newsletter.list_of_recipient_emails.count : 0 %> -
-
- <%= t("admin.newsletters.show.sent_at") %>
- <% if @newsletter.draft? %> - <%= t("admin.newsletters.index.draft") %> - <% else %> - <%= l @newsletter.sent_at.to_date %> - <% end %> -
-
- <%= t("admin.newsletters.show.from") %>
- <%= @newsletter.from %> -
-
- <%= t("admin.newsletters.show.subject") %>
- <%= @newsletter.subject %> -
-
- <%= t("admin.newsletters.show.segment_recipient") %>
- <%= segment_name(@newsletter.segment_recipient) %> - <%= t("admin.newsletters.show.affected_users", n: recipients_count) %> -
- -
- - <%= t("admin.newsletters.show.sent_emails", count: @newsletter.activities.count) %> - -
+
+
+ <%= t("admin.newsletters.show.sent_at") %>
+ <% if @newsletter.draft? %> + <%= t("admin.newsletters.index.draft") %> + <% else %> + <%= l @newsletter.sent_at.to_date %> + <% end %> +
+
+ <%= t("admin.newsletters.show.from") %>
+ <%= @newsletter.from %> +
+
+ <%= t("admin.newsletters.show.subject") %>
+ <%= @newsletter.subject %> +
+
+ <%= t("admin.newsletters.show.segment_recipient") %>
+ <%= segment_name(@newsletter.segment_recipient) %> + <%= t("admin.newsletters.show.affected_users", n: recipients_count) %>
- <%= t("admin.newsletters.show.body") %> -

- <%= t("admin.newsletters.show.body_help_text") %> -

+ + <%= t("admin.newsletters.show.sent_emails", count: @newsletter.activities.count) %> +
+
- <% if @newsletter.draft? && @newsletter.valid_segment_recipient? %> <%= link_to t("admin.newsletters.show.send"),