Commit c75687b5 authored by James Lopez's avatar James Lopez

Update members service to cope with errors

parent b49563c3
......@@ -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
......
---
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
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