Commit 4e006d3c authored by Francisco Javier López's avatar Francisco Javier López Committed by Vitali Tatarintev

Use linear version UserGroupNotificationSettingsFinder#execute

parent 0f685998
......@@ -8,7 +8,12 @@ class UserGroupNotificationSettingsFinder
def execute
# 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
@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
subject.map(&proc).uniq
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 ancestors' do
let_it_be(:groups) { create_list(:group, 3) }
it 'will be a default Global notification setting', :aggregate_failures do
expect(subject.count).to eq(3)
expect(attributes(&:notification_email)).to eq([nil])
expect(attributes(&:level)).to eq(['global'])
expect(attributes(&:notification_email)).to match_array([nil])
expect(attributes(&:level)).to match_array(['global'])
end
end
......@@ -38,11 +39,11 @@ RSpec.describe UserGroupNotificationSettingsFinder do
end
it 'has the same level set' do
expect(attributes(&:level)).to eq(['participating'])
expect(attributes(&:level)).to match_array(['participating'])
end
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
it 'only returns the two queried groups' do
......@@ -66,8 +67,8 @@ RSpec.describe UserGroupNotificationSettingsFinder do
it 'has the same email and level set', :aggregate_failures do
expect(subject.count).to eq(1)
expect(attributes(&:level)).to eq(['global'])
expect(attributes(&:notification_email)).to eq(['ancestor@example.com'])
expect(attributes(&:level)).to match_array(['global'])
expect(attributes(&:notification_email)).to match_array(['ancestor@example.com'])
end
end
......@@ -82,8 +83,8 @@ RSpec.describe UserGroupNotificationSettingsFinder do
it 'returns a default Global notification setting' do
expect(subject.count).to eq(1)
expect(attributes(&:level)).to eq(['global'])
expect(attributes(&:notification_email)).to eq([nil])
expect(attributes(&:level)).to match_array(['global'])
expect(attributes(&:notification_email)).to match_array([nil])
end
end
......@@ -103,8 +104,8 @@ RSpec.describe UserGroupNotificationSettingsFinder do
it 'still inherits the notification settings' do
expect(subject.count).to eq(1)
expect(attributes(&:level)).to eq(['participating'])
expect(attributes(&:notification_email)).to eq([ancestor_email.email])
expect(attributes(&:level)).to match_array(['participating'])
expect(attributes(&:notification_email)).to match_array([ancestor_email.email])
end
end
......@@ -162,4 +163,15 @@ RSpec.describe UserGroupNotificationSettingsFinder do
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
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