diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /lib/api/members.rb | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'lib/api/members.rb')
-rw-r--r-- | lib/api/members.rb | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/lib/api/members.rb b/lib/api/members.rb index 4edf94c6350..c28b3b1cc7c 100644 --- a/lib/api/members.rb +++ b/lib/api/members.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module API - class Members < Grape::API::Instance + class Members < ::API::Base include PaginationParams before { authenticate! } @@ -88,8 +88,8 @@ module API success Entities::Member end params do - requires :user_id, type: Integer, desc: 'The user ID of the new member' requires :access_level, type: Integer, desc: 'A valid access level (defaults: `30`, developer access level)' + requires :user_id, types: [Integer, String], desc: 'The user ID of the new member or multiple IDs separated by commas.' optional :expires_at, type: DateTime, desc: 'Date string in the format YEAR-MONTH-DAY' end # rubocop: disable CodeReuse/ActiveRecord @@ -97,20 +97,26 @@ module API source = find_source(source_type, params[:id]) authorize_admin_source!(source_type, source) - member = source.members.find_by(user_id: params[:user_id]) - conflict!('Member already exists') if member + if params[:user_id].to_s.include?(',') + create_service_params = params.except(:user_id).merge({ user_ids: params[:user_id] }) - user = User.find_by_id(params[:user_id]) - not_found!('User') unless user + ::Members::CreateService.new(current_user, create_service_params).execute(source) + elsif params[:user_id].present? + member = source.members.find_by(user_id: params[:user_id]) + conflict!('Member already exists') if member - member = create_member(current_user, user, source, params) + user = User.find_by_id(params[:user_id]) + not_found!('User') unless user - if !member - not_allowed! # This currently can only be reached in EE - elsif member.valid? && member.persisted? - present_members(member) - else - render_validation_error!(member) + member = create_member(current_user, user, source, params) + + if !member + not_allowed! # This currently can only be reached in EE + elsif member.valid? && member.persisted? + present_members(member) + else + render_validation_error!(member) + end end end # rubocop: enable CodeReuse/ActiveRecord |