Commit 3ce57ed3 authored by Peter Leitzen's avatar Peter Leitzen

Move Tracing project setting model to Core

This commit moves the tracing project setting model from Ultimate to
Core.
parent 8a5d5b40
......@@ -199,6 +199,7 @@ class Project < ApplicationRecord
has_one :import_export_upload, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
has_many :export_jobs, class_name: 'ProjectExportJob'
has_one :project_repository, inverse_of: :project
has_one :tracing_setting, class_name: 'ProjectTracingSetting'
has_one :incident_management_setting, inverse_of: :project, class_name: 'IncidentManagement::ProjectIncidentManagementSetting'
has_one :error_tracking_setting, inverse_of: :project, class_name: 'ErrorTracking::ProjectErrorTrackingSetting'
has_one :metrics_setting, inverse_of: :project, class_name: 'ProjectMetricsSetting'
......@@ -2523,6 +2524,10 @@ class Project < ApplicationRecord
instance.token
end
def tracing_external_url
tracing_setting&.external_url
end
private
def find_service(services, name)
......
......@@ -42,7 +42,6 @@ module EE
has_one :github_service
has_one :gitlab_slack_application_service
has_one :tracing_setting, class_name: 'ProjectTracingSetting'
has_one :status_page_setting, inverse_of: :project, class_name: 'StatusPage::ProjectSetting'
has_one :compliance_framework_setting, class_name: 'ComplianceManagement::ComplianceFramework::ProjectSettings', inverse_of: :project
has_one :security_setting, class_name: 'ProjectSecuritySetting'
......@@ -235,10 +234,6 @@ module EE
namespace.store_security_reports_available? || public?
end
def tracing_external_url
self.tracing_setting.try(:external_url)
end
def latest_pipeline_with_security_reports(only_successful: false)
pipeline_scope = all_pipelines.newest_first(ref: default_branch)
pipeline_scope = pipeline_scope.success if only_successful
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ProjectTracingSetting do
describe '#external_url' do
let_it_be(:project) { create(:project) }
let(:tracing_setting) { project.build_tracing_setting }
it 'accepts a valid url' do
tracing_setting.external_url = "https://gitlab.com"
expect(tracing_setting).to be_valid
expect { tracing_setting.save! }.not_to raise_error
end
it 'fails with an invalid url' do
tracing_setting.external_url = "gitlab.com"
expect(tracing_setting).not_to be_valid
end
it 'fails with a blank string' do
tracing_setting.external_url = " "
expect(tracing_setting).not_to be_valid
end
it 'sanitizes the url' do
tracing_setting.external_url = "https://replaceme.com/'><script>alert(document.cookie)</script>"
expect(tracing_setting).to be_valid
expect(tracing_setting.external_url).to eq("https://replaceme.com/'&gt;")
end
end
end
......@@ -72,6 +72,7 @@ RSpec.describe Project do
it { is_expected.to have_one(:last_event).class_name('Event') }
it { is_expected.to have_one(:forked_from_project).through(:fork_network_member) }
it { is_expected.to have_one(:auto_devops).class_name('ProjectAutoDevops') }
it { is_expected.to have_one(:tracing_setting).class_name('ProjectTracingSetting') }
it { is_expected.to have_one(:error_tracking_setting).class_name('ErrorTracking::ProjectErrorTrackingSetting') }
it { is_expected.to have_one(:project_setting) }
it { is_expected.to have_one(:alerting_setting).class_name('Alerting::ProjectAlertingSetting') }
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ProjectTracingSetting do
describe '#external_url' do
let_it_be(:project) { create(:project) }
let(:tracing_setting) { project.build_tracing_setting }
describe 'Validations' do
describe 'external_url' do
it 'accepts a valid url' do
tracing_setting.external_url = 'https://gitlab.com'
expect(tracing_setting).to be_valid
end
it 'fails with an invalid url' do
tracing_setting.external_url = 'gitlab.com'
expect(tracing_setting).to be_invalid
end
it 'fails with a blank string' do
tracing_setting.external_url = nil
expect(tracing_setting).to be_invalid
end
it 'sanitizes the url' do
tracing_setting.external_url = %{https://replaceme.com/'><script>alert(document.cookie)</script>}
expect(tracing_setting).to be_valid
expect(tracing_setting.external_url).to eq(%{https://replaceme.com/'&gt;})
end
end
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