diff options
Diffstat (limited to 'lib/gitlab/import_export/attributes_permitter.rb')
-rw-r--r-- | lib/gitlab/import_export/attributes_permitter.rb | 26 |
1 files changed, 19 insertions, 7 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) |