Update members service to cope with errors
This commit is contained in:
parent
b49563c39f
commit
c75687b519
3 changed files with 26 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Resolve UI bug adding group members with lower permissions
|
||||
merge_request: 24820
|
||||
author:
|
||||
type: fixed
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue