Commit 5913a7aa authored by Sean McGivern's avatar Sean McGivern

Merge branch 'gitlab_app_fixes' into 'master'

Fix GitLab Slack application configuration

See merge request !2392
parents 48cda4b3 09b90e89
......@@ -11,7 +11,18 @@ module Projects
@hook = ProjectHook.new
# Services
@services = @project.find_or_initialize_services
@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
if current_application_settings.slack_app_enabled
['slack_slash_commands']
else
['gitlab_slack_application']
end
end
end
end
......
......@@ -795,10 +795,12 @@ class Project < ActiveRecord::Base
update_column(:has_external_wiki, services.external_wikis.any?)
end
def find_or_initialize_services
def find_or_initialize_services(exceptions: [])
services_templates = Service.where(template: true)
Service.available_services_names.map do |service_name|
available_services_names = Service.available_services_names - exceptions
available_services_names.map do |service_name|
service = find_service(services, service_name)
if service
......
......@@ -246,6 +246,7 @@ class Service < ActiveRecord::Base
pushover
redmine
slack
slack_slash_commands
teamcity
microsoft_teams
]
......@@ -253,14 +254,10 @@ class Service < ActiveRecord::Base
service_names += %w[mock_ci mock_deployment mock_monitoring]
end
if show_gitlab_slack_application?
if Gitlab.com? || Rails.env.development?
service_names.push('gitlab_slack_application')
end
unless Gitlab.com?
service_names.push('slack_slash_commands')
end
service_names.sort_by(&:downcase)
end
......@@ -271,10 +268,6 @@ class Service < ActiveRecord::Base
service
end
def self.show_gitlab_slack_application?
(Gitlab.com? && current_application_settings.slack_app_enabled) || Rails.env.development?
end
private
def cache_project_has_external_issue_tracker
......
......@@ -17,4 +17,27 @@ describe Projects::Settings::IntegrationsController do
expect(response).to render_template(:show)
end
end
context 'Sets correct services list' do
it 'enables SlackSlashCommandsService and disables GitlabSlackApplication' do
get :show, namespace_id: project.namespace, project_id: project
services = assigns(:services).map(&:type)
expect(services).to include('SlackSlashCommandsService')
expect(services).not_to include('GitlabSlackApplicationService')
end
it 'enables GitlabSlackApplication and disables SlackSlashCommandsService' do
stub_application_setting(slack_app_enabled: true)
allow(::Gitlab).to receive(:com?).and_return(true)
get :show, namespace_id: project.namespace, project_id: project
services = assigns(:services).map(&:type)
expect(services).to include('GitlabSlackApplicationService')
expect(services).not_to include('SlackSlashCommandsService')
end
end
end
......@@ -24,7 +24,7 @@ describe Projects::Settings::SlacksController do
.to receive(:new).with(project, user, anything).and_return(service)
end
it 'calls service and redirects with no flash message if result is successful' do
it 'calls service and redirects with no alerts if result is successful' do
stub_service(status: :success)
get :slack_auth, namespace_id: project.namespace, project_id: project
......@@ -34,7 +34,7 @@ describe Projects::Settings::SlacksController do
expect(flash[:alert]).to be_nil
end
it 'calls service and redirects with flash message if there is error' do
it 'calls service and redirects with the alert if there is error' do
stub_service(status: :error, message: 'error')
get :slack_auth, namespace_id: project.namespace, project_id: project
......
......@@ -13,7 +13,7 @@ feature 'Slack application', feature: true do
create(:slack_integration, service: service)
allow(Service).to receive(:show_gitlab_slack_application?).and_return(true)
allow(Gitlab).to receive(:com?).and_return(true)
end
scenario '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