Merge pull request #539 from AyuntamientoMadrid/activities

Activities
This commit is contained in:
Enrique García
2015-09-23 12:40:02 +02:00
25 changed files with 638 additions and 16 deletions

28
app/models/activity.rb Normal file
View 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

View File

@@ -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?