diff --git a/app/models/article.rb b/app/models/article.rb index 3849fff..8ca5a44 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -2,10 +2,9 @@ require 'hpricot' class Article < ActiveRecord::Base - track_actions :create_article, :after_create, :keep_params => [:name, :url], :if => Proc.new { |a| a.published? && !a.profile.is_a?(Community) && !a.image? && a.notifiable? } - track_actions :update_article, :before_update, :keep_params => [:name, :url], :if => Proc.new { |a| a.published? && (a.body_changed? || a.name_changed?) && a.notifiable? } - track_actions :remove_article, :before_destroy, :keep_params => [:name], :if => Proc.new { |a| a.published? && a.notifiable? } - track_actions :publish_article_in_community, :after_create, :keep_params => ["name", "url", "profile.url", "profile.name"], :if => Proc.new { |a| a.published? && a.profile.is_a?(Community) && !a.image? && a.notifiable? } + track_actions :create_article, :after_create, :keep_params => [:name, :url], :if => Proc.new { |a| a.is_trackable? && !a.image? }, :custom_target => :action_tracker_target + track_actions :update_article, :before_update, :keep_params => [:name, :url], :if => Proc.new { |a| a.is_trackable? && (a.body_changed? || a.name_changed?) }, :custom_target => :action_tracker_target + track_actions :remove_article, :before_destroy, :keep_params => [:name], :if => Proc.new { |a| a.is_trackable? }, :custom_target => :action_tracker_target # xss_terminate plugin can't sanitize array fields before_save :sanitize_tag_list @@ -43,6 +42,10 @@ class Article < ActiveRecord::Base validates_format_of :external_link, :with => URL_FORMAT, :if => lambda { |article| !article.external_link.blank? } + def is_trackable? + self.published? && self.notifiable? && self.advertise? + end + def external_link=(link) if !link.blank? && link !~ /^[a-z]+:\/\//i link = 'http://' + link @@ -50,6 +53,9 @@ class Article < ActiveRecord::Base self[:external_link] = link end + def action_tracker_target + self.profile + end def self.human_attribute_name(attrib) case attrib.to_sym diff --git a/app/models/comment.rb b/app/models/comment.rb index b8a92ca..0bd61d7 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,6 +1,6 @@ class Comment < ActiveRecord::Base - track_actions :leave_comment, :after_create, :keep_params => ["article.title", "article.url", "title", "url", "body"] + track_actions :leave_comment, :after_create, :keep_params => ["article.title", "article.url", "title", "url", "body"], :custom_target => :action_tracker_target validates_presence_of :title, :body belongs_to :article, :counter_cache => true @@ -21,6 +21,10 @@ class Comment < ActiveRecord::Base xss_terminate :only => [ :body, :title, :name ], :on => 'validation' + def action_tracker_target + self.article.profile + end + def author_name if author author.short_name diff --git a/app/models/friendship.rb b/app/models/friendship.rb index 57b2e21..8df2844 100644 --- a/app/models/friendship.rb +++ b/app/models/friendship.rb @@ -1,5 +1,5 @@ class Friendship < ActiveRecord::Base - track_actions :new_friendship, :after_create, :keep_params => ["friend.name", "friend.url", "friend.profile_custom_icon"], :unless => Proc.new { |f| f.friend.is_a_friend?(f.person) } + track_actions :new_friendship, :after_create, :keep_params => ["friend.name", "friend.url", "friend.profile_custom_icon"], :custom_user => :person belongs_to :person, :foreign_key => :person_id belongs_to :friend, :class_name => 'Person', :foreign_key => 'friend_id' diff --git a/app/models/person.rb b/app/models/person.rb index d6edf46..ed1702b 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -327,12 +327,7 @@ class Person < Profile end def self.notify_activity(tracked_action) - profile = tracked_action.dispatcher.profile if tracked_action.dispatcher.is_a?(Article) - profile = tracked_action.dispatcher.resource if tracked_action.dispatcher.is_a?(RoleAssignment) - profile = tracked_action.dispatcher.article.profile if tracked_action.dispatcher.is_a?(Comment) - profile_id = profile.nil? ? nil : profile.id - Delayed::Job.enqueue NotifyActivityToProfilesJob.new(tracked_action.id, profile_id) - ActionTrackerNotification.create(:action_tracker => tracked_action, :profile => tracked_action.user) + Delayed::Job.enqueue NotifyActivityToProfilesJob.new(tracked_action.id) end def is_member_of?(profile) diff --git a/app/models/published_article.rb b/app/models/published_article.rb index a7a3653..98f09e8 100644 --- a/app/models/published_article.rb +++ b/app/models/published_article.rb @@ -37,4 +37,8 @@ class PublishedArticle < Article reference_article && reference_article.abstract end + def notifiable? + true + end + end diff --git a/app/views/profile/_profile_network_activities.rhtml b/app/views/profile/_profile_network_activities.rhtml index 88002eb..ed32049 100644 --- a/app/views/profile/_profile_network_activities.rhtml +++ b/app/views/profile/_profile_network_activities.rhtml @@ -9,6 +9,7 @@

<%= time_ago_as_sentence(activity.created_at) + ' ' + _('ago') %>

<%= link_to activity.user.name, activity.user.url %> <%= describe activity %>

+

<%= _('In community %s') % link_to(activity.target.name, activity.target.url) if !profile.is_a?(Community) && activity.target.is_a?(Community) %>