cfb511ea69
Fix Import/Export foreign key issue to do with project members Cleans-up any foreign keys in `ProjectMember` - same as we do with the rest of the models when importing. Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/23837 and https://gitlab.com/gitlab-org/gitlab-ce/issues/23739 See merge request !2020 Signed-off-by: Rémy Coutable <remy@rymai.me>
28 lines
699 B
Ruby
28 lines
699 B
Ruby
module Gitlab
|
|
module ImportExport
|
|
class AttributeCleaner
|
|
ALLOWED_REFERENCES = RelationFactory::PROJECT_REFERENCES + RelationFactory::USER_REFERENCES + ['group_id']
|
|
|
|
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)
|
|
end
|
|
end
|
|
end
|
|
end
|