Commit 09b90e89 authored by Valery Sizov's avatar Valery Sizov Committed by Sean McGivern

Fix GitLab Slack application configuration

parent bf495f36
...@@ -11,7 +11,18 @@ module Projects ...@@ -11,7 +11,18 @@ module Projects
@hook = ProjectHook.new @hook = ProjectHook.new
# Services # 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 end
end end
......
...@@ -795,10 +795,12 @@ class Project < ActiveRecord::Base ...@@ -795,10 +795,12 @@ class Project < ActiveRecord::Base
update_column(:has_external_wiki, services.external_wikis.any?) update_column(:has_external_wiki, services.external_wikis.any?)
end end
def find_or_initialize_services def find_or_initialize_services(exceptions: [])
services_templates = Service.where(template: true) 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) service = find_service(services, service_name)
if service if service
......
...@@ -246,6 +246,7 @@ class Service < ActiveRecord::Base ...@@ -246,6 +246,7 @@ class Service < ActiveRecord::Base
pushover pushover
redmine redmine
slack slack
slack_slash_commands
teamcity teamcity
microsoft_teams microsoft_teams
] ]
...@@ -253,14 +254,10 @@ class Service < ActiveRecord::Base ...@@ -253,14 +254,10 @@ class Service < ActiveRecord::Base
service_names += %w[mock_ci mock_deployment mock_monitoring] service_names += %w[mock_ci mock_deployment mock_monitoring]
end end
if show_gitlab_slack_application? if Gitlab.com? || Rails.env.development?
service_names.push('gitlab_slack_application') service_names.push('gitlab_slack_application')
end end
unless Gitlab.com?
service_names.push('slack_slash_commands')
end
service_names.sort_by(&:downcase) service_names.sort_by(&:downcase)
end end
...@@ -271,10 +268,6 @@ class Service < ActiveRecord::Base ...@@ -271,10 +268,6 @@ class Service < ActiveRecord::Base
service service
end end
def self.show_gitlab_slack_application?
(Gitlab.com? && current_application_settings.slack_app_enabled) || Rails.env.development?
end
private private
def cache_project_has_external_issue_tracker def cache_project_has_external_issue_tracker
......
...@@ -17,4 +17,27 @@ describe Projects::Settings::IntegrationsController do ...@@ -17,4 +17,27 @@ describe Projects::Settings::IntegrationsController do
expect(response).to render_template(:show) expect(response).to render_template(:show)
end end
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 end
...@@ -24,7 +24,7 @@ describe Projects::Settings::SlacksController do ...@@ -24,7 +24,7 @@ describe Projects::Settings::SlacksController do
.to receive(:new).with(project, user, anything).and_return(service) .to receive(:new).with(project, user, anything).and_return(service)
end 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) stub_service(status: :success)
get :slack_auth, namespace_id: project.namespace, project_id: project get :slack_auth, namespace_id: project.namespace, project_id: project
...@@ -34,7 +34,7 @@ describe Projects::Settings::SlacksController do ...@@ -34,7 +34,7 @@ describe Projects::Settings::SlacksController do
expect(flash[:alert]).to be_nil expect(flash[:alert]).to be_nil
end 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') stub_service(status: :error, message: 'error')
get :slack_auth, namespace_id: project.namespace, project_id: project get :slack_auth, namespace_id: project.namespace, project_id: project
......
...@@ -13,7 +13,7 @@ feature 'Slack application', feature: true do ...@@ -13,7 +13,7 @@ feature 'Slack application', feature: true do
create(:slack_integration, service: service) 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 end
scenario 'I can edit slack integration' do 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