Files
nairobi/app/models/activity.rb
Javi Martín 021fef07b6 Make action names to block and hide more clear
The `hide` action was calling the `block` method while the `soft_block`
action was calling the `hide` method.

Combined with the fact that we also have a `block` permission which is
used in `ModerateActions` the logic was hard to follow.
2021-12-30 15:50:03 +01:00

29 lines
1.0 KiB
Ruby

class Activity < ApplicationRecord
belongs_to :actionable, -> { with_hidden }, polymorphic: true
belongs_to :user, -> { with_hidden }, inverse_of: :activities
VALID_ACTIONS = %w[hide block restore valuate email].freeze
validates :action, inclusion: { in: VALID_ACTIONS }
scope :on_proposals, -> { where(actionable_type: "Proposal") }
scope :on_debates, -> { where(actionable_type: "Debate") }
scope :on_users, -> { where(actionable_type: "User") }
scope :on_comments, -> { where(actionable_type: "Comment") }
scope :on_budget_investments, -> { where(actionable_type: "Budget::Investment") }
scope :on_system_emails, -> { where(actionable_type: "ProposalNotification") }
scope :for_render, -> { includes(user: [:moderator, :administrator]).includes(:actionable) }
def self.log(user, action, actionable)
create!(user: user, action: action.to_s, actionable: actionable)
end
def self.on(actionable)
where(actionable: actionable)
end
def self.by(user)
where(user: user)
end
end