Commit 2d3800c33c1c7ece6a2fe05c530b2acd33dbdb16
Exists in
master
and in
28 other branches
erge commit 'refs/merge-requests/390' of git://gitorious.org/noosfero/noosfero i…
…nto merge-requests/390
Showing
6 changed files
with
58 additions
and
5 deletions
Show diff stats
app/models/person.rb
... | ... | @@ -468,7 +468,7 @@ class Person < Profile |
468 | 468 | end |
469 | 469 | |
470 | 470 | def activities |
471 | - 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") | |
471 | + 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") | |
472 | 472 | end |
473 | 473 | |
474 | 474 | # by default, all fields are private | ... | ... |
app/models/scrap.rb
... | ... | @@ -14,9 +14,11 @@ class Scrap < ActiveRecord::Base |
14 | 14 | |
15 | 15 | named_scope :not_replies, :conditions => {:scrap_id => nil} |
16 | 16 | |
17 | - 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 | |
17 | + 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 | |
18 | 18 | |
19 | - track_actions :leave_scrap_to_self, :after_create, :keep_params => ['sender.name', 'content'], :if => Proc.new{|s| s.receiver == s.sender} | |
19 | + track_actions :leave_scrap_to_self, :after_create, :keep_params => ['sender.name', 'content'], :if => Proc.new{|s| s.sender == s.receiver} | |
20 | + | |
21 | + 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} | |
20 | 22 | |
21 | 23 | after_create do |scrap| |
22 | 24 | scrap.root.update_attribute('updated_at', DateTime.now) unless scrap.root.nil? |
... | ... | @@ -25,6 +27,12 @@ class Scrap < ActiveRecord::Base |
25 | 27 | |
26 | 28 | before_validation :strip_all_html_tags |
27 | 29 | |
30 | + def top_root | |
31 | + scrap = self | |
32 | + scrap = Scrap.find(scrap.scrap_id) while scrap.scrap_id | |
33 | + scrap | |
34 | + end | |
35 | + | |
28 | 36 | def strip_all_html_tags |
29 | 37 | sanitizer = HTML::WhiteListSanitizer.new |
30 | 38 | self.content = sanitizer.sanitize(self.content, :tags => []) | ... | ... |
config/initializers/action_tracker.rb
... | ... | @@ -2,6 +2,8 @@ require 'noosfero/i18n' |
2 | 2 | |
3 | 3 | # ActionTracker plugin stuff |
4 | 4 | |
5 | +@reply_scrap_description = lambda { _('sent a message to %{receiver}: <br /> "%{message}"') % { :receiver => "{{link_to(ta.get_receiver_name, ta.get_receiver_url)}}", :message => "{{auto_link_urls(ta.get_content)}}" } } | |
6 | + | |
5 | 7 | ActionTrackerConfig.verbs = { |
6 | 8 | |
7 | 9 | :create_article => { |
... | ... | @@ -49,12 +51,16 @@ ActionTrackerConfig.verbs = { |
49 | 51 | }, |
50 | 52 | |
51 | 53 | :leave_scrap => { |
52 | - :description => lambda { _('sent a message to %{receiver}: <br /> "%{message}"') % { :receiver => "{{link_to(ta.get_receiver_name, ta.get_receiver_url)}}", :message => "{{auto_link_urls(ta.get_content)}}" } } | |
54 | + :description => @reply_scrap_description | |
53 | 55 | }, |
54 | 56 | |
55 | 57 | :leave_scrap_to_self => { |
56 | 58 | :description => lambda { _('wrote: <br /> "%{text}"') % { :text => "{{auto_link_urls(ta.get_content)}}" } } |
57 | - } | |
59 | + }, | |
60 | + | |
61 | + :reply_scrap_on_self => { | |
62 | + :description => @reply_scrap_description | |
63 | + }, | |
58 | 64 | } |
59 | 65 | |
60 | 66 | ActionTrackerConfig.current_user_method = :current_person | ... | ... |
test/unit/person_test.rb
... | ... | @@ -1335,4 +1335,24 @@ class PersonTest < ActiveSupport::TestCase |
1335 | 1335 | assert_includes non_abusers, not_abuser |
1336 | 1336 | end |
1337 | 1337 | |
1338 | + should 'not list leave_scrap_to_self in activities' do | |
1339 | + person = fast_create(Person) | |
1340 | + at = ActionTracker::Record.create!(:user => person, :verb => 'leave_scrap_to_self') | |
1341 | + person.reload | |
1342 | + assert_equal person.activities, [] | |
1343 | + end | |
1344 | + | |
1345 | + should 'not list add_member_in_community in activities' do | |
1346 | + person = fast_create(Person) | |
1347 | + at = ActionTracker::Record.create!(:user => person, :verb => 'add_member_in_community') | |
1348 | + person.reload | |
1349 | + assert_equal person.activities, [] | |
1350 | + end | |
1351 | + | |
1352 | + should 'not list reply_scrap_on_self in activities' do | |
1353 | + person = fast_create(Person) | |
1354 | + at = ActionTracker::Record.create!(:user => person, :verb => 'reply_scrap_on_self') | |
1355 | + person.reload | |
1356 | + assert_equal person.activities, [] | |
1357 | + end | |
1338 | 1358 | end | ... | ... |
test/unit/scrap_test.rb
... | ... | @@ -232,6 +232,14 @@ class ScrapTest < ActiveSupport::TestCase |
232 | 232 | assert_equal s, s2.root |
233 | 233 | end |
234 | 234 | |
235 | + should "have the top_root defined" do | |
236 | + s = fast_create(Scrap) | |
237 | + s1 = fast_create(Scrap, :scrap_id => s.id) | |
238 | + s2 = fast_create(Scrap, :scrap_id => s1.id) | |
239 | + assert_equal s, s1.top_root | |
240 | + assert_equal s, s2.top_root | |
241 | + end | |
242 | + | |
235 | 243 | should 'strip all html tags' do |
236 | 244 | s, r = fast_create(Person), fast_create(Person) |
237 | 245 | s = Scrap.new :sender => s, :receiver => r, :content => "<p>Test <b>Rails</b></p>" |
... | ... | @@ -276,4 +284,14 @@ class ScrapTest < ActiveSupport::TestCase |
276 | 284 | assert_equal s.scrap_wall_url, s.receiver.wall_url |
277 | 285 | end |
278 | 286 | |
287 | + should 'create activity with reply_scrap_on_self when top_root scrap receiver is the same as sender' do | |
288 | + s, r = fast_create(Person), fast_create(Person) | |
289 | + root = fast_create(Scrap, :sender_id => s.id, :receiver_id => r.id) | |
290 | + assert_difference ActionTracker::Record, :count, 1 do | |
291 | + reply = Scrap.create!(:sender => r, :receiver => s, :scrap_id => root.id, :content => 'sample') | |
292 | + end | |
293 | + activity = ActionTracker::Record.last | |
294 | + assert_equal 'reply_scrap_on_self', activity.verb.to_s | |
295 | + end | |
296 | + | |
279 | 297 | end | ... | ... |