diff options
author | Sean McGivern <sean@gitlab.com> | 2019-02-04 11:47:19 +0300 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2019-02-04 11:47:19 +0300 |
commit | 200ebab1cf8a41585c94a15bcc37547abd73bc80 (patch) | |
tree | 6012aabc74d7ea825cfb49494cf6bcc04481a45a | |
parent | 34908dd28447b831a31a4340076f3d494c80e531 (diff) | |
parent | c75687b51924a481dd05cf00f9fc28a3d8fd7735 (diff) |
Merge branch '55098-ui-bug-adding-group-members-with-lower-permissions' into 'master'
Resolve "UI bug adding group members with lower permissions"
Closes #55098
See merge request gitlab-org/gitlab-ce!24820
3 files changed, 26 insertions, 2 deletions
diff --git a/app/services/members/create_service.rb b/app/services/members/create_service.rb index 714b8586737..cf710fef52b 100644 --- a/app/services/members/create_service.rb +++ b/app/services/members/create_service.rb @@ -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 diff --git a/changelogs/unreleased/55098-ui-bug-adding-group-members-with-lower-permissions.yml b/changelogs/unreleased/55098-ui-bug-adding-group-members-with-lower-permissions.yml new file mode 100644 index 00000000000..f22524ef4b2 --- /dev/null +++ b/changelogs/unreleased/55098-ui-bug-adding-group-members-with-lower-permissions.yml @@ -0,0 +1,5 @@ +--- +title: Resolve UI bug adding group members with lower permissions +merge_request: 24820 +author: +type: fixed diff --git a/spec/services/members/create_service_spec.rb b/spec/services/members/create_service_spec.rb index 5c01463d757..3bc05182932 100644 --- a/spec/services/members/create_service_spec.rb +++ b/spec/services/members/create_service_spec.rb @@ -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 |