Commit 0fe0e436 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'onboarding-issues-invite-users-backend' into 'master'

Onboarding issues invite teammates - backend

See merge request gitlab-org/gitlab!38169
parents d9983961 3c95bfe2
...@@ -15,6 +15,8 @@ module Registrations ...@@ -15,6 +15,8 @@ module Registrations
@group = Groups::CreateService.new(current_user, group_params).execute @group = Groups::CreateService.new(current_user, group_params).execute
if @group.persisted? if @group.persisted?
invite_teammates
redirect_to new_users_sign_up_project_path(namespace_id: @group.id) redirect_to new_users_sign_up_project_path(namespace_id: @group.id)
else else
render action: :new render action: :new
...@@ -31,8 +33,21 @@ module Registrations ...@@ -31,8 +33,21 @@ module Registrations
access_denied! unless experiment_enabled?(:onboarding_issues) access_denied! unless experiment_enabled?(:onboarding_issues)
end end
def invite_teammates
invite_params = {
user_ids: emails_param[:emails].reject(&:blank?).join(','),
access_level: Gitlab::Access::DEVELOPER
}
Members::CreateService.new(current_user, invite_params).execute(@group)
end
def group_params def group_params
params.require(:group).permit(:name, :path, :visibility_level) params.require(:group).permit(:name, :path, :visibility_level)
end end
def emails_param
params.require(:group).permit(emails: [])
end
end end
end end
...@@ -48,7 +48,7 @@ RSpec.describe Registrations::GroupsController do ...@@ -48,7 +48,7 @@ RSpec.describe Registrations::GroupsController do
describe 'POST #create' do describe 'POST #create' do
subject { post :create, params: { group: params } } subject { post :create, params: { group: params } }
let(:params) { { name: 'Group name', path: 'group-path', visibility_level: Gitlab::VisibilityLevel::PRIVATE } } let(:params) { { name: 'Group name', path: 'group-path', visibility_level: Gitlab::VisibilityLevel::PRIVATE, emails: ['', ''] } }
context 'with an unauthenticated user' do context 'with an unauthenticated user' do
it { is_expected.to have_gitlab_http_status(:redirect) } it { is_expected.to have_gitlab_http_status(:redirect) }
...@@ -68,6 +68,46 @@ RSpec.describe Registrations::GroupsController do ...@@ -68,6 +68,46 @@ RSpec.describe Registrations::GroupsController do
it { is_expected.to have_gitlab_http_status(:redirect) } it { is_expected.to have_gitlab_http_status(:redirect) }
it { is_expected.to redirect_to(new_users_sign_up_project_path(namespace_id: user.groups.last.id)) } it { is_expected.to redirect_to(new_users_sign_up_project_path(namespace_id: user.groups.last.id)) }
context 'inviting teammates' do
context 'with no valid emails in the params' do
it 'does not add teammates' do
expect { subject }.to change(Member, :count).by(1)
end
it 'does not call the Members::CreateService' do
expect(Members::CreateService).not_to receive(:new)
end
end
context 'with valid emails in the params' do
before do
params[:emails] = ['a@a.a', 'b@b.b', '', '', 'x', 'y']
end
it 'adds users with developer access and ignores blank emails' do
expect_next_instance_of(Group) do |group|
expect(group).to receive(:add_users).with(
['a@a.a', 'b@b.b', 'x', 'y'],
Gitlab::Access::DEVELOPER,
expires_at: nil,
current_user: user
).and_call_original
end
subject
end
it 'sends invitations to valid emails only' do
subject
emails = assigns(:group).members.pluck(:invite_email)
expect(emails).to include('a@a.a', 'b@b.b')
expect(emails).not_to include('x', 'y')
end
end
end
context 'when the group cannot be saved' do context 'when the group cannot be saved' do
let(:params) { { name: '', path: '' } } let(:params) { { name: '', path: '' } }
......
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