diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 16:37:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 16:37:47 +0300 |
commit | aee0a117a889461ce8ced6fcf73207fe017f1d99 (patch) | |
tree | 891d9ef189227a8445d83f35c1b0fc99573f4380 /lib/gitlab/import_export | |
parent | 8d46af3258650d305f53b819eabf7ab18d22f59e (diff) |
Add latest changes from gitlab-org/gitlab@14-6-stable-eev14.6.0-rc42
Diffstat (limited to 'lib/gitlab/import_export')
4 files changed, 102 insertions, 18 deletions
diff --git a/lib/gitlab/import_export/group/relation_tree_restorer.rb b/lib/gitlab/import_export/group/relation_tree_restorer.rb index f3c392b8c20..cbc8ee9e18b 100644 --- a/lib/gitlab/import_export/group/relation_tree_restorer.rb +++ b/lib/gitlab/import_export/group/relation_tree_restorer.rb @@ -106,12 +106,7 @@ module Gitlab def update_params! params = @importable_attributes.except(*relations.keys.map(&:to_s)) params = params.merge(present_override_params) - - # Cleaning all imported and overridden params - params = Gitlab::ImportExport::AttributeCleaner.clean( - relation_hash: params, - relation_class: importable_class, - excluded_keys: excluded_keys_for_relation(importable_class_sym)) + params = filter_attributes(params) @importable.assign_attributes(params) @@ -122,6 +117,25 @@ module Gitlab end end + def filter_attributes(params) + if use_attributes_permitter? && attributes_permitter.permitted_attributes_defined?(importable_class_sym) + attributes_permitter.permit(importable_class_sym, params) + else + Gitlab::ImportExport::AttributeCleaner.clean( + relation_hash: params, + relation_class: importable_class, + excluded_keys: excluded_keys_for_relation(importable_class_sym)) + end + end + + def attributes_permitter + @attributes_permitter ||= Gitlab::ImportExport::AttributesPermitter.new + end + + def use_attributes_permitter? + Feature.enabled?(:permitted_attributes_for_import_export, default_enabled: :yaml) + end + def present_override_params # we filter out the empty strings from the overrides # keeping the default values configured diff --git a/lib/gitlab/import_export/json/streaming_serializer.rb b/lib/gitlab/import_export/json/streaming_serializer.rb index 9ab8fa68d0e..fb8d6e7d89b 100644 --- a/lib/gitlab/import_export/json/streaming_serializer.rb +++ b/lib/gitlab/import_export/json/streaming_serializer.rb @@ -40,6 +40,13 @@ module Gitlab end end + def serialize_root(exportable_path = @exportable_path) + attributes = exportable.as_json( + relations_schema.merge(include: nil, preloads: nil)) + + json_writer.write_attributes(exportable_path, attributes) + end + def serialize_relation(definition) raise ArgumentError, 'definition needs to be Hash' unless definition.is_a?(Hash) raise ArgumentError, 'definition needs to have exactly one Hash element' unless definition.one? @@ -60,12 +67,6 @@ module Gitlab attr_reader :json_writer, :relations_schema, :exportable - def serialize_root - attributes = exportable.as_json( - relations_schema.merge(include: nil, preloads: nil)) - json_writer.write_attributes(@exportable_path, attributes) - end - def serialize_many_relations(key, records, options) enumerator = Enumerator.new do |items| key_preloads = preloads&.dig(key) diff --git a/lib/gitlab/import_export/project/import_export.yml b/lib/gitlab/import_export/project/import_export.yml index d815dd284ba..ef146359da9 100644 --- a/lib/gitlab/import_export/project/import_export.yml +++ b/lib/gitlab/import_export/project/import_export.yml @@ -126,7 +126,6 @@ included_attributes: - :project_id project_badges: - :created_at - - :group_id - :image_url - :link_url - :name @@ -414,7 +413,6 @@ included_attributes: - :b_mode - :too_large - :binary - - :diff metrics: - :created_at - :updated_at @@ -572,7 +570,6 @@ included_attributes: - :updated_at actions: - :event - - :image_v432x230 design: &design_definition - :iid - :project_id @@ -632,6 +629,74 @@ included_attributes: - :expires_at - :ldap - :override + project: + - :approvals_before_merge + - :archived + - :auto_cancel_pending_pipelines + - :autoclose_referenced_issues + - :build_allow_git_fetch + - :build_coverage_regex + - :build_timeout + - :ci_config_path + - :delete_error + - :description + - :disable_overriding_approvers_per_merge_request + - :external_authorization_classification_label + - :has_external_issue_tracker + - :has_external_wiki + - :issues_template + - :jobs_cache_index + - :last_repository_check_failed + - :merge_requests_author_approval + - :merge_requests_disable_committers_approval + - :merge_requests_ff_only_enabled + - :merge_requests_rebase_enabled + - :merge_requests_template + - :only_allow_merge_if_all_discussions_are_resolved + - :only_allow_merge_if_pipeline_succeeds + - :pages_https_only + - :pending_delete + - :printing_merge_request_link_enabled + - :public_builds + - :remove_source_branch_after_merge + - :request_access_enabled + - :require_password_to_approve + - :reset_approvals_on_push + - :resolve_outdated_diff_discussions + - :service_desk_enabled + - :shared_runners_enabled + - :suggestion_commit_message + - :visibility_level + - :hooks + - :issues_access_level + - :forking_access_level + - :merge_requests_access_level + - :wiki_access_level + - :snippets_access_level + - :builds_access_level + - :repository_access_level + - :pages_access_level + - :metrics_dashboard_access_level + - :analytics_access_level + - :operations_access_level + - :security_and_compliance_access_level + - :container_registry_access_level + - :allow_merge_on_skipped_pipeline + - :auto_devops_deploy_strategy + - :auto_devops_enabled + - :container_registry_enabled + - :issues_enabled + - :jobs_enabled + - :merge_method + - :merge_requests_enabled + - :snippets_enabled + - :squash_option + - :topics + - :visibility + - :wiki_enabled + - :build_git_strategy + - :build_enabled + - :security_and_compliance_enabled # Do not include the following attributes for the models specified. excluded_attributes: @@ -747,6 +812,7 @@ excluded_attributes: - :service_desk_reply_to - :upvotes_count - :work_item_type_id + - :email_message_id merge_request: &merge_request_excluded_definition - :milestone_id - :sprint_id @@ -889,8 +955,6 @@ excluded_attributes: system_note_metadata: - :description_version_id - :note_id - pipeline_schedules: - - :active methods: notes: - :type @@ -1021,3 +1085,6 @@ ee: - :auto_fix_dast - :auto_fix_dependency_scanning - :auto_fix_sast + project: + - :requirements_enabled + - :requirements_access_level diff --git a/lib/gitlab/import_export/project/relation_factory.rb b/lib/gitlab/import_export/project/relation_factory.rb index d84db92fe69..c391f86b47b 100644 --- a/lib/gitlab/import_export/project/relation_factory.rb +++ b/lib/gitlab/import_export/project/relation_factory.rb @@ -131,7 +131,9 @@ module Gitlab end def setup_diff - @relation_hash['diff'] = @relation_hash.delete('utf8_diff') + diff = @relation_hash.delete('utf8_diff') + + parsed_relation_hash['diff'] = diff end def setup_pipeline |