Commit b1172cc1 authored by Arturo Herrero's avatar Arturo Herrero

Available services include project specific

This changes the default, available services include by default the
project specific services.
parent 0aee0030
......@@ -5,7 +5,7 @@ module Types
class ServiceTypeEnum < BaseEnum
graphql_name 'ServiceType'
::Service.available_services_types(include_project_specific: true, include_dev: false).each do |service_type|
::Service.available_services_types(include_dev: false).each do |service_type|
value service_type.underscore.upcase, value: service_type
end
end
......
......@@ -1341,7 +1341,7 @@ class Project < ApplicationRecord
end
def find_or_initialize_services
available_services_names = Service.available_services_names(include_project_specific: true) - disabled_services
available_services_names = Service.available_services_names - disabled_services
available_services_names.map do |service_name|
find_or_initialize_service(service_name)
......
......@@ -65,9 +65,9 @@ class Service < ApplicationRecord
scope :by_type, -> (type) { where(type: type) }
scope :by_active_flag, -> (flag) { where(active: flag) }
scope :inherit_from_id, -> (id) { where(inherit_from_id: id) }
scope :for_group, -> (group) { where(group_id: group, type: available_services_types) }
scope :for_template, -> { where(template: true, type: available_services_types) }
scope :for_instance, -> { where(instance: true, type: available_services_types) }
scope :for_group, -> (group) { where(group_id: group, type: available_services_types(include_project_specific: false)) }
scope :for_template, -> { where(template: true, type: available_services_types(include_project_specific: false)) }
scope :for_instance, -> { where(instance: true, type: available_services_types(include_project_specific: false)) }
scope :push_hooks, -> { where(push_events: true, active: true) }
scope :tag_push_hooks, -> { where(tag_push_events: true, active: true) }
......@@ -169,7 +169,7 @@ class Service < ApplicationRecord
private_class_method :create_nonexistent_templates
def self.find_or_initialize_integration(name, instance: false, group_id: nil)
if name.in?(available_services_names)
if name.in?(available_services_names(include_project_specific: false))
"#{name}_service".camelize.constantize.find_or_initialize_by(instance: instance, group_id: group_id)
end
end
......@@ -188,11 +188,11 @@ class Service < ApplicationRecord
def self.list_nonexistent_services_for(scope)
# Using #map instead of #pluck to save one query count. This is because
# ActiveRecord loaded the object here, so we don't need to query again later.
available_services_types - scope.map(&:type)
available_services_types(include_project_specific: false) - scope.map(&:type)
end
private_class_method :list_nonexistent_services_for
def self.available_services_names(include_project_specific: false, include_dev: true)
def self.available_services_names(include_project_specific: true, include_dev: true)
service_names = services_names
service_names += project_specific_services_names if include_project_specific
service_names += dev_services_names if include_dev
......@@ -214,7 +214,7 @@ class Service < ApplicationRecord
[]
end
def self.available_services_types(include_project_specific: false, include_dev: true)
def self.available_services_types(include_project_specific: true, include_dev: true)
available_services_names(include_project_specific: include_project_specific, include_dev: include_dev).map do |service_name|
"#{service_name}_service".camelize
end
......
......@@ -156,7 +156,7 @@ module Gitlab
underscored_service = matched_login['service'].underscore
if Service.available_services_names(include_project_specific: true).include?(underscored_service)
if Service.available_services_names.include?(underscored_service)
# We treat underscored_service as a trusted input because it is included
# in the Service.available_services_names allowlist.
service = project.public_send("#{underscored_service}_service") # rubocop:disable GitlabSecurity/PublicSend
......
......@@ -429,7 +429,7 @@ module Gitlab
def services_usage
# rubocop: disable UsageData/LargeTable:
Service.available_services_names(include_project_specific: true).each_with_object({}) do |service_name, response|
Service.available_services_names.each_with_object({}) do |service_name, response|
response["projects_#{service_name}_active".to_sym] = count(Service.active.where.not(project: nil).where(type: "#{service_name}_service".camelize))
response["groups_#{service_name}_active".to_sym] = count(Service.active.where.not(group: nil).where(type: "#{service_name}_service".camelize))
response["templates_#{service_name}_active".to_sym] = count(Service.active.where(template: true, type: "#{service_name}_service".camelize))
......
......@@ -46,7 +46,7 @@ RSpec.describe Groups::Settings::IntegrationsController do
describe '#edit' do
context 'when user is not owner' do
it 'renders not_found' do
get :edit, params: { group_id: group, id: Service.available_services_names.sample }
get :edit, params: { group_id: group, id: Service.available_services_names(include_project_specific: false).sample }
expect(response).to have_gitlab_http_status(:not_found)
end
......@@ -61,13 +61,13 @@ RSpec.describe Groups::Settings::IntegrationsController do
it 'returns not_found' do
stub_feature_flags(group_level_integrations: false)
get :edit, params: { group_id: group, id: Service.available_services_names.sample }
get :edit, params: { group_id: group, id: Service.available_services_names(include_project_specific: false).sample }
expect(response).to have_gitlab_http_status(:not_found)
end
end
Service.available_services_names.each do |integration_name|
Service.available_services_names(include_project_specific: false).each do |integration_name|
context "#{integration_name}" do
it 'successfully displays the template' do
get :edit, params: { group_id: group, id: integration_name }
......
......@@ -11,5 +11,5 @@ RSpec.describe GitlabSchema.types['ServiceType'] do
end
def available_services_enum
::Service.available_services_types(include_project_specific: true, include_dev: false).map(&:underscore).map(&:upcase)
::Service.available_services_types(include_dev: false).map(&:underscore).map(&:upcase)
end
......@@ -224,7 +224,7 @@ RSpec.describe Service do
describe '.find_or_initialize_all' do
shared_examples 'service instances' do
it 'returns the available service instances' do
expect(Service.find_or_initialize_all(Service.for_instance).pluck(:type)).to match_array(Service.available_services_types)
expect(Service.find_or_initialize_all(Service.for_instance).pluck(:type)).to match_array(Service.available_services_types(include_project_specific: false))
end
it 'does not create service instances' do
......@@ -237,7 +237,7 @@ RSpec.describe Service do
context 'with all existing instances' do
before do
Service.insert_all(
Service.available_services_types.map { |type| { instance: true, type: type } }
Service.available_services_types(include_project_specific: false).map { |type| { instance: true, type: type } }
)
end
......@@ -265,13 +265,13 @@ RSpec.describe Service do
describe 'template' do
shared_examples 'retrieves service templates' do
it 'returns the available service templates' do
expect(Service.find_or_create_templates.pluck(:type)).to match_array(Service.available_services_types)
expect(Service.find_or_create_templates.pluck(:type)).to match_array(Service.available_services_types(include_project_specific: false))
end
end
describe '.find_or_create_templates' do
it 'creates service templates' do
expect { Service.find_or_create_templates }.to change { Service.count }.from(0).to(Service.available_services_names.size)
expect { Service.find_or_create_templates }.to change { Service.count }.from(0).to(Service.available_services_names(include_project_specific: false).size)
end
it_behaves_like 'retrieves service templates'
......@@ -279,7 +279,7 @@ RSpec.describe Service do
context 'with all existing templates' do
before do
Service.insert_all(
Service.available_services_types.map { |type| { template: true, type: type } }
Service.available_services_types(include_project_specific: false).map { |type| { template: true, type: type } }
)
end
......@@ -305,7 +305,7 @@ RSpec.describe Service do
end
it 'creates the rest of the service templates' do
expect { Service.find_or_create_templates }.to change { Service.count }.from(1).to(Service.available_services_names.size)
expect { Service.find_or_create_templates }.to change { Service.count }.from(1).to(Service.available_services_names(include_project_specific: false).size)
end
it_behaves_like 'retrieves service templates'
......@@ -900,9 +900,9 @@ RSpec.describe Service do
end
it 'returns the available services names depending on the filters', :aggregate_failures do
expect(described_class.available_services_names).to eq(%w[asana prometheus pushover teamcity])
expect(described_class.available_services_names(include_project_specific: true, include_dev: false)).to eq(%w[assembla prometheus pushover teamcity])
expect(described_class.available_services_names(include_project_specific: true, include_dev: true)).to eq(%w[asana assembla prometheus pushover teamcity])
expect(described_class.available_services_names).to eq(%w[asana assembla prometheus pushover teamcity])
expect(described_class.available_services_names(include_project_specific: false)).to eq(%w[asana prometheus pushover teamcity])
expect(described_class.available_services_names(include_dev: false)).to eq(%w[assembla prometheus pushover teamcity])
end
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