diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 16:18:24 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 16:18:24 +0300 |
commit | 0653e08efd039a5905f3fa4f6e9cef9f5d2f799c (patch) | |
tree | 4dcc884cf6d81db44adae4aa99f8ec1233a41f55 /lib/gitlab/import_export | |
parent | 744144d28e3e7fddc117924fef88de5d9674fe4c (diff) |
Add latest changes from gitlab-org/gitlab@14-3-stable-eev14.3.0-rc42
Diffstat (limited to 'lib/gitlab/import_export')
-rw-r--r-- | lib/gitlab/import_export/attributes_permitter.rb | 26 | ||||
-rw-r--r-- | lib/gitlab/import_export/base/relation_factory.rb | 16 | ||||
-rw-r--r-- | lib/gitlab/import_export/project/import_export.yml | 43 | ||||
-rw-r--r-- | lib/gitlab/import_export/relation_tree_restorer.rb | 4 |
4 files changed, 77 insertions, 12 deletions
diff --git a/lib/gitlab/import_export/attributes_permitter.rb b/lib/gitlab/import_export/attributes_permitter.rb index 86f51add504..acd03d9ec20 100644 --- a/lib/gitlab/import_export/attributes_permitter.rb +++ b/lib/gitlab/import_export/attributes_permitter.rb @@ -42,6 +42,10 @@ module Gitlab class AttributesPermitter attr_reader :permitted_attributes + # We want to use AttributesCleaner for these relations instead, in the future this should be removed to make sure + # we are using AttributesPermitter for every imported relation. + DISABLED_RELATION_NAMES = %i[user author ci_cd_settings issuable_sla push_rule].freeze + def initialize(config: ImportExport::Config.new.to_h) @config = config @attributes_finder = Gitlab::ImportExport::AttributesFinder.new(config: @config) @@ -50,16 +54,20 @@ module Gitlab build_permitted_attributes end - def permit(relation_name, relation_hash) - permitted_attributes = permitted_attributes_for(relation_name) + def permit(relation_sym, relation_hash) + permitted_attributes = permitted_attributes_for(relation_sym) relation_hash.select do |key, _| - permitted_attributes.include?(key) + permitted_attributes.include?(key.to_sym) end end - def permitted_attributes_for(relation_name) - @permitted_attributes[relation_name] || [] + def permitted_attributes_for(relation_sym) + @permitted_attributes[relation_sym] || [] + end + + def permitted_attributes_defined?(relation_sym) + !DISABLED_RELATION_NAMES.include?(relation_sym) && @attributes_finder.included_attributes.key?(relation_sym) end private @@ -88,11 +96,15 @@ module Gitlab end def build_attributes - @attributes_finder.included_attributes.each(&method(:add_permitted_attributes)) + @attributes_finder.included_attributes.each do |model_name, attributes| + add_permitted_attributes(model_name, attributes) + end end def build_methods - @attributes_finder.methods.each(&method(:add_permitted_attributes)) + @attributes_finder.methods.each do |model_name, attributes| + add_permitted_attributes(model_name, attributes) + end end def add_permitted_attributes(model_name, attributes) diff --git a/lib/gitlab/import_export/base/relation_factory.rb b/lib/gitlab/import_export/base/relation_factory.rb index 30cd5ccfbcb..a84efd1d240 100644 --- a/lib/gitlab/import_export/base/relation_factory.rb +++ b/lib/gitlab/import_export/base/relation_factory.rb @@ -29,7 +29,7 @@ module Gitlab owner_id ].freeze - TOKEN_RESET_MODELS = %i[Project Namespace Group Ci::Trigger Ci::Build Ci::Runner ProjectHook].freeze + TOKEN_RESET_MODELS = %i[Project Namespace Group Ci::Trigger Ci::Build Ci::Runner ProjectHook ErrorTracking::ProjectErrorTrackingSetting].freeze def self.create(*args, **kwargs) new(*args, **kwargs).create @@ -45,6 +45,7 @@ module Gitlab end def initialize(relation_sym:, relation_index:, relation_hash:, members_mapper:, object_builder:, user:, importable:, excluded_keys: []) + @relation_sym = relation_sym @relation_name = self.class.overrides[relation_sym]&.to_sym || relation_sym @relation_index = relation_index @relation_hash = relation_hash.except('noteable_id') @@ -181,8 +182,17 @@ module Gitlab end def parsed_relation_hash - @parsed_relation_hash ||= Gitlab::ImportExport::AttributeCleaner.clean(relation_hash: @relation_hash, - relation_class: relation_class) + strong_memoize(:parsed_relation_hash) do + if Feature.enabled?(:permitted_attributes_for_import_export, default_enabled: :yaml) && attributes_permitter.permitted_attributes_defined?(@relation_sym) + attributes_permitter.permit(@relation_sym, @relation_hash) + else + Gitlab::ImportExport::AttributeCleaner.clean(relation_hash: @relation_hash, relation_class: relation_class) + end + end + end + + def attributes_permitter + @attributes_permitter ||= Gitlab::ImportExport::AttributesPermitter.new end def existing_or_new_object diff --git a/lib/gitlab/import_export/project/import_export.yml b/lib/gitlab/import_export/project/import_export.yml index 3ebdcc950c3..fe0974d27a6 100644 --- a/lib/gitlab/import_export/project/import_export.yml +++ b/lib/gitlab/import_export/project/import_export.yml @@ -107,6 +107,7 @@ tree: - lists: - label: - :priorities + - :service_desk_setting group_members: - :user @@ -120,6 +121,41 @@ included_attributes: - :name ci_cd_settings: - :group_runners_enabled + metrics_setting: + - :dashboard_timezone + - :external_dashboard_url + - :project_id + project_badges: + - :created_at + - :group_id + - :image_url + - :link_url + - :name + - :project_id + - :type + - :updated_at + pipeline_schedules: + - :active + - :created_at + - :cron + - :cron_timezone + - :description + - :next_run_at + - :owner_id + - :project_id + - :ref + - :updated_at + error_tracking_setting: + - :api_url + - :organization_name + - :project_id + - :project_name + auto_devops: + - :created_at + - :deploy_strategy + - :enabled + - :project_id + - :updated_at # Do not include the following attributes for the models specified. excluded_attributes: @@ -127,6 +163,7 @@ excluded_attributes: - :name - :path - :namespace_id + - :project_namespace_id - :creator_id - :pool_repository_id - :import_url @@ -297,6 +334,7 @@ excluded_attributes: - :integrated service_desk_setting: - :outgoing_name + - :file_template_project_id priorities: - :label_id events: @@ -331,6 +369,9 @@ excluded_attributes: project_members: - :source_id - :invite_email_success + - :state + group_members: + - :state metrics: - :merge_request_id - :pipeline_id @@ -359,6 +400,7 @@ excluded_attributes: boards: - :milestone_id - :iteration_id + - :iteration_cadence_id lists: - :board_id - :label_id @@ -454,7 +496,6 @@ ee: - :unprotect_access_levels - protected_environments: - :deploy_access_levels - - :service_desk_setting - :security_setting - :push_rule diff --git a/lib/gitlab/import_export/relation_tree_restorer.rb b/lib/gitlab/import_export/relation_tree_restorer.rb index d5f924ae2bd..8d93098a80a 100644 --- a/lib/gitlab/import_export/relation_tree_restorer.rb +++ b/lib/gitlab/import_export/relation_tree_restorer.rb @@ -61,7 +61,9 @@ module Gitlab # the configuration yaml file too. # Finally, it updates each attribute in the newly imported project/group. def create_relations! - relations.each(&method(:process_relation!)) + relations.each do |relation_key, relation_definition| + process_relation!(relation_key, relation_definition) + end end def process_relation!(relation_key, relation_definition) |