Commit b504b297 authored by Alex Kalderimis's avatar Alex Kalderimis

Merge branch 'remove_service_templates_#325659' into 'master'

Removed code for service templates

See merge request gitlab-org/gitlab!64975
parents 9fdc576c 359813b6
......@@ -7,7 +7,6 @@ const PERSISTENT_USER_CALLOUTS = [
'.js-buy-pipeline-minutes-notification-callout',
'.js-token-expiry-callout',
'.js-registration-enabled-callout',
'.js-service-templates-deprecated-callout',
'.js-new-user-signups-cap-reached',
'.js-eoa-bronze-plan-banner',
];
......
# frozen_string_literal: true
class Admin::ServicesController < Admin::ApplicationController
include Integrations::Params
before_action :integration, only: [:edit, :update]
before_action :disable_query_limiting, only: [:index]
feature_category :integrations
def index
@activated_services = Integration.for_template.active.sort_by(&:title)
@existing_instance_types = Integration.for_instance.pluck(:type) # rubocop: disable CodeReuse/ActiveRecord
end
def edit
if integration.nil? || Integration.instance_exists_for?(integration.type)
redirect_to admin_application_settings_services_path,
alert: "Service is unknown or it doesn't exist"
end
end
def update
if integration.update(integration_params[:integration])
PropagateServiceTemplateWorker.perform_async(integration.id) if integration.active? # rubocop:disable CodeReuse/Worker
redirect_to admin_application_settings_services_path,
notice: 'Application settings saved successfully'
else
render :edit
end
end
private
# rubocop: disable CodeReuse/ActiveRecord
def integration
@integration ||= Integration.find_by(id: params[:id], template: true)
@service ||= @integration # TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/329759
end
alias_method :service, :integration
# rubocop: enable CodeReuse/ActiveRecord
def disable_query_limiting
Gitlab::QueryLimiting.disable!('https://gitlab.com/gitlab-org/gitlab/-/issues/220357')
end
end
......@@ -4,7 +4,6 @@ module UserCalloutsHelper
GKE_CLUSTER_INTEGRATION = 'gke_cluster_integration'
GCP_SIGNUP_OFFER = 'gcp_signup_offer'
SUGGEST_POPOVER_DISMISSED = 'suggest_popover_dismissed'
SERVICE_TEMPLATES_DEPRECATED_CALLOUT = 'service_templates_deprecated_callout'
TABS_POSITION_HIGHLIGHT = 'tabs_position_highlight'
CUSTOMIZE_HOMEPAGE = 'customize_homepage'
FEATURE_FLAGS_NEW_VERSION = 'feature_flags_new_version'
......@@ -35,13 +34,6 @@ module UserCalloutsHelper
!user_dismissed?(SUGGEST_POPOVER_DISMISSED)
end
def show_service_templates_deprecated_callout?
!Gitlab.com? &&
current_user&.admin? &&
Integration.for_template.active.exists? &&
!user_dismissed?(SERVICE_TEMPLATES_DEPRECATED_CALLOUT)
end
def show_customize_homepage_banner?
current_user.default_dashboard? && !user_dismissed?(CUSTOMIZE_HOMEPAGE)
end
......
......@@ -62,15 +62,13 @@ class Integration < ApplicationRecord
belongs_to :group, inverse_of: :integrations
has_one :service_hook, inverse_of: :integration, foreign_key: :service_id
validates :project_id, presence: true, unless: -> { template? || instance_level? || group_level? }
validates :group_id, presence: true, unless: -> { template? || instance_level? || project_level? }
validates :project_id, :group_id, absence: true, if: -> { template? || instance_level? }
validates :project_id, presence: true, unless: -> { instance_level? || group_level? }
validates :group_id, presence: true, unless: -> { instance_level? || project_level? }
validates :project_id, :group_id, absence: true, if: -> { instance_level? }
validates :type, presence: true, exclusion: BASE_CLASSES
validates :type, uniqueness: { scope: :template }, if: :template?
validates :type, uniqueness: { scope: :instance }, if: :instance_level?
validates :type, uniqueness: { scope: :project_id }, if: :project_level?
validates :type, uniqueness: { scope: :group_id }, if: :group_level?
validate :validate_is_instance_or_template
validate :validate_belongs_to_project_or_group
scope :external_issue_trackers, -> { where(category: 'issue_tracker').active }
......@@ -81,7 +79,6 @@ class Integration < ApplicationRecord
scope :inherit_from_id, -> (id) { where(inherit_from_id: id) }
scope :inherit, -> { where.not(inherit_from_id: nil) }
scope :for_group, -> (group) { where(group_id: group, type: available_integration_types(include_project_specific: false)) }
scope :for_template, -> { where(template: true, type: available_integration_types(include_project_specific: false)) }
scope :for_instance, -> { where(instance: true, type: available_integration_types(include_project_specific: false)) }
scope :push_hooks, -> { where(push_events: true, active: true) }
......@@ -169,25 +166,10 @@ class Integration < ApplicationRecord
'push'
end
def self.find_or_create_templates
create_nonexistent_templates
for_template
def self.event_description(event)
IntegrationsHelper.integration_event_description(event)
end
def self.create_nonexistent_templates
nonexistent_integrations = build_nonexistent_integrations_for(for_template)
return if nonexistent_integrations.empty?
# Create within a transaction to perform the lowest possible SQL queries.
transaction do
nonexistent_integrations.each do |integration|
integration.template = true
integration.save
end
end
end
private_class_method :create_nonexistent_templates
def self.find_or_initialize_non_project_specific_integration(name, instance: false, group_id: nil)
return unless name.in?(available_integration_names(include_project_specific: false))
......@@ -275,7 +257,6 @@ class Integration < ApplicationRecord
data_fields.integration = new_integration
end
new_integration.template = false
new_integration.instance = false
new_integration.project_id = project_id
new_integration.group_id = group_id
......@@ -306,12 +287,11 @@ class Integration < ApplicationRecord
end
private_class_method :instance_level_integration
def self.create_from_active_default_integrations(scope, association, with_templates: false)
def self.create_from_active_default_integrations(scope, association)
group_ids = sorted_ancestors(scope).select(:id)
array = group_ids.to_sql.present? ? "array(#{group_ids.to_sql})" : 'ARRAY[]'
from_union([
with_templates ? active.where(template: true) : none,
active.where(instance: true),
active.where(group_id: group_ids, inherit_from_id: nil)
]).order(Arel.sql("type ASC, array_position(#{array}::bigint[], #{table_name}.group_id), instance DESC")).group_by(&:type).each do |type, records|
......@@ -384,7 +364,7 @@ class Integration < ApplicationRecord
end
def to_integration_hash
as_json(methods: :type, except: %w[id template instance project_id group_id])
as_json(methods: :type, except: %w[id instance project_id group_id])
end
def to_data_fields_hash
......@@ -503,10 +483,6 @@ class Integration < ApplicationRecord
end
end
def validate_is_instance_or_template
errors.add(:template, 'The service should be a service template or instance-level integration') if template? && instance_level?
end
def validate_belongs_to_project_or_group
errors.add(:project_id, 'The service cannot belong to both a project and a group') if project_level? && group_level?
end
......
......@@ -1411,7 +1411,7 @@ class Project < ApplicationRecord
def find_or_initialize_integration(name)
return if disabled_integrations.include?(name)
find_integration(integrations, name) || build_from_instance_or_template(name) || build_integration(name)
find_integration(integrations, name) || build_from_instance(name) || build_integration(name)
end
# rubocop: disable CodeReuse/ServiceClass
......@@ -2673,22 +2673,18 @@ class Project < ApplicationRecord
integrations.find { _1.to_param == name }
end
def build_from_instance_or_template(name)
def build_from_instance(name)
instance = find_integration(integration_instances, name)
return Integration.build_from_integration(instance, project_id: id) if instance
template = find_integration(integration_templates, name)
return Integration.build_from_integration(template, project_id: id) if template
return unless instance
Integration.build_from_integration(instance, project_id: id)
end
def build_integration(name)
Integration.integration_name_to_model(name).new(project_id: id)
end
def integration_templates
@integration_templates ||= Integration.for_template
end
def integration_instances
@integration_instances ||= Integration.for_instance
end
......
......@@ -16,7 +16,6 @@ class UserCallout < ApplicationRecord
tabs_position_highlight: 10,
threat_monitoring_info: 11, # EE-only
account_recovery_regular_check: 12, # EE-only
service_templates_deprecated_callout: 14,
web_ide_alert_dismissed: 16, # no longer in use
active_user_count_threshold: 18, # EE-only
buy_pipeline_minutes_notification_dot: 19, # EE-only
......
......@@ -5,9 +5,7 @@ module Admin
include PropagateService
def propagate
return unless integration.active?
create_integration_for_projects_without_integration
# TODO: Remove this as part of https://gitlab.com/gitlab-org/gitlab/-/issues/335178
end
end
end
......@@ -162,7 +162,7 @@ module Projects
@project.create_or_update_import_data(data: @import_data[:data], credentials: @import_data[:credentials]) if @import_data
if @project.save
Integration.create_from_active_default_integrations(@project, :project_id, with_templates: true)
Integration.create_from_active_default_integrations(@project, :project_id)
@project.create_labels unless @project.gitlab_project_import?
......
= render "service_templates_deprecated_alert"
%h3.page-title
= @service.title
%p= @service.description
= form_for :service, url: admin_application_settings_service_path, method: :put, html: { class: 'fieldset-form js-integration-settings-form' } do |form|
= render 'shared/service_settings', form: form, integration: @service
- doc_link_start = "<a href=\"#{integrations_help_page_path}\" target='_blank' rel='noopener noreferrer'>".html_safe
- settings_link_start = "<a href=\"#{integrations_admin_application_settings_path}\">".html_safe
.gl-alert.gl-alert-danger.gl-mt-5{ role: 'alert' }
.gl-alert-container
= sprite_icon('error', css_class: 'gl-alert-icon gl-alert-icon-no-title')
.gl-alert-content
%h4.gl-alert-title= s_('AdminSettings|Service templates are deprecated and will be removed in GitLab 14.0.')
.gl-alert-body
= html_escape_once(s_("AdminSettings|You can't add new templates. To migrate or remove a Service template, create a new integration at %{settings_link_start}Settings &gt; Integrations%{link_end}. Learn more about %{doc_link_start}Project integration management%{link_end}.")).html_safe % { settings_link_start: settings_link_start, doc_link_start: doc_link_start, link_end: '</a>'.html_safe }
- add_to_breadcrumbs _("Service Templates"), admin_application_settings_services_path
- page_title @service.title, _("Service Templates")
- breadcrumb_title @service.title
- @content_class = 'limit-container-width' unless fluid_layout
= render 'form'
- page_title _("Service Templates")
- @content_class = 'limit-container-width' unless fluid_layout
= render "service_templates_deprecated_alert"
- if @activated_services.any?
%h3.page-title Service templates
%p= s_('AdminSettings|Service template allows you to set default values for integrations')
%table.table.b-table.gl-table
%colgroup
%col
%col
%col
%col{ width: 135 }
%thead
%tr
%th
%th= _('Service')
%th= _('Description')
%th= _('Last edit')
- @activated_services.each do |service|
- if service.type.in?(@existing_instance_types)
%tr
%td
%td
= link_to edit_admin_application_settings_integration_path(service.to_param), class: 'gl-text-blue-300!' do
%strong.has-tooltip{ title: s_('AdminSettings|Moved to integrations'), data: { container: 'body' } }
= service.title
%td.gl-cursor-default.gl-text-gray-400
= service.description
%td
- else
%tr
%td
= boolean_to_icon service.activated?
%td
= link_to edit_admin_application_settings_service_path(service.id) do
%strong= service.title
%td
= service.description
%td.light
= time_ago_with_tooltip service.updated_at
......@@ -11,7 +11,6 @@
= render "layouts/broadcast"
= render "layouts/header/read_only_banner"
= render "layouts/header/registration_enabled_callout"
= render "layouts/header/service_templates_deprecation_callout"
= render "layouts/nav/classification_level_banner"
= yield :flash_message
= render "shared/service_ping_consent"
......
- return unless show_service_templates_deprecated_callout?
- doc_link_start = "<a href=\"#{integrations_help_page_path}\" target='_blank' rel='noopener noreferrer'>".html_safe
- settings_link_start = "<a href=\"#{integrations_admin_application_settings_path}\">".html_safe
%div{ class: [container_class, @content_class, 'gl-pt-5!'] }
.gl-alert.gl-alert-warning.js-service-templates-deprecated-callout{ role: 'alert', data: { feature_id: UserCalloutsHelper::SERVICE_TEMPLATES_DEPRECATED_CALLOUT, dismiss_endpoint: user_callouts_path } }
= sprite_icon('warning', size: 16, css_class: 'gl-alert-icon')
%button.gl-alert-dismiss.js-close{ type: 'button', aria: { label: _('Close') }, data: { testid: 'close-service-templates-deprecated-callout' } }
= sprite_icon('close', size: 16)
.gl-alert-title
= s_('AdminSettings|Service templates are deprecated and will be removed in GitLab 14.0.')
.gl-alert-body
= html_escape_once(s_('AdminSettings|You should migrate to %{doc_link_start}Project integration management%{link_end}, available at %{settings_link_start}Settings &gt; Integrations.%{link_end}')).html_safe % { doc_link_start: doc_link_start, settings_link_start: settings_link_start, link_end: '</a>'.html_safe }
.gl-alert-actions
= link_to admin_application_settings_services_path, class: 'btn gl-alert-action btn-info btn-md gl-button' do
%span.gl-button-text
= s_('AdminSettings|See affected service templates')
= link_to "https://gitlab.com/gitlab-org/gitlab/-/issues/325905", class: 'btn gl-alert-action btn-default btn-md gl-button', target: '_blank', rel: 'noopener noreferrer' do
%span.gl-button-text
= _('Leave feedback')
......@@ -125,7 +125,6 @@ namespace :admin do
end
resource :application_settings, only: :update do
resources :services, only: [:index, :edit, :update]
resources :integrations, only: [:edit, :update] do
member do
put :test
......
......@@ -15334,7 +15334,6 @@ Name of the feature that the callout is for.
| <a id="usercalloutfeaturenameenumregistration_enabled_callout"></a>`REGISTRATION_ENABLED_CALLOUT` | Callout feature name for registration_enabled_callout. |
| <a id="usercalloutfeaturenameenumsecurity_configuration_devops_alert"></a>`SECURITY_CONFIGURATION_DEVOPS_ALERT` | Callout feature name for security_configuration_devops_alert. |
| <a id="usercalloutfeaturenameenumsecurity_configuration_upgrade_banner"></a>`SECURITY_CONFIGURATION_UPGRADE_BANNER` | Callout feature name for security_configuration_upgrade_banner. |
| <a id="usercalloutfeaturenameenumservice_templates_deprecated_callout"></a>`SERVICE_TEMPLATES_DEPRECATED_CALLOUT` | Callout feature name for service_templates_deprecated_callout. |
| <a id="usercalloutfeaturenameenumsuggest_pipeline"></a>`SUGGEST_PIPELINE` | Callout feature name for suggest_pipeline. |
| <a id="usercalloutfeaturenameenumsuggest_popover_dismissed"></a>`SUGGEST_POPOVER_DISMISSED` | Callout feature name for suggest_popover_dismissed. |
| <a id="usercalloutfeaturenameenumtabs_position_highlight"></a>`TABS_POSITION_HIGHLIGHT` | Callout feature name for tabs_position_highlight. |
......
......@@ -2389,9 +2389,6 @@ msgstr ""
msgid "AdminSettings|Maximum duration of a session for Git operations when 2FA is enabled."
msgstr ""
msgid "AdminSettings|Moved to integrations"
msgstr ""
msgid "AdminSettings|New CI/CD variables in projects and groups default to protected."
msgstr ""
......@@ -2404,21 +2401,12 @@ msgstr ""
msgid "AdminSettings|Required pipeline configuration"
msgstr ""
msgid "AdminSettings|See affected service templates"
msgstr ""
msgid "AdminSettings|Select a CI/CD template"
msgstr ""
msgid "AdminSettings|Select a group to use as the source for instance-level project templates."
msgstr ""
msgid "AdminSettings|Service template allows you to set default values for integrations"
msgstr ""
msgid "AdminSettings|Service templates are deprecated and will be removed in GitLab 14.0."
msgstr ""
msgid "AdminSettings|Session duration for Git operations when 2FA is enabled (minutes)"
msgstr ""
......@@ -2440,12 +2428,6 @@ msgstr ""
msgid "AdminSettings|The template for the required pipeline configuration can be one of the GitLab-provided templates, or a custom template added to an instance template repository. %{link_start}How do I create an instance template repository?%{link_end}"
msgstr ""
msgid "AdminSettings|You can't add new templates. To migrate or remove a Service template, create a new integration at %{settings_link_start}Settings &gt; Integrations%{link_end}. Learn more about %{doc_link_start}Project integration management%{link_end}."
msgstr ""
msgid "AdminSettings|You should migrate to %{doc_link_start}Project integration management%{link_end}, available at %{settings_link_start}Settings &gt; Integrations.%{link_end}"
msgstr ""
msgid "AdminStatistics|Active Users"
msgstr ""
......@@ -19143,9 +19125,6 @@ msgstr ""
msgid "Last contact"
msgstr ""
msgid "Last edit"
msgstr ""
msgid "Last edited %{date}"
msgstr ""
......@@ -19425,9 +19404,6 @@ msgstr ""
msgid "Leave edit mode? All unsaved changes will be lost."
msgstr ""
msgid "Leave feedback"
msgstr ""
msgid "Leave group"
msgstr ""
......@@ -29732,9 +29708,6 @@ msgstr ""
msgid "Service Desk allows people to create issues in your GitLab instance without their own user account. It provides a unique email address for end users to create issues in a project. Replies can be sent either through the GitLab interface or by email. End users only see threads through email."
msgstr ""
msgid "Service Templates"
msgstr ""
msgid "Service URL"
msgstr ""
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Admin::ServicesController do
let(:admin) { create(:admin) }
before do
sign_in(admin)
end
describe 'GET #edit' do
let(:service) do
create(:jira_integration, :template)
end
it 'successfully displays the template' do
get :edit, params: { id: service.id }
expect(response).to have_gitlab_http_status(:ok)
end
context 'when integration does not exists' do
it 'redirects to the admin application integration page' do
get :edit, params: { id: 'invalid' }
expect(response).to redirect_to(admin_application_settings_services_path)
end
end
context 'when instance integration exists' do
before do
create(:jira_integration, :instance)
end
it 'redirects to the admin application integration page' do
get :edit, params: { id: service.id }
expect(response).to redirect_to(admin_application_settings_services_path)
end
end
end
describe "#update" do
let(:project) { create(:project) }
let!(:service_template) do
Integrations::Redmine.create!(
project: nil,
active: false,
template: true,
properties: {
project_url: 'http://abc',
issues_url: 'http://abc',
new_issue_url: 'http://abc'
}
)
end
it 'calls the propagation worker when service is active' do
expect(PropagateServiceTemplateWorker).to receive(:perform_async).with(service_template.id)
put :update, params: { id: service_template.id, service: { active: true } }
expect(response).to have_gitlab_http_status(:found)
end
it 'does not call the propagation worker when service is not active' do
expect(PropagateServiceTemplateWorker).not_to receive(:perform_async)
put :update, params: { id: service_template.id, service: { properties: {} } }
expect(response).to have_gitlab_http_status(:found)
end
end
end
......@@ -25,7 +25,6 @@ FactoryBot.define do
create(:service, project: projects[2], type: 'SlackService', active: true)
create(:service, project: projects[2], type: 'MattermostService', active: false)
create(:service, group: group, project: nil, type: 'MattermostService', active: true)
create(:service, :template, type: 'MattermostService', active: true)
mattermost_instance = create(:service, :instance, type: 'MattermostService', active: true)
create(:service, project: projects[1], type: 'MattermostService', active: true, inherit_from_id: mattermost_instance.id)
create(:service, group: group, project: nil, type: 'SlackService', active: true, inherit_from_id: mattermost_instance.id)
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Admin visits service templates' do
let(:admin) { create(:user, :admin) }
let(:slack_integration) { Integration.for_template.find { |s| s.type == 'SlackService' } }
before do
sign_in(admin)
gitlab_enable_admin_mode_sign_in(admin)
end
context 'without an active service template' do
before do
visit(admin_application_settings_services_path)
end
it 'does not show service template content' do
expect(page).not_to have_content('Service template allows you to set default values for integrations')
end
end
context 'with an active service template' do
before do
create(:integrations_slack, :template, active: true)
visit(admin_application_settings_services_path)
end
it 'shows service template content' do
expect(page).to have_content('Service template allows you to set default values for integrations')
end
context 'without instance-level integration' do
it 'shows a link to service template' do
expect(page).to have_link('Slack', href: edit_admin_application_settings_service_path(slack_integration.id))
expect(page).not_to have_link('Slack', href: edit_admin_application_settings_integration_path(slack_integration))
end
end
context 'with instance-level integration' do
before do
create(:integrations_slack, instance: true, project: nil)
visit(admin_application_settings_services_path)
end
it 'shows a link to instance-level integration' do
expect(page).not_to have_link('Slack', href: edit_admin_application_settings_service_path(slack_integration.id))
expect(page).to have_link('Slack', href: edit_admin_application_settings_integration_path(slack_integration))
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Service templates deprecation callout' do
let_it_be(:admin) { create(:admin) }
let_it_be(:non_admin) { create(:user) }
let_it_be(:callout_content) { 'Service templates are deprecated and will be removed in GitLab 14.0.' }
context 'when a non-admin is logged in' do
before do
sign_in(non_admin)
visit root_dashboard_path
end
it 'does not display callout' do
expect(page).not_to have_content callout_content
end
end
context 'when an admin is logged in' do
before do
sign_in(admin)
gitlab_enable_admin_mode_sign_in(admin)
visit root_dashboard_path
end
context 'with no active service templates' do
it 'does not display callout' do
expect(page).not_to have_content callout_content
end
end
context 'with active service template' do
before do
create(:service, :template, type: 'MattermostService', active: true)
visit root_dashboard_path
end
it 'displays callout' do
expect(page).to have_content callout_content
expect(page).to have_link 'See affected service templates', href: admin_application_settings_services_path
end
context 'when callout is dismissed', :js do
before do
find('[data-testid="close-service-templates-deprecated-callout"]').click
visit root_dashboard_path
end
it 'does not display callout' do
expect(page).not_to have_content callout_content
end
end
end
end
end
......@@ -61,34 +61,6 @@ RSpec.describe UserCalloutsHelper do
end
end
describe '.show_service_templates_deprecated_callout?' do
using RSpec::Parameterized::TableSyntax
let_it_be(:admin) { create(:user, :admin) }
let_it_be(:non_admin) { create(:user) }
subject { helper.show_service_templates_deprecated_callout? }
where(:self_managed, :is_admin_user, :has_active_service_template, :callout_dismissed, :should_show_callout) do
true | true | true | false | true
true | true | true | true | false
true | false | true | false | false
false | true | true | false | false
true | true | false | false | false
end
with_them do
before do
allow(::Gitlab).to receive(:com?).and_return(!self_managed)
allow(helper).to receive(:current_user).and_return(is_admin_user ? admin : non_admin)
allow(helper).to receive(:user_dismissed?).with(described_class::SERVICE_TEMPLATES_DEPRECATED_CALLOUT) { callout_dismissed }
create(:service, :template, type: 'MattermostService', active: has_active_service_template)
end
it { is_expected.to be should_show_callout }
end
end
describe '.show_customize_homepage_banner?' do
subject { helper.show_customize_homepage_banner? }
......
......@@ -568,7 +568,6 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
expect(count_data[:projects_custom_issue_tracker_active]).to eq(1)
expect(count_data[:projects_mattermost_active]).to eq(1)
expect(count_data[:groups_mattermost_active]).to eq(1)
expect(count_data[:templates_mattermost_active]).to eq(1)
expect(count_data[:instances_mattermost_active]).to eq(1)
expect(count_data[:projects_inheriting_mattermost_active]).to eq(1)
expect(count_data[:groups_inheriting_slack_active]).to eq(1)
......
This diff is collapsed.
......@@ -5911,10 +5911,9 @@ RSpec.describe Project, factory_default: :keep do
end
end
context 'with an instance-level and template integrations' do
context 'with an instance-level integration' do
before do
create(:prometheus_integration, :instance, api_url: 'https://prometheus.instance.com/')
create(:prometheus_integration, :template, api_url: 'https://prometheus.template.com/')
end
it 'builds the integration from the instance integration' do
......@@ -5922,17 +5921,7 @@ RSpec.describe Project, factory_default: :keep do
end
end
context 'with a template integration and no instance-level' do
before do
create(:prometheus_integration, :template, api_url: 'https://prometheus.template.com/')
end
it 'builds the integration from the template' do
expect(subject.find_or_initialize_integration('prometheus').api_url).to eq('https://prometheus.template.com/')
end
end
context 'without an exisiting integration, or instance-level or template' do
context 'without an existing integration or instance-level' do
it 'builds the integration' do
expect(subject.find_or_initialize_integration('prometheus')).to be_a(::Integrations::Prometheus)
expect(subject.find_or_initialize_integration('prometheus').api_url).to be_nil
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Admin::PropagateServiceTemplate do
describe '.propagate' do
let_it_be(:project) { create(:project) }
let!(:service_template) do
Integrations::Pushover.create!(
template: true,
active: true,
push_events: false,
properties: {
device: 'MyDevice',
sound: 'mic',
priority: 4,
user_key: 'asdf',
api_key: '123456789'
}
)
end
it 'calls to PropagateIntegrationProjectWorker' do
expect(PropagateIntegrationProjectWorker).to receive(:perform_async)
.with(service_template.id, project.id, project.id)
described_class.propagate(service_template)
end
context 'with a project that has another service' do
before do
Integrations::Bamboo.create!(
active: true,
project: project,
properties: {
bamboo_url: 'http://gitlab.com',
username: 'mic',
password: 'password',
build_key: 'build'
}
)
end
it 'calls to PropagateIntegrationProjectWorker' do
expect(PropagateIntegrationProjectWorker).to receive(:perform_async)
.with(service_template.id, project.id, project.id)
described_class.propagate(service_template)
end
end
it 'does not create the service if it exists already' do
Integration.build_from_integration(service_template, project_id: project.id).save!
expect { described_class.propagate(service_template) }
.not_to change { Integration.count }
end
end
end
......@@ -96,18 +96,4 @@ RSpec.describe BulkCreateIntegrationService do
it_behaves_like 'updates inherit_from_id'
end
end
context 'passing a template integration' do
let(:integration) { template_integration }
context 'with a project association' do
let!(:project) { create(:project) }
let(:created_integration) { project.jira_integration }
let(:batch) { Project.where(id: project.id) }
let(:association) { 'project' }
let(:inherit_from_id) { integration.id }
it_behaves_like 'creates integration from batch ids'
end
end
end
......@@ -607,65 +607,55 @@ RSpec.describe Projects::CreateService, '#execute' do
describe 'create integration for the project' do
subject(:project) { create_project(user, opts) }
context 'with an active integration template' do
let!(:template_integration) { create(:prometheus_integration, :template, api_url: 'https://prometheus.template.com/') }
context 'with an active instance-level integration' do
let!(:instance_integration) { create(:prometheus_integration, :instance, api_url: 'https://prometheus.instance.com/') }
it 'creates an integration from the template' do
it 'creates an integration from the instance-level integration' do
expect(project.integrations.count).to eq(1)
expect(project.integrations.first.api_url).to eq(template_integration.api_url)
expect(project.integrations.first.inherit_from_id).to be_nil
expect(project.integrations.first.api_url).to eq(instance_integration.api_url)
expect(project.integrations.first.inherit_from_id).to eq(instance_integration.id)
end
context 'with an active instance-level integration' do
let!(:instance_integration) { create(:prometheus_integration, :instance, api_url: 'https://prometheus.instance.com/') }
context 'with an active group-level integration' do
let!(:group_integration) { create(:prometheus_integration, group: group, project: nil, api_url: 'https://prometheus.group.com/') }
let!(:group) do
create(:group).tap do |group|
group.add_owner(user)
end
end
it 'creates an integration from the instance-level integration' do
let(:opts) do
{
name: 'GitLab',
namespace_id: group.id
}
end
it 'creates an integration from the group-level integration' do
expect(project.integrations.count).to eq(1)
expect(project.integrations.first.api_url).to eq(instance_integration.api_url)
expect(project.integrations.first.inherit_from_id).to eq(instance_integration.id)
expect(project.integrations.first.api_url).to eq(group_integration.api_url)
expect(project.integrations.first.inherit_from_id).to eq(group_integration.id)
end
context 'with an active group-level integration' do
let!(:group_integration) { create(:prometheus_integration, group: group, project: nil, api_url: 'https://prometheus.group.com/') }
let!(:group) do
create(:group).tap do |group|
group.add_owner(user)
context 'with an active subgroup' do
let!(:subgroup_integration) { create(:prometheus_integration, group: subgroup, project: nil, api_url: 'https://prometheus.subgroup.com/') }
let!(:subgroup) do
create(:group, parent: group).tap do |subgroup|
subgroup.add_owner(user)
end
end
let(:opts) do
{
name: 'GitLab',
namespace_id: group.id
namespace_id: subgroup.id
}
end
it 'creates an integration from the group-level integration' do
it 'creates an integration from the subgroup-level integration' do
expect(project.integrations.count).to eq(1)
expect(project.integrations.first.api_url).to eq(group_integration.api_url)
expect(project.integrations.first.inherit_from_id).to eq(group_integration.id)
end
context 'with an active subgroup' do
let!(:subgroup_integration) { create(:prometheus_integration, group: subgroup, project: nil, api_url: 'https://prometheus.subgroup.com/') }
let!(:subgroup) do
create(:group, parent: group).tap do |subgroup|
subgroup.add_owner(user)
end
end
let(:opts) do
{
name: 'GitLab',
namespace_id: subgroup.id
}
end
it 'creates an integration from the subgroup-level integration' do
expect(project.integrations.count).to eq(1)
expect(project.integrations.first.api_url).to eq(subgroup_integration.api_url)
expect(project.integrations.first.inherit_from_id).to eq(subgroup_integration.id)
end
expect(project.integrations.first.api_url).to eq(subgroup_integration.api_url)
expect(project.integrations.first.inherit_from_id).to eq(subgroup_integration.id)
end
end
end
......
......@@ -4,9 +4,10 @@ require 'spec_helper'
RSpec.describe PropagateIntegrationWorker do
describe '#perform' do
let(:project) { create(:project) }
let(:integration) do
Integrations::Pushover.create!(
template: true,
project: project,
active: true,
device: 'MyDevice',
sound: 'mic',
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe PropagateServiceTemplateWorker do
include ExclusiveLeaseHelpers
describe '#perform' do
it 'calls the propagate service with the template' do
template = Integrations::Pushover.create!(
template: true,
active: true,
properties: {
device: 'MyDevice',
sound: 'mic',
priority: 4,
user_key: 'asdf',
api_key: '123456789'
})
stub_exclusive_lease("propagate_service_template_worker:#{template.id}",
timeout: PropagateServiceTemplateWorker::LEASE_TIMEOUT)
expect(Admin::PropagateServiceTemplate)
.to receive(:propagate)
.with(template)
subject.perform(template.id)
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