Commit f1640616 authored by Stan Hu's avatar Stan Hu

Fix Error 500 when inviting user already present

A project admin attempting to invite an already-invited user
will see a confusing Error 500 message.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/61574
parent 712dccd4
...@@ -23,7 +23,16 @@ module Members ...@@ -23,7 +23,16 @@ module Members
members.each do |member| members.each do |member|
if member.errors.any? if member.errors.any?
errors << "#{member.user.username}: #{member.errors.full_messages.to_sentence}" current_error =
# Invited users may not have an associated user
if member.user.present?
"#{member.user.username}: "
else
""
end
current_error += member.errors.full_messages.to_sentence
errors << current_error
else else
after_execute(member: member) after_execute(member: member)
end end
......
---
title: Fix Error 500 when inviting user already present
merge_request: 28198
author:
type: fixed
...@@ -44,7 +44,18 @@ describe Members::CreateService do ...@@ -44,7 +44,18 @@ describe Members::CreateService do
result = described_class.new(user, params).execute(project) result = described_class.new(user, params).execute(project)
expect(result[:status]).to eq(:error) expect(result[:status]).to eq(:error)
expect(result[:message]).to include(project_user.username) expect(result[:message]).to include("#{project_user.username}: Access level is not included in the list")
expect(project.users).not_to include project_user expect(project.users).not_to include project_user
end end
it 'does not add a member with an existing invite' do
invited_member = create(:project_member, :invited, project: project)
params = { user_ids: invited_member.invite_email,
access_level: Gitlab::Access::GUEST }
result = described_class.new(user, params).execute(project)
expect(result[:status]).to eq(:error)
expect(result[:message]).to eq('Invite email has already been taken')
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