Commit ac9e49fd authored by Robert Speicher's avatar Robert Speicher Committed by Robert Speicher

Merge branch 'fix/import-event-error' into 'master'

Fix problems with events under notes importing GitLab projects

Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/19588

See merge request !5154
(cherry picked from commit 734e44ee)
parent 43d6c0be
Please view this file on the master branch, on stable branches it's out of date. Please view this file on the master branch, on stable branches it's out of date.
v 8.9.6 v 8.9.6
- Fix importing of events under notes for GitLab projects. !5154
- Fix log statements in import/export. !5129 - Fix log statements in import/export. !5129
- Fix commit avatar alignment in compare view. !5128 - Fix commit avatar alignment in compare view. !5128
- Fix broken migration in MySQL. !5005 - Fix broken migration in MySQL. !5005
......
...@@ -70,10 +70,19 @@ module Gitlab ...@@ -70,10 +70,19 @@ module Gitlab
# Example: # Example:
# +relation_key+ issues, loops through the list of *issues* and for each individual # +relation_key+ issues, loops through the list of *issues* and for each individual
# issue, finds any subrelations such as notes, creates them and assign them back to the hash # issue, finds any subrelations such as notes, creates them and assign them back to the hash
#
# Recursively calls this method if the sub-relation is a hash containing more sub-relations
def create_sub_relations(relation, tree_hash) def create_sub_relations(relation, tree_hash)
relation_key = relation.keys.first.to_s relation_key = relation.keys.first.to_s
return if tree_hash[relation_key].blank?
tree_hash[relation_key].each do |relation_item| tree_hash[relation_key].each do |relation_item|
relation.values.flatten.each do |sub_relation| relation.values.flatten.each do |sub_relation|
# We just use author to get the user ID, do not attempt to create an instance.
next if sub_relation == :author
create_sub_relations(sub_relation, relation_item) if sub_relation.is_a?(Hash)
relation_hash, sub_relation = assign_relation_hash(relation_item, sub_relation) relation_hash, sub_relation = assign_relation_hash(relation_item, sub_relation)
relation_item[sub_relation.to_s] = create_relation(sub_relation, relation_hash) unless relation_hash.blank? relation_item[sub_relation.to_s] = create_relation(sub_relation, relation_hash) unless relation_hash.blank?
end end
......
...@@ -4208,7 +4208,18 @@ ...@@ -4208,7 +4208,18 @@
"name": "User 4" "name": "User 4"
}, },
"events": [ "events": [
{
"id": 529,
"target_type": "Note",
"target_id": 2521,
"title": "test levels",
"data": null,
"project_id": 4,
"created_at": "2016-07-07T14:35:12.128Z",
"updated_at": "2016-07-07T14:35:12.128Z",
"action": 6,
"author_id": 1
}
] ]
}, },
{ {
......
...@@ -25,11 +25,27 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do ...@@ -25,11 +25,27 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do
expect(Ci::Pipeline.first.notes).not_to be_empty expect(Ci::Pipeline.first.notes).not_to be_empty
end end
it 'restores the correct event' do it 'restores the correct event with symbolised data' do
restored_project_json restored_project_json
expect(Event.where.not(data: nil).first.data[:ref]).not_to be_empty expect(Event.where.not(data: nil).first.data[:ref]).not_to be_empty
end end
context 'event at forth level of the tree' do
let(:event) { Event.where(title: 'test levels').first }
before do
restored_project_json
end
it 'restores the event' do
expect(event).not_to be_nil
end
it 'event belongs to note, belongs to merge request, belongs to a project' do
expect(event.note.noteable.project).not_to be_nil
end
end
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment