From e3ee6d371937c883478bcdc5e3ebb60f41335222 Mon Sep 17 00:00:00 2001 From: Leandro Nunes dos Santos Date: Tue, 21 Sep 2010 17:50:24 -0300 Subject: [PATCH] Implmenting some improvement on profile activity: --- app/models/article.rb | 14 ++++++++++---- app/models/comment.rb | 6 +++++- app/models/friendship.rb | 2 +- app/models/person.rb | 7 +------ app/models/published_article.rb | 4 ++++ app/views/profile/_profile_network_activities.rhtml | 1 + config/initializers/action_tracker.rb | 13 ++++++++----- db/migrate/20100920182433_change_action_tracker_record.rb | 13 +++++++++++++ lib/notify_activity_to_profiles_job.rb | 26 +++++++++++++++++++++----- test/factories.rb | 4 ++-- test/functional/profile_controller_test.rb | 3 ++- test/unit/article_test.rb | 36 ++++++++++++++++++++++++++++++++++++ test/unit/comment_test.rb | 12 ++++++++++++ test/unit/community_test.rb | 4 ++-- test/unit/friendship_test.rb | 20 ++++++++++++-------- test/unit/notify_activity_to_profiles_job_test.rb | 152 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- test/unit/person_test.rb | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------- test/unit/published_article_test.rb | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/unit/textile_article_test.rb | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/unit/tiny_mce_article_test.rb | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/plugins/access_control/lib/role_assignment.rb | 8 ++++++-- vendor/plugins/action_tracker/generators/action_tracker/templates/migration.rb | 4 ++-- vendor/plugins/action_tracker/lib/action_tracker.rb | 18 +++++++++++------- vendor/plugins/action_tracker/lib/action_tracker_model.rb | 9 ++++++--- vendor/plugins/action_tracker/test/action_tracker_model_test.rb | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------- vendor/plugins/action_tracker/test/action_tracker_test.rb | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- vendor/plugins/user_stamp/lib/user_stamp.rb | 10 ++++++---- vendor/plugins/user_stamp/spec/user_stamp_sweeper_spec.rb | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------- 28 files changed, 932 insertions(+), 119 deletions(-) create mode 100644 db/migrate/20100920182433_change_action_tracker_record.rb 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) %>