diff --git a/lib/notify_activity_to_profiles_job.rb b/lib/notify_activity_to_profiles_job.rb index 4e2400c..8360844 100644 --- a/lib/notify_activity_to_profiles_job.rb +++ b/lib/notify_activity_to_profiles_job.rb @@ -10,7 +10,7 @@ class NotifyActivityToProfilesJob < Struct.new(:tracked_action_id) return unless ActionTracker::Record.exists?(tracked_action_id) tracked_action = ActionTracker::Record.find(tracked_action_id) target = tracked_action.target - if target.is_a?(Community) && NOTIFY_ONLY_COMMUNITY.include?(tracked_action.verb) + if target.is_a?(Community) && ( NOTIFY_ONLY_COMMUNITY.include?(tracked_action.verb) || ! target.public_profile ) ActionTrackerNotification.create(:profile_id => target.id, :action_tracker_id => tracked_action.id) return end diff --git a/test/unit/notify_activity_to_profiles_job_test.rb b/test/unit/notify_activity_to_profiles_job_test.rb index aacaa14..b065082 100644 --- a/test/unit/notify_activity_to_profiles_job_test.rb +++ b/test/unit/notify_activity_to_profiles_job_test.rb @@ -88,6 +88,31 @@ class NotifyActivityToProfilesJobTest < ActiveSupport::TestCase end end + should 'notify only the community if it is private' do + person = fast_create(Person) + private_community = fast_create(Community, :public_profile => false) + action_tracker = fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => person.id, :target_type => 'Profile', :target_id => private_community.id, :verb => 'create_article') + assert !NotifyActivityToProfilesJob::NOTIFY_ONLY_COMMUNITY.include?(action_tracker.verb) + p1, p2, m1, m2 = fast_create(Person), fast_create(Person), fast_create(Person), fast_create(Person) + fast_create(Friendship, :person_id => person.id, :friend_id => p1.id) + fast_create(Friendship, :person_id => person.id, :friend_id => p2.id) + fast_create(RoleAssignment, :accessor_id => m1.id, :role_id => 3, :resource_id => private_community.id) + fast_create(RoleAssignment, :accessor_id => m2.id, :role_id => 3, :resource_id => private_community.id) + ActionTrackerNotification.delete_all + job = NotifyActivityToProfilesJob.new(action_tracker.id) + job.perform + process_delayed_job_queue + + assert_equal 1, ActionTrackerNotification.count + [person, p1, p2, m1, m2].each do |profile| + notification = ActionTrackerNotification.find_by_profile_id profile.id + assert notification.nil? + end + + notification = ActionTrackerNotification.find_by_profile_id private_community.id + assert_equal action_tracker, notification.action_tracker + end + should 'not notify the community tracking join_community verb' do person = fast_create(Person) community = fast_create(Community) -- libgit2 0.21.2