Commit a5c05d69 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Merge branch '345791-fj-use-linear-user-group-notifications-settings-finder' into 'master'

Use linear version UserGroupNotificationSettingsFinder#execute

See merge request gitlab-org/gitlab!74606
parents f3915fd9 4e006d3c
...@@ -8,7 +8,12 @@ class UserGroupNotificationSettingsFinder ...@@ -8,7 +8,12 @@ class UserGroupNotificationSettingsFinder
def execute def execute
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
groups_with_ancestors = Gitlab::ObjectHierarchy.new(Group.where(id: groups.select(:id))).base_and_ancestors selected_groups = Group.where(id: groups.select(:id))
groups_with_ancestors = if Feature.enabled?(:linear_user_group_notification_settings_finder_ancestors_scopes, user, default_enabled: :yaml)
selected_groups.self_and_ancestors
else
Gitlab::ObjectHierarchy.new(selected_groups).base_and_ancestors
end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
@loaded_groups_with_ancestors = groups_with_ancestors.index_by(&:id) @loaded_groups_with_ancestors = groups_with_ancestors.index_by(&:id)
......
---
name: linear_user_group_notification_settings_finder_ancestors_scopes
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/74606
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/345792
milestone: '14.6'
type: development
group: group::access
default_enabled: false
...@@ -11,14 +11,15 @@ RSpec.describe UserGroupNotificationSettingsFinder do ...@@ -11,14 +11,15 @@ RSpec.describe UserGroupNotificationSettingsFinder do
subject.map(&proc).uniq subject.map(&proc).uniq
end end
shared_examples 'user group notifications settings tests' do
context 'when the groups have no existing notification settings' do context 'when the groups have no existing notification settings' do
context 'when the groups have no ancestors' do context 'when the groups have no ancestors' do
let_it_be(:groups) { create_list(:group, 3) } let_it_be(:groups) { create_list(:group, 3) }
it 'will be a default Global notification setting', :aggregate_failures do it 'will be a default Global notification setting', :aggregate_failures do
expect(subject.count).to eq(3) expect(subject.count).to eq(3)
expect(attributes(&:notification_email)).to eq([nil]) expect(attributes(&:notification_email)).to match_array([nil])
expect(attributes(&:level)).to eq(['global']) expect(attributes(&:level)).to match_array(['global'])
end end
end end
...@@ -38,11 +39,11 @@ RSpec.describe UserGroupNotificationSettingsFinder do ...@@ -38,11 +39,11 @@ RSpec.describe UserGroupNotificationSettingsFinder do
end end
it 'has the same level set' do it 'has the same level set' do
expect(attributes(&:level)).to eq(['participating']) expect(attributes(&:level)).to match_array(['participating'])
end end
it 'has the same email set' do it 'has the same email set' do
expect(attributes(&:notification_email)).to eq(['ancestor@example.com']) expect(attributes(&:notification_email)).to match_array(['ancestor@example.com'])
end end
it 'only returns the two queried groups' do it 'only returns the two queried groups' do
...@@ -66,8 +67,8 @@ RSpec.describe UserGroupNotificationSettingsFinder do ...@@ -66,8 +67,8 @@ RSpec.describe UserGroupNotificationSettingsFinder do
it 'has the same email and level set', :aggregate_failures do it 'has the same email and level set', :aggregate_failures do
expect(subject.count).to eq(1) expect(subject.count).to eq(1)
expect(attributes(&:level)).to eq(['global']) expect(attributes(&:level)).to match_array(['global'])
expect(attributes(&:notification_email)).to eq(['ancestor@example.com']) expect(attributes(&:notification_email)).to match_array(['ancestor@example.com'])
end end
end end
...@@ -82,8 +83,8 @@ RSpec.describe UserGroupNotificationSettingsFinder do ...@@ -82,8 +83,8 @@ RSpec.describe UserGroupNotificationSettingsFinder do
it 'returns a default Global notification setting' do it 'returns a default Global notification setting' do
expect(subject.count).to eq(1) expect(subject.count).to eq(1)
expect(attributes(&:level)).to eq(['global']) expect(attributes(&:level)).to match_array(['global'])
expect(attributes(&:notification_email)).to eq([nil]) expect(attributes(&:notification_email)).to match_array([nil])
end end
end end
...@@ -103,8 +104,8 @@ RSpec.describe UserGroupNotificationSettingsFinder do ...@@ -103,8 +104,8 @@ RSpec.describe UserGroupNotificationSettingsFinder do
it 'still inherits the notification settings' do it 'still inherits the notification settings' do
expect(subject.count).to eq(1) expect(subject.count).to eq(1)
expect(attributes(&:level)).to eq(['participating']) expect(attributes(&:level)).to match_array(['participating'])
expect(attributes(&:notification_email)).to eq([ancestor_email.email]) expect(attributes(&:notification_email)).to match_array([ancestor_email.email])
end end
end end
...@@ -162,4 +163,15 @@ RSpec.describe UserGroupNotificationSettingsFinder do ...@@ -162,4 +163,15 @@ RSpec.describe UserGroupNotificationSettingsFinder do
end end
end end
end end
end
it_behaves_like 'user group notifications settings tests'
context 'when feature flag :linear_user_group_notification_settings_finder_ancestors_scopes is disabled' do
before do
stub_feature_flags(linear_user_group_notification_settings_finder_ancestors_scopes: false)
end
it_behaves_like 'user group notifications settings tests'
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment