2016-08-12 06:04:33 -04:00
|
|
|
module Gitlab
|
|
|
|
module ImportExport
|
|
|
|
class AttributeCleaner
|
2016-10-18 13:31:10 -04:00
|
|
|
ALLOWED_REFERENCES = RelationFactory::PROJECT_REFERENCES + RelationFactory::USER_REFERENCES + ['group_id']
|
2016-08-12 06:04:33 -04:00
|
|
|
|
2016-10-27 06:22:18 -04:00
|
|
|
def self.clean(*args)
|
|
|
|
new(*args).clean
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(relation_hash:, relation_class:)
|
|
|
|
@relation_hash = relation_hash
|
|
|
|
@relation_class = relation_class
|
|
|
|
end
|
|
|
|
|
|
|
|
def clean
|
|
|
|
@relation_hash.reject do |key, _value|
|
|
|
|
prohibited_key?(key) || !@relation_class.attribute_method?(key)
|
|
|
|
end.except('id')
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def prohibited_key?(key)
|
|
|
|
key.end_with?('_id') && !ALLOWED_REFERENCES.include?(key)
|
2016-08-12 06:04:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|