Add backend for the moderators

Add new routes for the proposal notifications edition and
abilities to let moderators edit it (mark as ignored, hide, etc.).

The notifications are not flaggable because they doesn't work like that,
but in a similar way. The moderator/administrator is in charge of hidding
them through the UI, so the normal users don't flag it as inappropriate.

New controller Moderation::ProposalNotification to manage the moderators
work.
This commit is contained in:
iagirre
2018-05-16 13:03:56 +02:00
committed by decabeza
parent 7982574993
commit 21b1d00205
10 changed files with 109 additions and 3 deletions

View File

@@ -52,6 +52,17 @@ module Abilities
can :block, User
cannot :block, User, id: user.id
can :hide, ProposalNotification, hidden_at: nil
cannot :hide, ProposalNotification, author_id: user.id
can :ignore_flag, ProposalNotification, ignored_at: nil, hidden_at: nil
cannot :ignore_flag, ProposalNotification, author_id: user.id
can :moderate, ProposalNotification
cannot :moderate, ProposalNotification, author_id: user.id
can :index, ProposalNotification
end
end
end

View File

@@ -10,7 +10,19 @@ class ProposalNotification < ActiveRecord::Base
validates :proposal, presence: true
validate :minimum_interval
scope :public_for_api, -> { where(proposal_id: Proposal.public_for_api.pluck(:id)) }
scope :public_for_api, -> { where(proposal_id: Proposal.public_for_api.pluck(:id)) }
scope :sort_by_created_at, -> { reorder(created_at: :desc) }
scope :sort_by_moderated, -> { reorder(moderated: :desc) }
scope :moderated, -> { where(moderated: true) }
scope :not_moderated, -> { where(moderated: false) }
scope :pending_review, -> { moderated.where(ignored_at: nil) }
scope :ignored, -> { moderated.where.not(ignored_at: nil) }
acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases
after_create :set_author
def minimum_interval
return true if proposal.try(:notifications).blank?
@@ -25,4 +37,18 @@ class ProposalNotification < ActiveRecord::Base
proposal
end
def ignore_flag
update(ignored_at: Time.current)
end
def ignored?
ignored_at.present?
end
private
def set_author
self.update(author_id: self.proposal.author_id) if self.proposal
end
end

View File

@@ -182,12 +182,14 @@ class User < ActiveRecord::Base
debates_ids = Debate.where(author_id: id).pluck(:id)
comments_ids = Comment.where(user_id: id).pluck(:id)
proposal_ids = Proposal.where(author_id: id).pluck(:id)
proposal_notification_ids = ProposalNotification.where(author_id: id).pluck(:id)
hide
Debate.hide_all debates_ids
Comment.hide_all comments_ids
Proposal.hide_all proposal_ids
ProposalNotification.hide_all proposal_notification_ids
end
def erase(erase_reason = nil)