From ba0ce4e14b59283977a9d4296c42c1c973135d4a Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Tue, 6 Oct 2015 12:05:34 +0200 Subject: [PATCH] =?UTF-8?q?a=C3=B1adir=20track=5Factivity=20para=20mostrar?= =?UTF-8?q?=20futuras=20notificaciones=20a=20los=20usuarios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 8 ++++++++ app/controllers/comments_controller.rb | 1 + app/models/activity.rb | 2 -- app/models/user.rb | 2 +- db/migrate/20150928075646_create_activities.rb | 9 +++++++++ db/schema.rb | 1 + 6 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20150928075646_create_activities.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 841b32498..b2bd92af1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 35406faf0..e05be448a 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -9,6 +9,7 @@ class CommentsController < ApplicationController def create if @comment.save CommentNotifier.new(comment: @comment).process + track_activity @comment else render :new end diff --git a/app/models/activity.rb b/app/models/activity.rb index 977204669..047ccb7dd 100644 --- a/app/models/activity.rb +++ b/app/models/activity.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index dd2bc5cf0..0d07643bd 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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}") ) diff --git a/db/migrate/20150928075646_create_activities.rb b/db/migrate/20150928075646_create_activities.rb new file mode 100644 index 000000000..89b0edcbc --- /dev/null +++ b/db/migrate/20150928075646_create_activities.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index ca180b297..16b50e4e9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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"