summaryrefslogtreecommitdiff
path: root/lib/gitlab
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab')
-rw-r--r--lib/gitlab/background_migration/activate_prometheus_services_for_shared_cluster_applications.rb52
-rw-r--r--lib/gitlab/ci/pipeline/chain/command.rb6
-rw-r--r--lib/gitlab/ci/pipeline/chain/validate/abilities.rb26
-rw-r--r--lib/gitlab/import_export/group_project_object_builder.rb14
-rw-r--r--lib/gitlab/import_export/import_export.yml8
-rw-r--r--lib/gitlab/import_export/relation_factory.rb23
-rw-r--r--lib/gitlab/import_export/relation_tree_restorer.rb2
7 files changed, 43 insertions, 88 deletions
diff --git a/lib/gitlab/background_migration/activate_prometheus_services_for_shared_cluster_applications.rb b/lib/gitlab/background_migration/activate_prometheus_services_for_shared_cluster_applications.rb
deleted file mode 100644
index 19f5821d449..00000000000
--- a/lib/gitlab/background_migration/activate_prometheus_services_for_shared_cluster_applications.rb
+++ /dev/null
@@ -1,52 +0,0 @@
-# frozen_string_literal: true
-
-module Gitlab
- module BackgroundMigration
- # Create missing PrometheusServices records or sets active attribute to true
- # for all projects which belongs to cluster with Prometheus Application installed.
- class ActivatePrometheusServicesForSharedClusterApplications
- module Migratable
- # Migration model namespace isolated from application code.
- class PrometheusService < ActiveRecord::Base
- self.inheritance_column = :_type_disabled
- self.table_name = 'services'
-
- default_scope { where("services.type = 'PrometheusService'") }
-
- def self.for_project(project_id)
- new(
- project_id: project_id,
- active: true,
- properties: '{}',
- type: 'PrometheusService',
- template: false,
- push_events: true,
- issues_events: true,
- merge_requests_events: true,
- tag_push_events: true,
- note_events: true,
- category: 'monitoring',
- default: false,
- wiki_page_events: true,
- pipeline_events: true,
- confidential_issues_events: true,
- commit_events: true,
- job_events: true,
- confidential_note_events: true,
- deployment_events: false
- )
- end
-
- def managed?
- properties == '{}'
- end
- end
- end
-
- def perform(project_id)
- service = Migratable::PrometheusService.find_by(project_id: project_id) || Migratable::PrometheusService.for_project(project_id)
- service.update!(active: true) if service.managed?
- end
- end
- end
-end
diff --git a/lib/gitlab/ci/pipeline/chain/command.rb b/lib/gitlab/ci/pipeline/chain/command.rb
index 0f355906948..6a16e6df23d 100644
--- a/lib/gitlab/ci/pipeline/chain/command.rb
+++ b/lib/gitlab/ci/pipeline/chain/command.rb
@@ -22,12 +22,6 @@ module Gitlab
end
end
- def uses_unsupported_legacy_trigger?
- trigger_request.present? &&
- trigger_request.trigger.legacy? &&
- !trigger_request.trigger.supports_legacy_tokens?
- end
-
def branch_exists?
strong_memoize(:is_branch) do
project.repository.branch_exists?(ref)
diff --git a/lib/gitlab/ci/pipeline/chain/validate/abilities.rb b/lib/gitlab/ci/pipeline/chain/validate/abilities.rb
index f9ed9d91177..a30b6c6ef0e 100644
--- a/lib/gitlab/ci/pipeline/chain/validate/abilities.rb
+++ b/lib/gitlab/ci/pipeline/chain/validate/abilities.rb
@@ -14,16 +14,12 @@ module Gitlab
return error('Pipelines are disabled!')
end
- if @command.uses_unsupported_legacy_trigger?
- return error('Trigger token is invalid because is not owned by any user')
+ unless allowed_to_create_pipeline?
+ return error('Insufficient permissions to create a new pipeline')
end
- unless allowed_to_trigger_pipeline?
- if can?(current_user, :create_pipeline, project)
- return error("Insufficient permissions for protected ref '#{command.ref}'")
- else
- return error('Insufficient permissions to create a new pipeline')
- end
+ unless allowed_to_write_ref?
+ return error("Insufficient permissions for protected ref '#{command.ref}'")
end
end
@@ -31,17 +27,13 @@ module Gitlab
@pipeline.errors.any?
end
- def allowed_to_trigger_pipeline?
- if current_user
- allowed_to_create?
- else # legacy triggers don't have a corresponding user
- !@command.protected_ref?
- end
- end
+ private
- def allowed_to_create?
- return unless can?(current_user, :create_pipeline, project)
+ def allowed_to_create_pipeline?
+ can?(current_user, :create_pipeline, project)
+ end
+ def allowed_to_write_ref?
access = Gitlab::UserAccess.new(current_user, project: project)
if @command.branch_exists?
diff --git a/lib/gitlab/import_export/group_project_object_builder.rb b/lib/gitlab/import_export/group_project_object_builder.rb
index b94839363df..2e7ab3d4b69 100644
--- a/lib/gitlab/import_export/group_project_object_builder.rb
+++ b/lib/gitlab/import_export/group_project_object_builder.rb
@@ -26,6 +26,8 @@ module Gitlab
end
def find
+ return if epic? && group.nil?
+
find_object || klass.create(project_attributes)
end
@@ -54,10 +56,10 @@ module Gitlab
# or, if group is present:
# `"{table_name}"."project_id" = {project.id} OR "{table_name}"."group_id" = {group.id}`
def where_clause_base
- clause = table[:project_id].eq(project.id) if project
- clause = clause.or(table[:group_id].eq(group.id)) if group
-
- clause
+ [].tap do |clauses|
+ clauses << table[:project_id].eq(project.id) if project
+ clauses << table[:group_id].eq(group.id) if group
+ end.reduce(:or)
end
# Returns Arel clause `"{table_name}"."title" = '{attributes['title']}'`
@@ -108,6 +110,10 @@ module Gitlab
klass == MergeRequest
end
+ def epic?
+ klass == Epic
+ end
+
# If an existing group milestone used the IID
# claim the IID back and set the group milestone to use one available
# This is necessary to fix situations like the following:
diff --git a/lib/gitlab/import_export/import_export.yml b/lib/gitlab/import_export/import_export.yml
index 3208e6648a7..0f0397ec13b 100644
--- a/lib/gitlab/import_export/import_export.yml
+++ b/lib/gitlab/import_export/import_export.yml
@@ -322,6 +322,13 @@ excluded_attributes:
- :board_id
- :label_id
- :milestone_id
+ epic:
+ - :start_date_sourcing_milestone_id
+ - :due_date_sourcing_milestone_id
+ - :parent_id
+ - :state_id
+ - :start_date_sourcing_epic_id
+ - :due_date_sourcing_epic_id
methods:
notes:
- :type
@@ -374,6 +381,7 @@ ee:
- design_versions:
- actions:
- :design # Duplicate export of issues.designs in order to link the record to both Issue and Action
+ - :epic
- protected_branches:
- :unprotect_access_levels
- protected_environments:
diff --git a/lib/gitlab/import_export/relation_factory.rb b/lib/gitlab/import_export/relation_factory.rb
index 9dd30803196..9a5e01462fb 100644
--- a/lib/gitlab/import_export/relation_factory.rb
+++ b/lib/gitlab/import_export/relation_factory.rb
@@ -40,7 +40,21 @@ module Gitlab
IMPORTED_OBJECT_MAX_RETRIES = 5.freeze
- EXISTING_OBJECT_CHECK = %i[milestone milestones label labels project_label project_labels group_label group_labels project_feature merge_request ProjectCiCdSetting container_expiration_policy].freeze
+ EXISTING_OBJECT_CHECK = %i[
+ milestone
+ milestones
+ label
+ labels
+ project_label
+ project_labels
+ group_label
+ group_labels
+ project_feature
+ merge_request
+ epic
+ ProjectCiCdSetting
+ container_expiration_policy
+ ].freeze
TOKEN_RESET_MODELS = %i[Project Namespace Ci::Trigger Ci::Build Ci::Runner ProjectHook].freeze
@@ -86,9 +100,6 @@ module Gitlab
def create
return if unknown_service?
- # Do not import legacy triggers
- return if !Feature.enabled?(:use_legacy_pipeline_triggers, @project) && legacy_trigger?
-
setup_models
object = generate_imported_object
@@ -345,10 +356,6 @@ module Gitlab
!Object.const_defined?(parsed_relation_hash['type'])
end
- def legacy_trigger?
- @relation_name == :'Ci::Trigger' && @relation_hash['owner_id'].nil?
- end
-
def find_or_create_object!
if UNIQUE_RELATIONS.include?(@relation_name)
unique_relation_object = relation_class.find_or_create_by(project_id: @project.id)
diff --git a/lib/gitlab/import_export/relation_tree_restorer.rb b/lib/gitlab/import_export/relation_tree_restorer.rb
index 886087bc73a..4f58406360e 100644
--- a/lib/gitlab/import_export/relation_tree_restorer.rb
+++ b/lib/gitlab/import_export/relation_tree_restorer.rb
@@ -4,7 +4,7 @@ module Gitlab
module ImportExport
class RelationTreeRestorer
# Relations which cannot be saved at project level (and have a group assigned)
- GROUP_MODELS = [GroupLabel, Milestone].freeze
+ GROUP_MODELS = [GroupLabel, Milestone, Epic].freeze
attr_reader :user
attr_reader :shared