diff --git a/app/models/person.rb b/app/models/person.rb index 8729394..619c298 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -468,7 +468,7 @@ class Person < Profile end def activities - Scrap.find_by_sql("SELECT id, updated_at, '#{Scrap.to_s}' AS klass FROM #{Scrap.table_name} WHERE scraps.receiver_id = #{self.id} AND scraps.scrap_id IS NULL UNION SELECT id, updated_at, '#{ActionTracker::Record.to_s}' AS klass FROM #{ActionTracker::Record.table_name} WHERE action_tracker.user_id = #{self.id} and action_tracker.verb != 'leave_scrap_to_self' and action_tracker.verb != 'add_member_in_community' ORDER BY updated_at DESC") + Scrap.find_by_sql("SELECT id, updated_at, '#{Scrap.to_s}' AS klass FROM #{Scrap.table_name} WHERE scraps.receiver_id = #{self.id} AND scraps.scrap_id IS NULL UNION SELECT id, updated_at, '#{ActionTracker::Record.to_s}' AS klass FROM #{ActionTracker::Record.table_name} WHERE action_tracker.user_id = #{self.id} and action_tracker.verb != 'leave_scrap_to_self' and action_tracker.verb != 'add_member_in_community' and action_tracker.verb != 'reply_scrap_on_self' ORDER BY updated_at DESC") end # by default, all fields are private diff --git a/app/models/scrap.rb b/app/models/scrap.rb index 85d100a..c224a3e 100644 --- a/app/models/scrap.rb +++ b/app/models/scrap.rb @@ -14,9 +14,11 @@ class Scrap < ActiveRecord::Base named_scope :not_replies, :conditions => {:scrap_id => nil} - track_actions :leave_scrap, :after_create, :keep_params => ['sender.name', 'content', 'receiver.name', 'receiver.url'], :if => Proc.new{|s| s.receiver != s.sender}, :custom_target => :action_tracker_target + track_actions :leave_scrap, :after_create, :keep_params => ['sender.name', 'content', 'receiver.name', 'receiver.url'], :if => Proc.new{|s| s.sender != s.receiver && s.sender != s.top_root.receiver}, :custom_target => :action_tracker_target - track_actions :leave_scrap_to_self, :after_create, :keep_params => ['sender.name', 'content'], :if => Proc.new{|s| s.receiver == s.sender} + track_actions :leave_scrap_to_self, :after_create, :keep_params => ['sender.name', 'content'], :if => Proc.new{|s| s.sender == s.receiver} + + track_actions :reply_scrap_on_self, :after_create, :keep_params => ['sender.name', 'content'], :if => Proc.new{|s| s.sender != s.receiver && s.sender == s.top_root.receiver} after_create do |scrap| scrap.root.update_attribute('updated_at', DateTime.now) unless scrap.root.nil? @@ -25,6 +27,12 @@ class Scrap < ActiveRecord::Base before_validation :strip_all_html_tags + def top_root + scrap = self + scrap = Scrap.find(scrap.scrap_id) while scrap.scrap_id + scrap + end + def strip_all_html_tags sanitizer = HTML::WhiteListSanitizer.new self.content = sanitizer.sanitize(self.content, :tags => []) diff --git a/app/views/profile/_reply_scrap_on_self.rhtml b/app/views/profile/_reply_scrap_on_self.rhtml new file mode 120000 index 0000000..56c0e42 --- /dev/null +++ b/app/views/profile/_reply_scrap_on_self.rhtml @@ -0,0 +1 @@ +_leave_scrap.rhtml \ No newline at end of file diff --git a/config/initializers/action_tracker.rb b/config/initializers/action_tracker.rb index f295c33..5fd4037 100644 --- a/config/initializers/action_tracker.rb +++ b/config/initializers/action_tracker.rb @@ -2,6 +2,8 @@ require 'noosfero/i18n' # ActionTracker plugin stuff +@reply_scrap_description = lambda { _('sent a message to %{receiver}:
"%{message}"') % { :receiver => "{{link_to(ta.get_receiver_name, ta.get_receiver_url)}}", :message => "{{auto_link_urls(ta.get_content)}}" } } + ActionTrackerConfig.verbs = { :create_article => { @@ -49,12 +51,16 @@ ActionTrackerConfig.verbs = { }, :leave_scrap => { - :description => lambda { _('sent a message to %{receiver}:
"%{message}"') % { :receiver => "{{link_to(ta.get_receiver_name, ta.get_receiver_url)}}", :message => "{{auto_link_urls(ta.get_content)}}" } } + :description => @reply_scrap_description }, :leave_scrap_to_self => { :description => lambda { _('wrote:
"%{text}"') % { :text => "{{auto_link_urls(ta.get_content)}}" } } - } + }, + + :reply_scrap_on_self => { + :description => @reply_scrap_description + }, } ActionTrackerConfig.current_user_method = :current_person diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index d8e2ee5..1d5e0ef 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -1335,4 +1335,23 @@ class PersonTest < ActiveSupport::TestCase assert_includes non_abusers, not_abuser end + should 'not list leave_scrap_to_self in activities' do + person = fast_create(Person) + at = fast_create(ActionTracker::Record, :user_type => 'Person', :user_id => person.id, :verb => 'leave_scrap_to_self') + assert_not_includes person.activities, at + end + + should 'not list add_member_in_community in activities' do + person = fast_create(Person) + at = fast_create(ActionTracker::Record, :user_type => 'Person', :user_id => person.id, :verb => 'add_member_in_community') + assert_not_includes person.activities, at + end + + should 'not list reply_scrap_on_self in activities' do + person = fast_create(Person) + at = ActionTracker::Record.create!(:user => person, :verb => 'reply_scrap_on_self') + person.reload + pp person.activities + assert_not_includes person.activities, at + end end diff --git a/test/unit/scrap_test.rb b/test/unit/scrap_test.rb index 867c761..5bf0ec4 100644 --- a/test/unit/scrap_test.rb +++ b/test/unit/scrap_test.rb @@ -232,6 +232,14 @@ class ScrapTest < ActiveSupport::TestCase assert_equal s, s2.root end + should "have the top_root defined" do + s = fast_create(Scrap) + s1 = fast_create(Scrap, :scrap_id => s.id) + s2 = fast_create(Scrap, :scrap_id => s1.id) + assert_equal s, s1.top_root + assert_equal s, s2.top_root + end + should 'strip all html tags' do s, r = fast_create(Person), fast_create(Person) s = Scrap.new :sender => s, :receiver => r, :content => "

Test Rails

" @@ -276,4 +284,14 @@ class ScrapTest < ActiveSupport::TestCase assert_equal s.scrap_wall_url, s.receiver.wall_url end + should 'create activity with reply_scrap_on_self when top_root scrap receiver is the same as sender' do + s, r = fast_create(Person), fast_create(Person) + root = fast_create(Scrap, :sender_id => s.id, :receiver_id => r.id) + assert_difference ActionTracker::Record, :count, 1 do + reply = Scrap.create!(:sender => r, :receiver => s, :scrap_id => root.id, :content => 'sample') + end + activity = ActionTracker::Record.last + assert_equal 'reply_scrap_on_self', activity.verb.to_s + end + end -- libgit2 0.21.2