Skip to content

Commit

Permalink
Merge pull request #17918 from yrudman/do-not-duplicate-same-notifica…
Browse files Browse the repository at this point in the history
…tion

Do not duplicate same notification if user belongs to several groups
  • Loading branch information
gtanzillo authored Sep 5, 2018
2 parents 1d98cbe + 7312c3a commit 26bf79c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/notification_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def subscriber_ids(subject, initiator)
subject.tenant
elsif initiator.kind_of?(User)
initiator.current_tenant
end.try(:user_ids)
end.try(:user_ids).try(:uniq)
when AUDIENCE_SUPERADMIN
User.superadmins.pluck(:id)
when AUDIENCE_NONE
Expand Down
5 changes: 5 additions & 0 deletions spec/models/notification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
expect(user.unseen_notifications.count).to eq(1)
end

it 'creates single record in notification_recipients table if recipent user belongs to several groups' do
user.miq_groups << FactoryGirl.create(:miq_group, :tenant => tenant)
expect(subject.recipients).to match_array([user])
end

context 'asynchronous notifications' do
before { stub_settings(:server => {:asynchronous_notifications => async}) }
context 'enabled' do
Expand Down
6 changes: 5 additions & 1 deletion spec/models/notification_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
end
end

describe '#subscribers' do
describe '#subscribers_ids' do
let(:user1) { FactoryGirl.create(:user) }
let(:tenant2) { FactoryGirl.create(:tenant) }
let!(:user2) { FactoryGirl.create(:user_with_group, :tenant => tenant2) }
Expand All @@ -38,6 +38,10 @@
it 'returns the users in the tenant same tenant as concerned vm' do
is_expected.to match_array([user2.id])
end
it "returns single id if user belongs to different group" do
user2.miq_groups << FactoryGirl.create(:miq_group, :tenant => tenant2)
is_expected.to match_array([user2.id])
end
end
end
end

0 comments on commit 26bf79c

Please sign in to comment.