añadir track_activity para mostrar futuras notificaciones a los usuarios
This commit is contained in:
@@ -108,4 +108,12 @@ class ApplicationController < ActionController::Base
|
||||
store_location_for(:user, request.path)
|
||||
end
|
||||
end
|
||||
|
||||
def track_activity(trackable)
|
||||
if trackable.is_a? Comment
|
||||
action = trackable.root? ? "debate_comment" : "comment_reply"
|
||||
activity = current_user.activities.create! action: action, trackable: trackable
|
||||
add_notifications_for activity
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,6 +9,7 @@ class CommentsController < ApplicationController
|
||||
def create
|
||||
if @comment.save
|
||||
CommentNotifier.new(comment: @comment).process
|
||||
track_activity @comment
|
||||
else
|
||||
render :new
|
||||
end
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
class Activity < ActiveRecord::Base
|
||||
|
||||
belongs_to :actionable, -> { with_hidden }, polymorphic: true
|
||||
belongs_to :user, -> { with_hidden }
|
||||
|
||||
@@ -24,5 +23,4 @@ class Activity < ActiveRecord::Base
|
||||
def self.by(user)
|
||||
where(user: user)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -199,7 +199,7 @@ class User < ActiveRecord::Base
|
||||
def email_required?
|
||||
!erased?
|
||||
end
|
||||
|
||||
|
||||
def has_official_email?
|
||||
domain = Setting.value_for 'email_domain_for_officials'
|
||||
!email.blank? && ( (email.end_with? "@#{domain}") || (email.end_with? ".#{domain}") )
|
||||
|
||||
9
db/migrate/20150928075646_create_activities.rb
Normal file
9
db/migrate/20150928075646_create_activities.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
class CreateActivities < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :activities do |t|
|
||||
t.belongs_to :user, index: true, foreign_key: true
|
||||
t.string :action
|
||||
t.belongs_to :trackable, polymorphic: true
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -396,6 +396,7 @@ ActiveRecord::Schema.define(version: 20151215165824) do
|
||||
add_index "votes", ["votable_id", "votable_type", "vote_scope"], name: "index_votes_on_votable_id_and_votable_type_and_vote_scope", using: :btree
|
||||
add_index "votes", ["voter_id", "voter_type", "vote_scope"], name: "index_votes_on_voter_id_and_voter_type_and_vote_scope", using: :btree
|
||||
|
||||
add_foreign_key "activities", "users"
|
||||
add_foreign_key "administrators", "users"
|
||||
add_foreign_key "annotations", "legislations"
|
||||
add_foreign_key "annotations", "users"
|
||||
|
||||
Reference in New Issue
Block a user