28
app/models/activity.rb
Normal file
28
app/models/activity.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
class Activity < ActiveRecord::Base
|
||||
|
||||
belongs_to :actionable, -> { with_hidden }, polymorphic: true
|
||||
belongs_to :user, -> { with_hidden }
|
||||
|
||||
VALID_ACTIONS = %w( hide block restore )
|
||||
|
||||
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 :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
|
||||
@@ -73,11 +73,11 @@ class Comment < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def after_hide
|
||||
commentable_type.constantize.reset_counters(commentable_id, :comments)
|
||||
commentable_type.constantize.with_hidden.reset_counters(commentable_id, :comments)
|
||||
end
|
||||
|
||||
def after_restore
|
||||
commentable_type.constantize.reset_counters(commentable_id, :comments)
|
||||
commentable_type.constantize.with_hidden.reset_counters(commentable_id, :comments)
|
||||
end
|
||||
|
||||
def reply?
|
||||
|
||||
Reference in New Issue
Block a user