Commit d2f57e9a authored by Etienne Baqué's avatar Etienne Baqué

Merge branch 'vij-cater-for-active-member' into 'master'

Handle members who are existing hierarchy members

See merge request gitlab-org/gitlab!76850
parents c2cf9777 c6ce9796
...@@ -148,6 +148,7 @@ module EE ...@@ -148,6 +148,7 @@ module EE
def set_membership_activation def set_membership_activation
return unless group return unless group
return if user && ::Member.in_hierarchy(group).with_user(user).with_state(:active).any?
self.state = ::Member::STATE_AWAITING if group.user_cap_reached? self.state = ::Member::STATE_AWAITING if group.user_cap_reached?
end end
......
...@@ -7,5 +7,11 @@ FactoryBot.modify do ...@@ -7,5 +7,11 @@ FactoryBot.modify do
member.wait member.wait
end end
end end
trait :active do
after(:create) do |member|
member.activate
end
end
end end
end end
...@@ -7,5 +7,11 @@ FactoryBot.modify do ...@@ -7,5 +7,11 @@ FactoryBot.modify do
member.wait member.wait
end end
end end
trait :active do
after(:create) do |member|
member.activate
end
end
end end
end end
...@@ -164,6 +164,7 @@ RSpec.describe Member, type: :model do ...@@ -164,6 +164,7 @@ RSpec.describe Member, type: :model do
namespace_settings: create(:namespace_settings, new_user_signups_cap: 1)) namespace_settings: create(:namespace_settings, new_user_signups_cap: 1))
end end
let_it_be(:subgroup) { create(:group, parent: group) }
let_it_be(:project, refind: true) { create(:project, namespace: group)} let_it_be(:project, refind: true) { create(:project, namespace: group)}
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
...@@ -220,8 +221,6 @@ RSpec.describe Member, type: :model do ...@@ -220,8 +221,6 @@ RSpec.describe Member, type: :model do
end end
it 'sets the group member to awaiting when added to a subgroup' do it 'sets the group member to awaiting when added to a subgroup' do
subgroup = create(:group, parent: group)
subgroup.add_developer(user) subgroup.add_developer(user)
expect(user.group_members.last).to be_awaiting expect(user.group_members.last).to be_awaiting
...@@ -232,6 +231,36 @@ RSpec.describe Member, type: :model do ...@@ -232,6 +231,36 @@ RSpec.describe Member, type: :model do
expect(user.project_members.last).to be_awaiting expect(user.project_members.last).to be_awaiting
end end
context 'when the user is already an active root group member' do
it 'sets the group member to active' do
create(:group_member, :active, group: group, user: user)
subgroup.add_owner(user)
expect(user.group_members.last).to be_active
end
end
context 'when the user is already an active subgroup member' do
it 'sets the group member to active' do
other_subgroup = create(:group, parent: group)
create(:group_member, :active, group: other_subgroup, user: user)
subgroup.add_developer(user)
expect(user.group_members.last).to be_active
end
end
context 'when the user is already an active project member' do
it 'sets the group member to active' do
create(:project_member, :active, project: project, user: user)
expect { subgroup.add_owner(user) }.to change { ::Member.with_state(:active).count }.by(1)
expect(user.group_members.last).to be_active
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