Class: Gitlab::ImportExport::AttributesPermitter

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/import_export/attributes_permitter.rb

Constant Summary collapse

DISABLED_RELATION_NAMES =

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.

%i[author issuable_sla].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config: ImportExport::Config.new.to_h) ⇒ AttributesPermitter

Returns a new instance of AttributesPermitter.


49
50
51
52
53
54
55
# File 'lib/gitlab/import_export/attributes_permitter.rb', line 49

def initialize(config: ImportExport::Config.new.to_h)
  @config = config
  @attributes_finder = Gitlab::ImportExport::AttributesFinder.new(config: @config)
  @permitted_attributes = {}

  build_permitted_attributes
end

Instance Attribute Details

#permitted_attributesObject (readonly)

Returns the value of attribute permitted_attributes.


43
44
45
# File 'lib/gitlab/import_export/attributes_permitter.rb', line 43

def permitted_attributes
  @permitted_attributes
end

Instance Method Details

#permit(relation_sym, relation_hash) ⇒ Object


57
58
59
60
61
62
63
# File 'lib/gitlab/import_export/attributes_permitter.rb', line 57

def permit(relation_sym, relation_hash)
  permitted_attributes = permitted_attributes_for(relation_sym)

  relation_hash.select do |key, _|
    permitted_attributes.include?(key.to_sym)
  end
end

#permitted_attributes_defined?(relation_sym) ⇒ Boolean

Returns:

  • (Boolean)

69
70
71
# File 'lib/gitlab/import_export/attributes_permitter.rb', line 69

def permitted_attributes_defined?(relation_sym)
  !DISABLED_RELATION_NAMES.include?(relation_sym) && @attributes_finder.included_attributes.key?(relation_sym)
end

#permitted_attributes_for(relation_sym) ⇒ Object


65
66
67
# File 'lib/gitlab/import_export/attributes_permitter.rb', line 65

def permitted_attributes_for(relation_sym)
  @permitted_attributes[relation_sym] || []
end