Update members service to cope with errors

This commit is contained in:
James Lopez 2019-01-31 10:51:29 +01:00
parent b49563c39f
commit c75687b519
No known key found for this signature in database
GPG key ID: 756BF8E9D7C0CF39
3 changed files with 26 additions and 2 deletions

View file

@ -19,9 +19,19 @@ module Members
current_user: current_user
)
members.each { |member| after_execute(member: member) }
errors = []
success
members.each do |member|
if member.errors.any?
errors << "#{member.user.username}: #{member.errors.full_messages.to_sentence}"
else
after_execute(member: member)
end
end
return success unless errors.any?
error(errors.to_sentence)
end
private

View file

@ -0,0 +1,5 @@
---
title: Resolve UI bug adding group members with lower permissions
merge_request: 24820
author:
type: fixed

View file

@ -36,4 +36,13 @@ describe Members::CreateService do
expect(result[:message]).to be_present
expect(project.users).not_to include project_user
end
it 'does not add an invalid member' do
params = { user_ids: project_user.id.to_s, access_level: -1 }
result = described_class.new(user, params).execute(project)
expect(result[:status]).to eq(:error)
expect(result[:message]).to include(project_user.username)
expect(project.users).not_to include project_user
end
end