Commit e1c73a69 authored by James Fargher's avatar James Fargher

Merge branch 'service-clean-up' into 'master'

Clean code: Refactor and improve code related to services

See merge request gitlab-org/gitlab!28230
parents 00c62397 ae484e90
......@@ -3,23 +3,12 @@
module Projects
module Settings
class IntegrationsController < Projects::ApplicationController
include ServiceParams
before_action :authorize_admin_project!
layout "project_settings"
def show
@services = @project.find_or_initialize_services(exceptions: service_exceptions)
end
private
# Returns a list of services that should be hidden from the list
def service_exceptions
@project.disabled_services.dup
@services = @project.find_or_initialize_services
end
end
end
end
Projects::Settings::IntegrationsController.prepend_if_ee('EE::Projects::Settings::IntegrationsController')
......@@ -1238,14 +1238,12 @@ class Project < ApplicationRecord
update_column(:has_external_wiki, services.external_wikis.any?) if Gitlab::Database.read_write?
end
def find_or_initialize_services(exceptions: [])
available_services_names = Service.available_services_names - exceptions
def find_or_initialize_services
available_services_names = Service.available_services_names - disabled_services
available_services = available_services_names.map do |service_name|
available_services_names.map do |service_name|
find_or_initialize_service(service_name)
end
available_services.compact
end
def disabled_services
......@@ -1258,13 +1256,11 @@ class Project < ApplicationRecord
service = find_service(services, name)
return service if service
# We should check if template for the service exists
template = find_service(services_templates, name)
if template
Service.build_from_template(id, template)
else
# If no template, we should create an instance. Ex `build_gitlab_ci_service`
public_send("build_#{name}_service") # rubocop:disable GitlabSecurity/PublicSend
end
end
......@@ -1278,10 +1274,6 @@ class Project < ApplicationRecord
end
# rubocop: enable CodeReuse/ServiceClass
def find_service(list, name)
list.find { |service| service.to_param == name }
end
def ci_services
services.where(category: :ci)
end
......@@ -2422,6 +2414,10 @@ class Project < ApplicationRecord
private
def find_service(services, name)
services.find { |service| service.to_param == name }
end
def closest_namespace_setting(name)
namespace.closest_setting(name)
end
......
......@@ -348,7 +348,7 @@ class Service < ApplicationRecord
service.template = false
service.project_id = project_id
service.active = false if service.active? && !service.valid?
service.active = false if service.active? && service.invalid?
service
end
......
# frozen_string_literal: true
module EE
module Projects
module Settings
module IntegrationsController
extend ::Gitlab::Utils::Override
private
override :service_exceptions
def service_exceptions
super << slack_service
end
def slack_service
if ::Gitlab::CurrentSettings.slack_app_enabled
'slack_slash_commands'
else
'gitlab_slack_application'
end
end
end
end
end
end
......@@ -537,6 +537,7 @@ module EE
[].tap do |services|
services.push('jenkins', 'jenkins_deprecated') unless feature_available?(:jenkins_integration)
services.push('github') unless feature_available?(:github_project_service_integration)
::Gitlab::CurrentSettings.slack_app_enabled ? services.push('slack_slash_commands') : services.push('gitlab_slack_application')
end
end
end
......
......@@ -16,6 +16,7 @@ describe 'Slack application' do
create(:slack_integration, service: service)
allow(Gitlab).to receive(:com?).and_return(true)
allow(Gitlab::CurrentSettings).to receive(:slack_app_enabled).and_return(true)
end
it 'I can edit slack integration' do
......
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