Add latest changes from gitlab-org/gitlab@master
This commit is contained in:
parent
51d09c5698
commit
6c84e07376
|
@ -21,8 +21,8 @@ module API
|
||||||
end
|
end
|
||||||
params do
|
params do
|
||||||
requires :access_level, type: Integer, values: Gitlab::Access.all_values, desc: 'A valid access level (defaults: `30`, developer access level)'
|
requires :access_level, type: Integer, values: Gitlab::Access.all_values, desc: 'A valid access level (defaults: `30`, developer access level)'
|
||||||
optional :email, types: [String, Array[String]], email_or_email_list: true, desc: 'The email address to invite, or multiple emails separated by comma'
|
optional :email, type: Array[String], email_or_email_list: true, coerce_with: ::API::Validations::Types::CommaSeparatedToArray.coerce, desc: 'The email address to invite, or multiple emails separated by comma'
|
||||||
optional :user_id, types: [Integer, String], desc: 'The user ID of the new member or multiple IDs separated by commas.'
|
optional :user_id, type: Array[String], coerce_with: ::API::Validations::Types::CommaSeparatedToArray.coerce, 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'
|
optional :expires_at, type: DateTime, desc: 'Date string in the format YEAR-MONTH-DAY'
|
||||||
optional :invite_source, type: String, desc: 'Source that triggered the member creation process', default: 'invitations-api'
|
optional :invite_source, type: String, desc: 'Source that triggered the member creation process', default: 'invitations-api'
|
||||||
optional :tasks_to_be_done, type: Array[String], coerce_with: Validations::Types::CommaSeparatedToArray.coerce, desc: 'Tasks the inviter wants the member to do'
|
optional :tasks_to_be_done, type: Array[String], coerce_with: Validations::Types::CommaSeparatedToArray.coerce, desc: 'Tasks the inviter wants the member to do'
|
||||||
|
|
|
@ -9,7 +9,12 @@ module API
|
||||||
|
|
||||||
return unless value
|
return unless value
|
||||||
|
|
||||||
return if value.split(',').map { |v| ValidateEmail.valid?(v) }.all?
|
case value
|
||||||
|
when String
|
||||||
|
return if value.split(',').map { |v| ValidateEmail.valid?(v) }.all?
|
||||||
|
when Array
|
||||||
|
return if value.map { |v| ValidateEmail.valid?(v) }.all?
|
||||||
|
end
|
||||||
|
|
||||||
raise Grape::Exceptions::Validation.new(
|
raise Grape::Exceptions::Validation.new(
|
||||||
params: [@scope.full_name(attr_name)],
|
params: [@scope.full_name(attr_name)],
|
||||||
|
|
|
@ -14,6 +14,7 @@ RSpec.describe API::Validations::Validators::EmailOrEmailList do
|
||||||
expect_no_validation_error('test' => 'test@example.org')
|
expect_no_validation_error('test' => 'test@example.org')
|
||||||
expect_no_validation_error('test' => 'test1@example.com,test2@example.org')
|
expect_no_validation_error('test' => 'test1@example.com,test2@example.org')
|
||||||
expect_no_validation_error('test' => 'test1@example.com,test2@example.org,test3@example.co.uk')
|
expect_no_validation_error('test' => 'test1@example.com,test2@example.org,test3@example.co.uk')
|
||||||
|
expect_no_validation_error('test' => %w[test1@example.com test2@example.org test3@example.co.uk])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -23,6 +24,7 @@ RSpec.describe API::Validations::Validators::EmailOrEmailList do
|
||||||
expect_validation_error('test' => '@example.com')
|
expect_validation_error('test' => '@example.com')
|
||||||
expect_validation_error('test' => 'test1@example.com,asdf')
|
expect_validation_error('test' => 'test1@example.com,asdf')
|
||||||
expect_validation_error('test' => 'asdf,testa1@example.com,asdf')
|
expect_validation_error('test' => 'asdf,testa1@example.com,asdf')
|
||||||
|
expect_validation_error('test' => %w[asdf testa1@example.com asdf])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -347,6 +347,14 @@ RSpec.describe API::Invitations do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns 400 when the email list is not a valid format' do
|
it 'returns 400 when the email list is not a valid format' do
|
||||||
|
post invitations_url(source, maintainer),
|
||||||
|
params: { email: %w[email1@example.com not-an-email], access_level: Member::MAINTAINER }
|
||||||
|
|
||||||
|
expect(response).to have_gitlab_http_status(:bad_request)
|
||||||
|
expect(json_response['error']).to eq('email contains an invalid email address')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns 400 when the comma-separated email list is not a valid format' do
|
||||||
post invitations_url(source, maintainer),
|
post invitations_url(source, maintainer),
|
||||||
params: { email: 'email1@example.com,not-an-email', access_level: Member::MAINTAINER }
|
params: { email: 'email1@example.com,not-an-email', access_level: Member::MAINTAINER }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue