Commit 55d3ff1a authored by Nikola Milojevic's avatar Nikola Milojevic

Merge branch '330300-cleanup' into 'master'

Clean up temporary code

See merge request gitlab-org/gitlab!65769
parents b3658f2c b3fd1372
...@@ -41,6 +41,5 @@ class Projects::MattermostsController < Projects::ApplicationController ...@@ -41,6 +41,5 @@ class Projects::MattermostsController < Projects::ApplicationController
def integration def integration
@integration ||= @project.find_or_initialize_integration('mattermost_slash_commands') @integration ||= @project.find_or_initialize_integration('mattermost_slash_commands')
@service = @integration # TODO: remove when https://gitlab.com/gitlab-org/gitlab/-/issues/330300 is complete
end end
end end
...@@ -16,6 +16,5 @@ class Projects::ServiceHookLogsController < Projects::HookLogsController ...@@ -16,6 +16,5 @@ class Projects::ServiceHookLogsController < Projects::HookLogsController
def integration def integration
@integration ||= @project.find_or_initialize_integration(params[:service_id]) @integration ||= @project.find_or_initialize_integration(params[:service_id])
@service = @integration # TODO: remove when https://gitlab.com/gitlab-org/gitlab/-/issues/330300 is complete
end end
end end
...@@ -112,7 +112,7 @@ class Projects::ServicesController < Projects::ApplicationController ...@@ -112,7 +112,7 @@ class Projects::ServicesController < Projects::ApplicationController
return if !integration.is_a?(::Integrations::Prometheus) || !Feature.enabled?(:settings_operations_prometheus_service, project) return if !integration.is_a?(::Integrations::Prometheus) || !Feature.enabled?(:settings_operations_prometheus_service, project)
operations_link_start = "<a href=\"#{project_settings_operations_path(project)}\">" operations_link_start = "<a href=\"#{project_settings_operations_path(project)}\">"
message = s_('PrometheusService|You can now manage your Prometheus settings on the %{operations_link_start}Operations%{operations_link_end} page. Fields on this page has been deprecated.') % { operations_link_start: operations_link_start, operations_link_end: "</a>" } message = s_('PrometheusService|You can now manage your Prometheus settings on the %{operations_link_start}Operations%{operations_link_end} page. Fields on this page have been deprecated.') % { operations_link_start: operations_link_start, operations_link_end: "</a>" }
flash.now[:alert] = message.html_safe flash.now[:alert] = message.html_safe
end end
end end
...@@ -15,4 +15,4 @@ ...@@ -15,4 +15,4 @@
and try again. and try again.
%hr %hr
.clearfix .clearfix
= link_to 'Go back', edit_project_service_path(@project, @service), class: 'gl-button btn btn-lg float-right' = link_to 'Go back', edit_project_service_path(@project, @integration), class: 'gl-button btn btn-lg float-right'
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
This service will be installed on the Mattermost instance at This service will be installed on the Mattermost instance at
%strong= link_to Gitlab.config.mattermost.host, Gitlab.config.mattermost.host %strong= link_to Gitlab.config.mattermost.host, Gitlab.config.mattermost.host
%hr %hr
= form_for(:mattermost, method: :post, url: project_mattermost_path(@project), html: { class: 'js-requires-input'} ) do |f| = form_for(:mattermost, method: :post, url: project_mattermost_path(@project), html: { class: 'js-requires-input' }) do |f|
%h4 Team %h4 Team
%p %p
= @teams.one? ? 'The team' : 'Select the team' = @teams.one? ? 'The team' : 'Select the team'
...@@ -42,5 +42,5 @@ ...@@ -42,5 +42,5 @@
%hr %hr
.clearfix .clearfix
.float-right .float-right
= link_to 'Cancel', edit_project_service_path(@project, @service), class: 'gl-button btn btn-lg' = link_to 'Cancel', edit_project_service_path(@project, @integration), class: 'gl-button btn btn-lg'
= f.submit 'Install', class: 'gl-button btn btn-success btn-lg' = f.submit 'Install', class: 'gl-button btn btn-success btn-lg'
...@@ -26414,7 +26414,7 @@ msgstr "" ...@@ -26414,7 +26414,7 @@ msgstr ""
msgid "PrometheusService|Waiting for your first deployment to an environment to find common metrics" msgid "PrometheusService|Waiting for your first deployment to an environment to find common metrics"
msgstr "" msgstr ""
msgid "PrometheusService|You can now manage your Prometheus settings on the %{operations_link_start}Operations%{operations_link_end} page. Fields on this page has been deprecated." msgid "PrometheusService|You can now manage your Prometheus settings on the %{operations_link_start}Operations%{operations_link_end} page. Fields on this page have been deprecated."
msgstr "" msgstr ""
msgid "PrometheusService|You have a cluster with the Prometheus integration enabled." msgid "PrometheusService|You have a cluster with the Prometheus integration enabled."
......
...@@ -8,9 +8,10 @@ RSpec.describe Projects::ServicesController do ...@@ -8,9 +8,10 @@ RSpec.describe Projects::ServicesController do
let_it_be(:project) { create(:project, :repository) } let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let_it_be(:service) { create(:jira_integration, project: project) } let_it_be(:jira_integration) { create(:jira_integration, project: project) }
let(:service_params) { { username: 'username', password: 'password', url: 'http://example.com' } } let(:integration) { jira_integration }
let(:integration_params) { { username: 'username', password: 'password', url: 'http://example.com' } }
before do before do
sign_in(user) sign_in(user)
...@@ -29,10 +30,10 @@ RSpec.describe Projects::ServicesController do ...@@ -29,10 +30,10 @@ RSpec.describe Projects::ServicesController do
end end
context 'when validations fail' do context 'when validations fail' do
let(:service_params) { { active: 'true', url: '' } } let(:integration_params) { { active: 'true', url: '' } }
it 'returns error messages in JSON response' do it 'returns error messages in JSON response' do
put :test, params: project_params(service: service_params) put :test, params: project_params(service: integration_params)
expect(json_response['message']).to eq 'Validations failed.' expect(json_response['message']).to eq 'Validations failed.'
expect(json_response['service_response']).to include "Url can't be blank" expect(json_response['service_response']).to include "Url can't be blank"
...@@ -40,12 +41,14 @@ RSpec.describe Projects::ServicesController do ...@@ -40,12 +41,14 @@ RSpec.describe Projects::ServicesController do
end end
end end
context 'success' do context 'when successful' do
context 'with empty project' do context 'with empty project' do
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
context 'with chat notification service' do context 'with chat notification integration' do
let_it_be(:service) { project.create_microsoft_teams_integration(webhook: 'http://webhook.com') } let_it_be(:teams_integration) { project.create_microsoft_teams_integration(webhook: 'http://webhook.com') }
let(:integration) { teams_integration }
it 'returns success' do it 'returns success' do
allow_next(::MicrosoftTeams::Notifier).to receive(:ping).and_return(true) allow_next(::MicrosoftTeams::Notifier).to receive(:ping).and_return(true)
...@@ -61,7 +64,7 @@ RSpec.describe Projects::ServicesController do ...@@ -61,7 +64,7 @@ RSpec.describe Projects::ServicesController do
expect(Gitlab::HTTP).to receive(:get).with('/rest/api/2/serverInfo', any_args).and_call_original expect(Gitlab::HTTP).to receive(:get).with('/rest/api/2/serverInfo', any_args).and_call_original
put :test, params: project_params(service: service_params) put :test, params: project_params(service: integration_params)
expect(response).to be_successful expect(response).to be_successful
end end
...@@ -72,13 +75,13 @@ RSpec.describe Projects::ServicesController do ...@@ -72,13 +75,13 @@ RSpec.describe Projects::ServicesController do
expect(Gitlab::HTTP).to receive(:get).with('/rest/api/2/serverInfo', any_args).and_call_original expect(Gitlab::HTTP).to receive(:get).with('/rest/api/2/serverInfo', any_args).and_call_original
put :test, params: project_params(service: service_params) put :test, params: project_params(service: integration_params)
expect(response).to be_successful expect(response).to be_successful
end end
context 'when service is configured for the first time' do context 'when service is configured for the first time' do
let(:service_params) do let(:integration_params) do
{ {
'active' => '1', 'active' => '1',
'push_events' => '1', 'push_events' => '1',
...@@ -109,17 +112,17 @@ RSpec.describe Projects::ServicesController do ...@@ -109,17 +112,17 @@ RSpec.describe Projects::ServicesController do
def do_put def do_put
put :test, params: project_params(id: 'buildkite', put :test, params: project_params(id: 'buildkite',
service: service_params) service: integration_params)
end end
end end
end end
context 'failure' do context 'when unsuccessful' do
it 'returns an error response when the integration test fails' do it 'returns an error response when the integration test fails' do
stub_request(:get, 'http://example.com/rest/api/2/serverInfo') stub_request(:get, 'http://example.com/rest/api/2/serverInfo')
.to_return(status: 404) .to_return(status: 404)
put :test, params: project_params(service: service_params) put :test, params: project_params(service: integration_params)
expect(response).to be_successful expect(response).to be_successful
expect(json_response).to eq( expect(json_response).to eq(
...@@ -132,7 +135,6 @@ RSpec.describe Projects::ServicesController do ...@@ -132,7 +135,6 @@ RSpec.describe Projects::ServicesController do
context 'with the Slack integration' do context 'with the Slack integration' do
let_it_be(:integration) { build(:integrations_slack) } let_it_be(:integration) { build(:integrations_slack) }
let_it_be(:service) { integration } # TODO: remove when https://gitlab.com/gitlab-org/gitlab/-/issues/330300 is complete
it 'returns an error response when the URL is blocked' do it 'returns an error response when the URL is blocked' do
put :test, params: project_params(service: { webhook: 'http://127.0.0.1' }) put :test, params: project_params(service: { webhook: 'http://127.0.0.1' })
...@@ -165,17 +167,17 @@ RSpec.describe Projects::ServicesController do ...@@ -165,17 +167,17 @@ RSpec.describe Projects::ServicesController do
describe 'PUT #update' do describe 'PUT #update' do
describe 'as HTML' do describe 'as HTML' do
let(:service_params) { { active: true } } let(:integration_params) { { active: true } }
let(:params) { project_params(service: service_params) } let(:params) { project_params(service: integration_params) }
let(:message) { 'Jira settings saved and active.' } let(:message) { 'Jira settings saved and active.' }
let(:redirect_url) { edit_project_service_path(project, service) } let(:redirect_url) { edit_project_service_path(project, integration) }
before do before do
put :update, params: params put :update, params: params
end end
shared_examples 'service update' do shared_examples 'integration update' do
it 'redirects to the correct url with a flash message' do it 'redirects to the correct url with a flash message' do
expect(response).to redirect_to(redirect_url) expect(response).to redirect_to(redirect_url)
expect(flash[:notice]).to eq(message) expect(flash[:notice]).to eq(message)
...@@ -183,49 +185,49 @@ RSpec.describe Projects::ServicesController do ...@@ -183,49 +185,49 @@ RSpec.describe Projects::ServicesController do
end end
context 'when param `active` is set to true' do context 'when param `active` is set to true' do
let(:params) { project_params(service: service_params, redirect_to: redirect) } let(:params) { project_params(service: integration_params, redirect_to: redirect) }
context 'when redirect_to param is present' do context 'when redirect_to param is present' do
let(:redirect) { '/redirect_here' } let(:redirect) { '/redirect_here' }
let(:redirect_url) { redirect } let(:redirect_url) { redirect }
it_behaves_like 'service update' it_behaves_like 'integration update'
end end
context 'when redirect_to is an external domain' do context 'when redirect_to is an external domain' do
let(:redirect) { 'http://examle.com' } let(:redirect) { 'http://examle.com' }
it_behaves_like 'service update' it_behaves_like 'integration update'
end end
context 'when redirect_to param is an empty string' do context 'when redirect_to param is an empty string' do
let(:redirect) { '' } let(:redirect) { '' }
it_behaves_like 'service update' it_behaves_like 'integration update'
end end
end end
context 'when param `active` is set to false' do context 'when param `active` is set to false' do
let(:service_params) { { active: false } } let(:integration_params) { { active: false } }
let(:message) { 'Jira settings saved, but not active.' } let(:message) { 'Jira settings saved, but not active.' }
it_behaves_like 'service update' it_behaves_like 'integration update'
end end
context 'when param `inherit_from_id` is set to empty string' do context 'when param `inherit_from_id` is set to empty string' do
let(:service_params) { { inherit_from_id: '' } } let(:integration_params) { { inherit_from_id: '' } }
it 'sets inherit_from_id to nil' do it 'sets inherit_from_id to nil' do
expect(service.reload.inherit_from_id).to eq(nil) expect(integration.reload.inherit_from_id).to eq(nil)
end end
end end
context 'when param `inherit_from_id` is set to some value' do context 'when param `inherit_from_id` is set to some value' do
let(:instance_service) { create(:jira_integration, :instance) } let(:instance_service) { create(:jira_integration, :instance) }
let(:service_params) { { inherit_from_id: instance_service.id } } let(:integration_params) { { inherit_from_id: instance_service.id } }
it 'sets inherit_from_id to value' do it 'sets inherit_from_id to value' do
expect(service.reload.inherit_from_id).to eq(instance_service.id) expect(integration.reload.inherit_from_id).to eq(instance_service.id)
end end
end end
end end
...@@ -233,11 +235,11 @@ RSpec.describe Projects::ServicesController do ...@@ -233,11 +235,11 @@ RSpec.describe Projects::ServicesController do
describe 'as JSON' do describe 'as JSON' do
before do before do
stub_jira_integration_test stub_jira_integration_test
put :update, params: project_params(service: service_params, format: :json) put :update, params: project_params(service: integration_params, format: :json)
end end
context 'when update succeeds' do context 'when update succeeds' do
let(:service_params) { { url: 'http://example.com' } } let(:integration_params) { { url: 'http://example.com' } }
it 'returns JSON response with no errors' do it 'returns JSON response with no errors' do
expect(response).to be_successful expect(response).to be_successful
...@@ -246,60 +248,67 @@ RSpec.describe Projects::ServicesController do ...@@ -246,60 +248,67 @@ RSpec.describe Projects::ServicesController do
end end
context 'when update fails' do context 'when update fails' do
let(:service_params) { { url: '' } } let(:integration_params) { { url: '' } }
it 'returns JSON response with errors' do it 'returns JSON response with errors' do
expect(response).to have_gitlab_http_status(:unprocessable_entity) expect(response).to have_gitlab_http_status(:unprocessable_entity)
expect(json_response).to include( expect(json_response).to include(
'active' => true, 'active' => true,
'errors' => { 'url' => ['must be a valid URL', %{can't be blank}] } 'errors' => { 'url' => ['must be a valid URL', %(can't be blank)] }
) )
end end
end end
end end
context 'Prometheus integration' do context 'with Prometheus integration' do
let_it_be(:service) { create(:prometheus_integration, project: project) } let_it_be(:prometheus_integration) { create(:prometheus_integration, project: project) }
let(:service_params) { { manual_configuration: '1', api_url: 'http://example.com' } } let(:integration) { prometheus_integration }
let(:integration_params) { { manual_configuration: '1', api_url: 'http://example.com' } }
context 'feature flag :settings_operations_prometheus_service is enabled' do context 'when feature flag :settings_operations_prometheus_service is enabled' do
before do before do
stub_feature_flags(settings_operations_prometheus_service: true) stub_feature_flags(settings_operations_prometheus_service: true)
end end
it 'redirects user back to edit page with alert' do it 'redirects user back to edit page with alert' do
put :update, params: project_params.merge(service: service_params) put :update, params: project_params.merge(service: integration_params)
expect(response).to redirect_to(edit_project_service_path(project, service)) expect(response).to redirect_to(edit_project_service_path(project, integration))
expected_alert = "You can now manage your Prometheus settings on the <a href=\"#{project_settings_operations_path(project)}\">Operations</a> page. Fields on this page has been deprecated." expected_alert = [
"You can now manage your Prometheus settings on the",
%(<a href="#{project_settings_operations_path(project)}">Operations</a> page.),
"Fields on this page have been deprecated."
].join(' ')
expect(controller).to set_flash.now[:alert].to(expected_alert) expect(controller).to set_flash.now[:alert].to(expected_alert)
end end
it 'does not modify integration' do it 'does not modify integration' do
expect { put :update, params: project_params.merge(service: service_params) }.not_to change { project.prometheus_integration.reload.attributes } expect { put :update, params: project_params.merge(service: integration_params) }
.not_to change { project.prometheus_integration.reload.attributes }
end end
end end
context 'feature flag :settings_operations_prometheus_service is disabled' do context 'when feature flag :settings_operations_prometheus_service is disabled' do
before do before do
stub_feature_flags(settings_operations_prometheus_service: false) stub_feature_flags(settings_operations_prometheus_service: false)
end end
it 'modifies integration' do it 'modifies integration' do
expect { put :update, params: project_params.merge(service: service_params) }.to change { project.prometheus_integration.reload.attributes } expect { put :update, params: project_params.merge(service: integration_params) }
.to change { project.prometheus_integration.reload.attributes }
end end
end end
end end
end end
describe 'GET #edit' do describe 'GET #edit' do
context 'Jira service' do context 'with Jira service' do
let(:service_param) { 'jira' } let(:integration_param) { 'jira' }
before do before do
get :edit, params: project_params(id: service_param) get :edit, params: project_params(id: integration_param)
end end
context 'with approved services' do context 'with approved services' do
...@@ -309,25 +318,30 @@ RSpec.describe Projects::ServicesController do ...@@ -309,25 +318,30 @@ RSpec.describe Projects::ServicesController do
end end
end end
context 'Prometheus service' do context 'with Prometheus service' do
let(:service_param) { 'prometheus' } let(:integration_param) { 'prometheus' }
context 'feature flag :settings_operations_prometheus_service is enabled' do context 'when feature flag :settings_operations_prometheus_service is enabled' do
before do before do
stub_feature_flags(settings_operations_prometheus_service: true) stub_feature_flags(settings_operations_prometheus_service: true)
get :edit, params: project_params(id: service_param) get :edit, params: project_params(id: integration_param)
end end
it 'renders deprecation warning notice' do it 'renders deprecation warning notice' do
expected_alert = "You can now manage your Prometheus settings on the <a href=\"#{project_settings_operations_path(project)}\">Operations</a> page. Fields on this page has been deprecated." expected_alert = [
"You can now manage your Prometheus settings on the",
%(<a href="#{project_settings_operations_path(project)}">Operations</a> page.),
"Fields on this page have been deprecated."
].join(' ')
expect(controller).to set_flash.now[:alert].to(expected_alert) expect(controller).to set_flash.now[:alert].to(expected_alert)
end end
end end
context 'feature flag :settings_operations_prometheus_service is disabled' do context 'when feature flag :settings_operations_prometheus_service is disabled' do
before do before do
stub_feature_flags(settings_operations_prometheus_service: false) stub_feature_flags(settings_operations_prometheus_service: false)
get :edit, params: project_params(id: service_param) get :edit, params: project_params(id: integration_param)
end end
it 'does not render deprecation warning notice' do it 'does not render deprecation warning notice' do
...@@ -343,7 +357,7 @@ RSpec.describe Projects::ServicesController do ...@@ -343,7 +357,7 @@ RSpec.describe Projects::ServicesController do
opts.reverse_merge( opts.reverse_merge(
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
id: service.to_param id: integration.to_param
) )
end end
end end
...@@ -17,6 +17,6 @@ RSpec.describe 'User activates Prometheus' do ...@@ -17,6 +17,6 @@ RSpec.describe 'User activates Prometheus' do
click_button('Save changes') click_button('Save changes')
expect(page).not_to have_content('Prometheus settings saved and active.') expect(page).not_to have_content('Prometheus settings saved and active.')
expect(page).to have_content('Fields on this page has been deprecated.') expect(page).to have_content('Fields on this page have been deprecated.')
end end
end end
...@@ -217,8 +217,6 @@ RSpec.describe Banzai::Filter::References::ExternalIssueReferenceFilter do ...@@ -217,8 +217,6 @@ RSpec.describe Banzai::Filter::References::ExternalIssueReferenceFilter do
context "ewm project" do context "ewm project" do
let_it_be(:integration) { create(:ewm_integration, project: project) } let_it_be(:integration) { create(:ewm_integration, project: project) }
let(:service) { integration } # TODO: remove when https://gitlab.com/gitlab-org/gitlab/-/issues/330300 is complete
before do before do
project.update!(issues_enabled: false) project.update!(issues_enabled: false)
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