Commit d74a9d99 authored by Vijay Hawoldar's avatar Vijay Hawoldar

Handle members who are existing hierarchy members

When adding a new member record for a user who is
already an active member of the hierarchy, they should
be added in active state too

Changelog: changed
EE: true
parent bdee564d
......@@ -148,6 +148,7 @@ module EE
def set_membership_activation
return unless group
return if user && ::Member.in_hierarchy(group.root_ancestor).with_user(user).with_state(:active).limit(1).any?
self.state = ::Member::STATE_AWAITING if group.user_cap_reached?
end
......
......@@ -7,5 +7,11 @@ FactoryBot.modify do
member.wait
end
end
trait :active do
after(:create) do |member|
member.activate
end
end
end
end
......@@ -7,5 +7,11 @@ FactoryBot.modify do
member.wait
end
end
trait :active do
after(:create) do |member|
member.activate
end
end
end
end
......@@ -164,6 +164,7 @@ RSpec.describe Member, type: :model do
namespace_settings: create(:namespace_settings, new_user_signups_cap: 1))
end
let_it_be(:subgroup) { create(:group, parent: group) }
let_it_be(:project, refind: true) { create(:project, namespace: group)}
let_it_be(:user) { create(:user) }
......@@ -220,8 +221,6 @@ RSpec.describe Member, type: :model do
end
it 'sets the group member to awaiting when added to a subgroup' do
subgroup = create(:group, parent: group)
subgroup.add_developer(user)
expect(user.group_members.last).to be_awaiting
......@@ -232,6 +231,24 @@ RSpec.describe Member, type: :model do
expect(user.project_members.last).to be_awaiting
end
context 'when the user is already an active 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 project member' do
it 'sets the group member to active' do
create(:project_member, :active, project: project, user: user)
subgroup.add_owner(user)
expect(user.group_members.last).to be_active
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