Adds moderate actions to proposal system notifications

This commit is contained in:
María Checa
2018-05-15 12:55:51 +02:00
committed by decabeza
parent 3cc8b1d123
commit f1e7b634ba
4 changed files with 55 additions and 27 deletions

View File

@@ -1,6 +1,6 @@
class Admin::SystemEmailsController < Admin::BaseController class Admin::SystemEmailsController < Admin::BaseController
before_action :load_system_email, only: [:view, :preview_pending] before_action :load_system_email, only: [:view, :preview_pending, :moderate_pending]
def index def index
@system_emails = { @system_emails = {

View File

@@ -55,4 +55,9 @@ class ProposalNotification < ActiveRecord::Base
self.update(author_id: self.proposal.author_id) if self.proposal self.update(author_id: self.proposal.author_id) if self.proposal
end end
def moderate_system_email(moderator)
Notification.where(notifiable_type: 'ProposalNotification', notifiable: self).destroy_all
Activity.log(moderator, :hide, self)
end
end end

View File

@@ -1,6 +1,7 @@
<% if preview.proposal.present? %> <% if preview.proposal.present? %>
<div id="<%= dom_id(preview) %>">
<div class="callout highlight"> <div class="callout highlight">
<div class="row"> <div class="row expanded">
<div class="small-12 medium-6 column"> <div class="small-12 medium-6 column">
<strong><%= t("admin.shared.proposal") %></strong><br> <strong><%= t("admin.shared.proposal") %></strong><br>
<%= link_to preview.proposal.title, proposal_url(preview.proposal) %> <%= link_to preview.proposal.title, proposal_url(preview.proposal) %>
@@ -9,8 +10,6 @@
<strong><%= t("admin.shared.title") %></strong><br> <strong><%= t("admin.shared.title") %></strong><br>
<%= link_to preview.title, proposal_url(preview.proposal, anchor: "tab-notifications") %> <%= link_to preview.title, proposal_url(preview.proposal, anchor: "tab-notifications") %>
</div> </div>
</div>
<div class="row">
<div class="small-12 medium-6 column"> <div class="small-12 medium-6 column">
<strong><%= t("admin.shared.author") %></strong><br> <strong><%= t("admin.shared.author") %></strong><br>
<%= preview.proposal.author&.username || '-' %> <%= preview.proposal.author&.username || '-' %>
@@ -25,9 +24,17 @@
<div class="row"> <div class="row">
<div class="column"> <div class="column">
<strong><%= t("admin.shared.content") %></strong> <strong><%= t("admin.shared.content") %></strong>
<p class="help-text" id="phase-description-help-text"> <p id="phase-description-help-text">
<%= preview.body %> <%= preview.body %>
</p> </p>
</div> </div>
</div> </div>
<%= link_to t("admin.system_emails.preview_pending.moderate_pending"),
admin_system_email_moderate_pending_path(system_email_id: 'proposal_notification_digest',
id: preview.id),
method: :put,
class: "button hollow float-right" %>
</div>
<hr>
<% end %> <% end %>

View File

@@ -152,5 +152,21 @@ describe ProposalNotification do
end end
describe "#moderate_system_email" do
let(:admin) { create(:administrator) }
let(:proposal) { create(:proposal) }
let(:proposal_notification) { build(:proposal_notification, proposal: proposal) }
let(:notification) { create(:notification, notifiable: proposal_notification) }
it "removes all notifications related to the proposal notification" do
proposal_notification.moderate_system_email(admin.user)
expect(Notification.all.count).to be(0)
end
it "records the moderation action in the Activity table" do
proposal_notification.moderate_system_email(admin.user)
expect(Activity.last.actionable_type).to eq('ProposalNotification')
end
end
end end
end end