diff --git a/app/models/community.rb b/app/models/community.rb index bd4cfdf..ae25d85 100644 --- a/app/models/community.rb +++ b/app/models/community.rb @@ -80,7 +80,7 @@ class Community < Organization 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.target_id = #{self.id} ORDER BY updated_at DESC") + Scrap.find_by_sql("SELECT id, updated_at, 'Scrap' AS klass FROM scraps WHERE scraps.receiver_id = #{self.id} AND scraps.scrap_id IS NULL UNION SELECT id, updated_at, 'ActionTracker::Record' AS klass FROM action_tracker WHERE action_tracker.target_id = #{self.id} UNION SELECT action_tracker.id, action_tracker.updated_at, 'ActionTracker::Record' AS klass FROM action_tracker INNER JOIN articles ON action_tracker.target_id = articles.id WHERE articles.profile_id = #{self.id} AND action_tracker.target_type = 'Article' ORDER BY action_tracker.updated_at DESC") end end diff --git a/lib/notify_activity_to_profiles_job.rb b/lib/notify_activity_to_profiles_job.rb index 1409161..39dd451 100644 --- a/lib/notify_activity_to_profiles_job.rb +++ b/lib/notify_activity_to_profiles_job.rb @@ -1,12 +1,10 @@ class NotifyActivityToProfilesJob < Struct.new(:tracked_action_id) NOTIFY_ONLY_COMMUNITY = [ 'add_member_in_community', - 'remove_member_in_community', ] NOT_NOTIFY_COMMUNITY = [ 'join_community', - 'leave_community', ] def perform return unless ActionTracker::Record.exists?(tracked_action_id) diff --git a/test/unit/community_test.rb b/test/unit/community_test.rb index 917fc6f..ac8175d 100644 --- a/test/unit/community_test.rb +++ b/test/unit/community_test.rb @@ -274,22 +274,19 @@ class CommunityTest < ActiveSupport::TestCase end end - should "be created an tracked action to the community when an community's article is commented" do + should "update the action of article creation when an community's article is commented" do ActionTrackerNotification.delete_all p1 = Person.first community = fast_create(Community) p2 = fast_create(Person) p3 = fast_create(Person) community.add_member(p3) - article = fast_create(Article, :profile_id => community.id) - ActionTracker::Record.destroy_all - assert_difference(ActionTrackerNotification, :count, 3) do - Comment.create!(:article_id => article.id, :title => 'some', :body => 'some', :author_id => p2.id) - process_delayed_job_queue - end - ActionTrackerNotification.all.map{|a|a.profile}.map do |profile| - assert [community,p1,p3].include?(profile) - end + article = create(TextileArticle, :profile_id => community.id) + time = article.activity.updated_at + Time.stubs(:now).returns(time + 1.day) + Comment.create!(:source_id => article.id, :title => 'some', :body => 'some', :author_id => p2.id) + process_delayed_job_queue + assert_equal time, article.activity.updated_at end should "see get all received scraps" do @@ -348,34 +345,28 @@ class CommunityTest < ActiveSupport::TestCase scrap = Scrap.create!(defaults_for_scrap(:sender => person, :receiver => community, :content => 'A scrap')) activity = ActionTracker::Record.last - assert_equal 'An article about free software', activity.get_name.last - assert_equal [scrap,activity], person.activities.map { |a| a.klass.constantize.find(a.id) } + assert_equal [scrap], community.activities.map { |a| a.klass.constantize.find(a.id) } end - should 'return tracked_actions as activities' do + should 'return tracked_actions of community as activities' do person = fast_create(Person) - another_person = fast_create(Person) + community = fast_create(Community) - scrap = Scrap.create!(defaults_for_scrap(:sender => another_person, :receiver => person, :content => 'A scrap')) UserStampSweeper.any_instance.expects(:current_user).returns(person).at_least_once - TinyMceArticle.create!(:profile => person, :name => 'An article about free software') - activity = ActionTracker::Record.last + article = create(TinyMceArticle, :profile => community, :name => 'An article about free software') - assert_equal 'An article about free software', activity.get_name.last - assert_equal [scrap,activity], person.activities.map { |a| a.klass.constantize.find(a.id) } + assert_equal [article.activity], community.activities.map { |a| a.klass.constantize.find(a.id) } end - should 'return articles published on communities as activities' do + should 'not return tracked_actions of other community as activities' do person = fast_create(Person) - another_person = fast_create(Person) + community = fast_create(Community) + community2 = fast_create(Community) - scrap = Scrap.create!(defaults_for_scrap(:sender => another_person, :receiver => person, :content => 'A scrap')) UserStampSweeper.any_instance.expects(:current_user).returns(person).at_least_once - TinyMceArticle.create!(:profile => person, :name => 'An article about free software') - activity = ActionTracker::Record.last + article = create(TinyMceArticle, :profile => community2, :name => 'Another article about free software') - assert_equal 'An article about free software', activity.get_name.last - assert_equal [scrap,activity], person.activities.map { |a| a.klass.constantize.find(a.id) } + assert_not_includes community.activities.map { |a| a.klass.constantize.find(a.id) }, article.activity end end diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index 747b94d..3dfd59e 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -1013,65 +1013,14 @@ class PersonTest < ActiveSupport::TestCase assert has_add_member_notification end - should 'track only one action when a person leaves a community' do + should 'not track when a person leaves a community' do p = create_user('test_user').person c = fast_create(Community, :name => "Foo") c.add_member(p) c.add_moderator(p) ActionTracker::Record.delete_all c.remove_member(p) - assert_equal ["Foo"], ActionTracker::Record.last(:conditions => {:verb => 'leave_community'}).get_resource_name - end - - should 'the tracker target be Community when a person leaves a community' do - ActionTracker::Record.delete_all - p = create_user('test_user').person - c = fast_create(Community, :name => "Foo") - c.add_member(p) - c.add_moderator(p) - ActionTracker::Record.delete_all - c.remove_member(p) - assert_kind_of Community, ActionTracker::Record.last(:conditions => {:verb => 'leave_community'}).target - end - - should 'the community be notified specifically when a person leaves a community' do - ActionTracker::Record.delete_all - p = create_user('test_user').person - c = fast_create(Community, :name => "Foo") - c.add_member(p) - c.add_moderator(p) - ActionTracker::Record.delete_all - c.remove_member(p) - assert_not_nil ActionTracker::Record.last(:conditions => {:verb => 'remove_member_in_community'}) - end - - should 'the community specific notification created when a member leaves community could not be propagated to members' do - ActionTracker::Record.delete_all - p1 = Person.first - p2 = create_user('test_user').person - p3 = create_user('test_user').person - c = fast_create(Community, :name => "Foo") - process_delayed_job_queue - Delayed::Job.delete_all - c.add_member(p1) - c.add_member(p3) - c.add_moderator(p1) - c.add_moderator(p3) - ActionTracker::Record.delete_all - c.remove_member(p1) - process_delayed_job_queue - c.remove_member(p3) - process_delayed_job_queue - assert_equal 4, ActionTracker::Record.count - assert_equal 5, ActionTrackerNotification.count - has_remove_member_notification = false - ActionTrackerNotification.all.map do |notification| - if notification.action_tracker.verb == 'remove_member_in_community' - has_remove_member_notification = true - assert_equal c, notification.profile - end - end - assert has_remove_member_notification + assert_equal [], ActionTracker::Record.all end should 'get all friends online' do @@ -1250,11 +1199,9 @@ class PersonTest < ActiveSupport::TestCase scrap = Scrap.create!(defaults_for_scrap(:sender => another_person, :receiver => person, :content => 'A scrap')) UserStampSweeper.any_instance.expects(:current_user).returns(person).at_least_once - TinyMceArticle.create!(:profile => person, :name => 'An article about free software') - activity = ActionTracker::Record.last + article = TinyMceArticle.create!(:profile => person, :name => 'An article about free software') - assert_equal 'An article about free software', activity.get_name.last - assert_equal [scrap,activity], person.activities.map { |a| a.klass.constantize.find(a.id) } + assert_equal [scrap,article.activity], person.activities.map { |a| a.klass.constantize.find(a.id) } end should 'not return tracked_actions and scraps from others as activities' do diff --git a/test/unit/tiny_mce_article_test.rb b/test/unit/tiny_mce_article_test.rb index a480074..f2f48a7 100644 --- a/test/unit/tiny_mce_article_test.rb +++ b/test/unit/tiny_mce_article_test.rb @@ -134,80 +134,64 @@ class TinyMceArticleTest < ActiveSupport::TestCase assert_equal 1, ActionTracker::Record.count end - should 'notify with different trackers activity create with different targets' do + should 'not group trackers activity of article\'s creation' do ActionTracker::Record.delete_all profile = fast_create(Profile) TinyMceArticle.create! :name => 'bar', :profile_id => profile.id, :published => true TinyMceArticle.create! :name => 'another bar', :profile_id => profile.id, :published => true - assert_equal 1, ActionTracker::Record.count - TinyMceArticle.create! :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true assert_equal 2, ActionTracker::Record.count + TinyMceArticle.create! :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true + assert_equal 3, ActionTracker::Record.count end - should 'notify activity on update' do + should 'update activity on update of an article' do ActionTracker::Record.delete_all - a = TinyMceArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true - assert_equal 1, ActionTracker::Record.count - a.name = 'foo' - a.save! - assert_equal 2, ActionTracker::Record.count + profile = fast_create(Profile) + article = create(TextileArticle, :profile_id => profile.id) + time = article.activity.updated_at + Time.stubs(:now).returns(time + 1.day) + assert_no_difference ActionTracker::Record, :count do + article.name = 'foo' + article.save! + end + assert_equal time + 1.day, article.activity.updated_at end - should 'notify with different trackers activity update with different targets' do + should 'not create trackers activity when updating articles' do ActionTracker::Record.delete_all a1 = TinyMceArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true a2 = TinyMceArticle.create! :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true - assert_equal 2, ActionTracker::Record.count - a1.name = 'foo' - a1.save! - assert_equal 3, ActionTracker::Record.count - a2.name = 'another foo' - a2.save! - assert_equal 4, ActionTracker::Record.count + assert_no_difference ActionTracker::Record, :count do + a1.name = 'foo';a1.save! + a2.name = 'another foo';a2.save! + end end - should 'notify activity on destroy' do - ActionTracker::Record.delete_all - a = TinyMceArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true - assert_equal 1, ActionTracker::Record.count - a.destroy - assert_equal 2, ActionTracker::Record.count - end - - should 'notify different activities when destroy articles with diferrents targets' do + should 'not notify when an article is destroyed' do ActionTracker::Record.delete_all a1 = TinyMceArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true a2 = TinyMceArticle.create! :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true - assert_equal 2, ActionTracker::Record.count - a1.destroy - assert_equal 3, ActionTracker::Record.count - a2.destroy - assert_equal 4, ActionTracker::Record.count + assert_no_difference ActionTracker::Record, :count do + a1.destroy + a2.destroy +end end - should "the tracker action target be defined as Community by custom_target method on articles'creation in communities" do + should "the tracker action target be defined as the article on articles'creation in communities" do ActionTracker::Record.delete_all community = fast_create(Community) p1 = Person.first community.add_member(p1) assert p1.is_member_of?(community) article = TinyMceArticle.create! :name => 'test', :profile_id => community.id - assert_equal true, article.published? - assert_equal true, article.notifiable? - assert_equal false, article.image? - assert_equal Community, article.profile.class - assert_equal Community, ActionTracker::Record.last.target.class + assert_equal article, ActionTracker::Record.last.target end - should "the tracker action target be defined as person by custom_target method on articles'creation in profile" do + should "the tracker action target be defined as the article on articles'creation in profile" do ActionTracker::Record.delete_all person = Person.first article = TinyMceArticle.create! :name => 'test', :profile_id => person.id - assert_equal true, article.published? - assert_equal true, article.notifiable? - assert_equal false, article.image? - assert_equal Person, article.profile.class - assert_equal person, ActionTracker::Record.last.target + assert_equal article, ActionTracker::Record.last.target end should 'not notify activity if the article is not advertise' do diff --git a/vendor/plugins/access_control/lib/role_assignment.rb b/vendor/plugins/access_control/lib/role_assignment.rb index 34ac5f1..c55d692 100644 --- a/vendor/plugins/access_control/lib/role_assignment.rb +++ b/vendor/plugins/access_control/lib/role_assignment.rb @@ -9,10 +9,6 @@ class RoleAssignment < ActiveRecord::Base track_actions :add_member_in_community, :after_create, :if => Proc.new { |x| x.resource.is_a?(Community) && x.accessor.role_assignments.count(:conditions => { :resource_id => x.resource.id, :resource_type => 'Profile' }) == 1 }, :custom_user => :accessor, :custom_target => :resource - track_actions :leave_community, :before_destroy, :keep_params => ["resource.name", "resource.url", "resource.profile_custom_icon"], :if => Proc.new { |x| x.resource.is_a?(Community) && x.accessor.role_assignments.count(:conditions => { :resource_id => x.resource.id, :resource_type => 'Profile' }) == 1 }, :custom_user => :accessor, :custom_target => :resource - - track_actions :remove_member_in_community, :before_destroy, :if => Proc.new { |x| x.resource.is_a?(Community) && x.accessor.role_assignments.count(:conditions => { :resource_id => x.resource.id, :resource_type => 'Profile' }) == 1 }, :custom_target => :resource, :custom_user => :accessor - def has_permission?(perm, res) return false unless role.has_permission?(perm.to_s) && (resource || is_global) return true if is_global -- libgit2 0.21.2