Commit 80b40c8c authored by Corinna Wiesner's avatar Corinna Wiesner

Add feature flag to highest role callback

Put the update highest role callback for Members behind a feature flag
because there needs to be an additional callback when a User does not
count as active anymore.
parent e419699c
...@@ -468,6 +468,7 @@ class Member < ApplicationRecord ...@@ -468,6 +468,7 @@ class Member < ApplicationRecord
# for a Member to be commited before attempting to update the highest role. # for a Member to be commited before attempting to update the highest role.
# rubocop: disable CodeReuse/ServiceClass # rubocop: disable CodeReuse/ServiceClass
def update_highest_role def update_highest_role
return unless Feature.enabled?(:highest_role_callback)
return unless user_id.present? return unless user_id.present?
return unless previous_changes[:access_level].present? return unless previous_changes[:access_level].present?
......
...@@ -586,49 +586,97 @@ describe Member do ...@@ -586,49 +586,97 @@ describe Member do
end end
context 'when after_commit :update_highest_role' do context 'when after_commit :update_highest_role' do
where(:member_type, :source_type) do context 'with feature flag enabled' do
:project_member | :project where(:member_type, :source_type) do
:group_member | :group :project_member | :project
end :group_member | :group
end
with_them do with_them do
describe 'create member' do describe 'create member' do
it 'initializes a new Members::UpdateHighestRoleService object' do it 'initializes a new Members::UpdateHighestRoleService object' do
source = create(source_type) # source owner initializes a new service object too source = create(source_type) # source owner initializes a new service object too
user = create(:user) user = create(:user)
expect(Members::UpdateHighestRoleService).to receive(:new).with(user.id).and_call_original expect(Members::UpdateHighestRoleService).to receive(:new).with(user.id).and_call_original
create(member_type, :guest, user: user, source_type => source) create(member_type, :guest, user: user, source_type => source)
end
end end
end
context 'when member exists' do context 'when member exists' do
let!(:member) { create(member_type) } let!(:member) { create(member_type) }
describe 'update member' do
context 'when access level was changed' do
it 'initializes a new Members::UpdateHighestRoleService object' do
expect(Members::UpdateHighestRoleService).to receive(:new).with(member.user_id).and_call_original
member.update(access_level: Gitlab::Access::GUEST)
end
end
context 'when access level was not changed' do
it 'does not initialize a new Members::UpdateHighestRoleService object' do
expect(Members::UpdateHighestRoleService).not_to receive(:new).with(member.user_id)
member.update(notification_level: NotificationSetting.levels[:disabled])
end
end
end
describe 'update member' do describe 'destroy member' do
context 'when access level was changed' do
it 'initializes a new Members::UpdateHighestRoleService object' do it 'initializes a new Members::UpdateHighestRoleService object' do
expect(Members::UpdateHighestRoleService).to receive(:new).with(member.user_id).and_call_original expect(Members::UpdateHighestRoleService).to receive(:new).with(member.user_id).and_call_original
member.update(access_level: Gitlab::Access::GUEST) member.destroy
end end
end end
end
end
end
context 'when access level was not changed' do context 'with feature flag disabled' do
it 'does not initialize a new Members::UpdateHighestRoleService object' do before do
expect(Members::UpdateHighestRoleService).not_to receive(:new).with(member.user_id) stub_feature_flags(highest_role_callback: false)
end
member.update(notification_level: NotificationSetting.levels[:disabled]) where(:member_type, :source_type) do
end :project_member | :project
:group_member | :group
end
with_them do
describe 'create member' do
it 'does not initialize a new Members::UpdateHighestRoleService object' do
source = create(source_type)
user = create(:user)
expect(Members::UpdateHighestRoleService).not_to receive(:new).with(user.id)
create(member_type, :guest, user: user, source_type => source)
end end
end end
describe 'destroy member' do context 'when member exists' do
it 'initializes a new Members::UpdateHighestRoleService object' do let!(:member) { create(member_type) }
expect(Members::UpdateHighestRoleService).to receive(:new).with(member.user_id).and_call_original
member.destroy describe 'update member' do
context 'when access level was changed' do
it 'does not initialize a new Members::UpdateHighestRoleService object' do
expect(Members::UpdateHighestRoleService).not_to receive(:new).with(member.user_id)
member.update(access_level: Gitlab::Access::GUEST)
end
end
end
describe 'destroy member' do
it 'does not initialize a new Members::UpdateHighestRoleService object' do
expect(Members::UpdateHighestRoleService).not_to receive(:new).with(member.user_id)
member.destroy
end
end end
end 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