diff --git a/app/models/integration.rb b/app/models/integration.rb index 5ab70554a0c1ef3ec15000d2cac446934d4106f0..0cbe092d1409885e46e6e3afa35811ee157c6544 100644 --- a/app/models/integration.rb +++ b/app/models/integration.rb @@ -165,9 +165,13 @@ def self.boolean_accessor(*args) args.each do |arg| class_eval <<~RUBY, __FILE__, __LINE__ + 1 + def #{arg} + Gitlab::Utils.to_boolean(properties['#{arg}']) + end + def #{arg}? # '!!' is used because nil or empty string is converted to nil - !!ActiveRecord::Type::Boolean.new.cast(#{arg}) + !!#{arg} end RUBY end diff --git a/lib/api/entities/project_service.rb b/lib/api/entities/project_service.rb index 947cec1e3cd199c52f190ae4691a851970778568..07abf23660de71a159da7c3571556c45e4433c7e 100644 --- a/lib/api/entities/project_service.rb +++ b/lib/api/entities/project_service.rb @@ -6,10 +6,18 @@ class ProjectService < Entities::ProjectServiceBasic # Expose serialized properties expose :properties do |service, options| # TODO: Simplify as part of https://gitlab.com/gitlab-org/gitlab/issues/29404 - if service.data_fields_present? - service.data_fields.as_json.slice(*service.api_field_names) - else - service.properties.slice(*service.api_field_names) + + attributes = + if service.data_fields_present? + service.data_fields.as_json.keys + else + service.properties.keys + end + + attributes &= service.api_field_names + + attributes.each_with_object({}) do |attribute, hash| + hash[attribute] = service.public_send(attribute) # rubocop:disable GitlabSecurity/PublicSend end end end diff --git a/spec/requests/api/services_spec.rb b/spec/requests/api/services_spec.rb index 9e9c1e0252987a7fbd673e468af9d059edfab3c3..f4c0384a61b4276489e05dcff872395c7d23173e 100644 --- a/spec/requests/api/services_spec.rb +++ b/spec/requests/api/services_spec.rb @@ -338,4 +338,26 @@ def deactive_service! expect(response).to have_gitlab_http_status(:ok) end end + + describe 'Pipelines Email Integration' do + let(:service_name) { 'pipelines-email' } + + context 'notify_only_broken_pipelines property was saved as a string' do + before do + project.create_pipelines_email_integration( + active: false, + properties: { + "notify_only_broken_pipelines": "true", + "branches_to_be_notified": "default" + } + ) + end + + it 'returns boolean values for notify_only_broken_pipelines' do + get api("/projects/#{project.id}/services/#{service_name}", user) + + expect(json_response['properties']['notify_only_broken_pipelines']).to eq(true) + end + end + end end