diff --git a/app/controllers/admin/system_emails_controller.rb b/app/controllers/admin/system_emails_controller.rb index da86b1e9a..626680f43 100644 --- a/app/controllers/admin/system_emails_controller.rb +++ b/app/controllers/admin/system_emails_controller.rb @@ -1,9 +1,11 @@ class Admin::SystemEmailsController < Admin::BaseController - before_action :load_system_email, only: [:view] + before_action :load_system_email, only: [:view, :preview_pending] def index - @system_emails = %w(proposal_notification_digest) + @system_emails = { + proposal_notification_digest: %w(view preview_pending) + } end def view @@ -14,9 +16,22 @@ class Admin::SystemEmailsController < Admin::BaseController end end + def preview_pending + case @system_email + when "proposal_notification_digest" + @previews = ProposalNotification.where(id: unsent_proposal_notifications_ids) + .page(params[:page]) + end + end + private def load_system_email @system_email = params[:system_email_id] end + + def unsent_proposal_notifications_ids + Notification.where(notifiable_type: "ProposalNotification", emailed_at: nil) + .group(:notifiable_id).count.keys + end end diff --git a/app/views/admin/system_emails/index.html.erb b/app/views/admin/system_emails/index.html.erb index 6e294d4e5..4d135d615 100644 --- a/app/views/admin/system_emails/index.html.erb +++ b/app/views/admin/system_emails/index.html.erb @@ -9,17 +9,24 @@ - <% @system_emails.each do |system_email| %> - + <% @system_emails.each do |system_email_title, system_email_actions| %> + - <%= t("admin.system_emails.#{system_email}.title") %> + <%= t("admin.system_emails.#{system_email_title}.title") %> - <%= t("admin.system_emails.#{system_email}.description") %> + <%= t("admin.system_emails.#{system_email_title}.description") %> - <%= link_to t("admin.shared.view"), admin_system_email_view_path(system_email), - class: "button hollow" %> + <% if system_email_actions.include?('view') %> + <%= link_to t("admin.shared.view"), admin_system_email_view_path(system_email_title), + class: "button hollow" %> + <% end %> + <% if system_email_actions.include?('preview_pending') %> + <%= link_to t("admin.system_emails.preview_pending.action"), + admin_system_email_preview_pending_path(system_email_title), + class: "button" %> + <% end %> <% end %> diff --git a/app/views/admin/system_emails/preview_pending.html.erb b/app/views/admin/system_emails/preview_pending.html.erb new file mode 100644 index 000000000..6de1c993f --- /dev/null +++ b/app/views/admin/system_emails/preview_pending.html.erb @@ -0,0 +1,16 @@ +<%= back_link_to admin_system_emails_path %> + +<% system_email_name = t("admin.system_emails.#{@system_email}.title") %> +

<%= t("admin.system_emails.preview_pending.preview_of", name: system_email_name) %>

+ +
+

<%= t("admin.system_emails.preview_pending.pending_to_be_sent") %>

+

<%= t("admin.system_emails.#{@system_email}.preview_detail") %>

+ + <% @previews.each do |preview| %> + <%= render partial: "admin/system_emails/preview_pending/#{@system_email}", + locals: { preview: preview } %> + <% end %> +
+ +<%= paginate @previews %> diff --git a/app/views/admin/system_emails/preview_pending/_proposal_notification_digest.html.erb b/app/views/admin/system_emails/preview_pending/_proposal_notification_digest.html.erb new file mode 100644 index 000000000..7cdd4d66d --- /dev/null +++ b/app/views/admin/system_emails/preview_pending/_proposal_notification_digest.html.erb @@ -0,0 +1,33 @@ +<% if preview.proposal.present? %> +
+
+
+ <%= t("admin.shared.proposal") %>
+ <%= link_to preview.proposal.title, proposal_url(preview.proposal) %> +
+
+ <%= t("admin.shared.title") %>
+ <%= link_to preview.title, proposal_url(preview.proposal, anchor: "tab-notifications") %> +
+
+
+
+ <%= t("admin.shared.author") %>
+ <%= preview.proposal.author&.username || '-' %> +
+
+ <%= t("admin.shared.created_at") %>
+ <%= l(preview.created_at, format: :datetime) %> +
+
+
+ +
+
+ <%= t("admin.shared.content") %> +

+ <%= preview.body %> +

+
+
+<% end %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index ea01f35d6..a2194110b 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -651,9 +651,14 @@ en: sent_guide: "This is how the users see the notification:" send_alert: Are you sure you want to send this notification to %{n} users? system_emails: + preview_pending: + action: Preview Pending + preview_of: Preview of %{name} + pending_to_be_sent: This is the content pending to be sent proposal_notification_digest: title: Proposal Notification Digest description: Gathers all proposal notifications for an user in a single message, to avoid too much emails. + preview_detail: Users will only recieve notifications from the proposals they are following emails_download: index: title: Emails download @@ -1051,7 +1056,10 @@ en: show_image: Show image moderated_content: "Check the content moderated by the moderators, and confirm if the moderation has been done correctly." view: View - preview: Preview + proposal: Proposal + author: Author + content: Content + created_at: Created at spending_proposals: index: geozone_filter_all: All zones diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 62e806ffb..2d652e8e2 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -652,9 +652,14 @@ es: sent_guide: "Así es como los usuarios ven la notificación:" send_alert: ¿Estás seguro/a de que quieres enviar esta notificación a %{n} usuarios? system_emails: + preview_pending: + action: Previsualizar Pendientes + preview_of: Vista previa de %{name} + pending_to_be_sent: Este es todo el contenido pendiente de enviar proposal_notification_digest: title: Resumen de Notificationes de Propuestas description: Reune todas las notificaciones de propuestas en un único mensaje, para evitar demasiados emails. + preview_detail: Los usuarios sólo recibirán las notificaciones de aquellas propuestas que siguen. emails_download: index: title: Descarga de emails @@ -1052,7 +1057,10 @@ es: show_image: Mostrar imagen moderated_content: "Revisa el contenido moderado por los moderadores, y confirma si la moderación se ha realizado correctamente." view: Ver - preview: Previsualizar + proposal: Propuesta + author: Autor + content: Contenido + created_at: Fecha de creación spending_proposals: index: geozone_filter_all: Todos los ámbitos de actuación diff --git a/config/routes/admin.rb b/config/routes/admin.rb index 2fe805593..150d1b28a 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -167,6 +167,7 @@ namespace :admin do resources :system_emails, only: [:index] do get :view + get :preview_pending end resources :emails_download, only: :index do diff --git a/spec/features/admin/system_emails_spec.rb b/spec/features/admin/system_emails_spec.rb index ddd812236..634a32efb 100644 --- a/spec/features/admin/system_emails_spec.rb +++ b/spec/features/admin/system_emails_spec.rb @@ -40,4 +40,29 @@ feature "System Emails" do end end + context "Preview Pending" do + scenario "#proposal_notification_digest" do + proposal_a = create(:proposal, title: 'Proposal A') + proposal_b = create(:proposal, title: 'Proposal B') + proposal_notification_a = create(:proposal_notification, proposal: proposal_a, + title: 'Proposal A Title', + body: 'Proposal A Notification Body') + proposal_notification_b = create(:proposal_notification, proposal: proposal_b, + title: 'Proposal B Title', + body: 'Proposal B Notification Body') + create(:notification, notifiable: proposal_notification_a, emailed_at: nil) + create(:notification, notifiable: proposal_notification_b, emailed_at: nil) + + visit admin_system_email_preview_pending_path('proposal_notification_digest') + + expect(page).to have_content('This is the content pending to be sent') + expect(page).to have_link('Proposal A', href: proposal_url(proposal_a)) + expect(page).to have_link('Proposal B', href: proposal_url(proposal_b)) + expect(page).to have_link('Proposal A Title', href: proposal_url(proposal_a, + anchor: 'tab-notifications')) + expect(page).to have_link('Proposal B Title', href: proposal_url(proposal_b, + anchor: 'tab-notifications')) + end + end + end