Commit 6e886413 authored by Rémy Coutable's avatar Rémy Coutable Committed by Robert Speicher

Merge branch 'fix/import-export-events' into 'master'

Fixing problems with events for import/export

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

A couple of issues related to target being missing in exported `Events` (as being polymorphic and not have `ActiveRecord` relationships is a bit more tricky than normal models) plus as the export was in JSON, the import retrieves hashed fields as stringified hashes and not symbolized - so fixed that as well, which was the cause of https://gitlab.com/gitlab-org/gitlab-ce/issues/19202

Also fixed / refactored tests
:simpl
Import/Export Version has been bumped to 0.1.1 as theses changes to events won't work very well with old exports - forcing users to generate a new export in the new version.

See merge request !4987
(cherry picked from commit c368cb60)
parent c090535a
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.5 v 8.9.5
- Fix issues importing events in Import/Export. !4987
- Fixed 'use shortcuts' button on docs. !4979 - Fixed 'use shortcuts' button on docs. !4979
- Admin should be able to turn shared runners into specific ones. !4961 - Admin should be able to turn shared runners into specific ones. !4961
- Update RedCloth to 4.3.2 for CVE-2012-6684. !4929 (Takuya Noguchi) - Update RedCloth to 4.3.2 for CVE-2012-6684. !4929 (Takuya Noguchi)
......
...@@ -19,6 +19,8 @@ class Issue < ActiveRecord::Base ...@@ -19,6 +19,8 @@ class Issue < ActiveRecord::Base
belongs_to :project belongs_to :project
belongs_to :moved_to, class_name: 'Issue' belongs_to :moved_to, class_name: 'Issue'
has_many :events, as: :target, dependent: :destroy
validates :project, presence: true validates :project, presence: true
scope :cared, ->(user) { where(assignee_id: user) } scope :cared, ->(user) { where(assignee_id: user) }
......
...@@ -12,6 +12,8 @@ class MergeRequest < ActiveRecord::Base ...@@ -12,6 +12,8 @@ class MergeRequest < ActiveRecord::Base
has_one :merge_request_diff, dependent: :destroy has_one :merge_request_diff, dependent: :destroy
has_many :events, as: :target, dependent: :destroy
serialize :merge_params, Hash serialize :merge_params, Hash
after_create :create_merge_request_diff, unless: :importing after_create :create_merge_request_diff, unless: :importing
......
...@@ -17,6 +17,7 @@ class Milestone < ActiveRecord::Base ...@@ -17,6 +17,7 @@ class Milestone < ActiveRecord::Base
has_many :labels, -> { distinct.reorder('labels.title') }, through: :issues has_many :labels, -> { distinct.reorder('labels.title') }, through: :issues
has_many :merge_requests has_many :merge_requests
has_many :participants, -> { distinct.reorder('users.name') }, through: :issues, source: :assignee has_many :participants, -> { distinct.reorder('users.name') }, through: :issues, source: :assignee
has_many :events, as: :target, dependent: :destroy
scope :active, -> { with_state(:active) } scope :active, -> { with_state(:active) }
scope :closed, -> { with_state(:closed) } scope :closed, -> { with_state(:closed) }
......
...@@ -21,6 +21,7 @@ class Note < ActiveRecord::Base ...@@ -21,6 +21,7 @@ class Note < ActiveRecord::Base
belongs_to :updated_by, class_name: "User" belongs_to :updated_by, class_name: "User"
has_many :todos, dependent: :destroy has_many :todos, dependent: :destroy
has_many :events, as: :target, dependent: :destroy
delegate :gfm_reference, :local_reference, to: :noteable delegate :gfm_reference, :local_reference, to: :noteable
delegate :name, to: :project, prefix: true delegate :name, to: :project, prefix: true
......
...@@ -2,7 +2,7 @@ module Gitlab ...@@ -2,7 +2,7 @@ module Gitlab
module ImportExport module ImportExport
extend self extend self
VERSION = '0.1.0' VERSION = '0.1.1'
def export_path(relative_path:) def export_path(relative_path:)
File.join(storage_path, relative_path) File.join(storage_path, relative_path)
......
# Model relationships to be included in the project import/export # Model relationships to be included in the project import/export
project_tree: project_tree:
- issues: - issues:
- :events
- notes: - notes:
:author - :author
- :events
- :labels - :labels
- :milestones - milestones:
- :events
- snippets: - snippets:
- notes: - notes:
:author :author
- :releases - :releases
- :events
- project_members: - project_members:
- :user - :user
- merge_requests: - merge_requests:
- notes: - notes:
:author - :author
- :events
- :merge_request_diff - :merge_request_diff
- :events
- pipelines: - pipelines:
- notes: - notes:
:author - :author
- :events
- :statuses - :statuses
- :variables - :variables
- :triggers - :triggers
......
...@@ -33,6 +33,7 @@ module Gitlab ...@@ -33,6 +33,7 @@ module Gitlab
update_user_references update_user_references
update_project_references update_project_references
reset_ci_tokens if @relation_name == 'Ci::Trigger' reset_ci_tokens if @relation_name == 'Ci::Trigger'
@relation_hash['data'].deep_symbolize_keys! if @relation_name == :events && @relation_hash['data']
generate_imported_object generate_imported_object
end end
......
This diff is collapsed.
...@@ -24,6 +24,12 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do ...@@ -24,6 +24,12 @@ 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
restored_project_json
expect(Event.where.not(data: nil).first.data[:ref]).not_to be_empty
end
end end
end end
end end
...@@ -34,7 +34,7 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do ...@@ -34,7 +34,7 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do
end end
it 'has events' do it 'has events' do
expect(saved_project_json['events']).not_to be_empty expect(saved_project_json['milestones'].first['events']).not_to be_empty
end end
it 'has milestones' do it 'has milestones' do
...@@ -132,7 +132,7 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do ...@@ -132,7 +132,7 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do
statuses: [commit_status]) statuses: [commit_status])
create(:ci_build, pipeline: ci_pipeline, project: project) create(:ci_build, pipeline: ci_pipeline, project: project)
create(:milestone, project: project) milestone = create(:milestone, project: project)
create(:note, noteable: issue, project: project) create(:note, noteable: issue, project: project)
create(:note, noteable: merge_request, project: project) create(:note, noteable: merge_request, project: project)
create(:note, noteable: snippet, project: project) create(:note, noteable: snippet, project: project)
...@@ -140,6 +140,9 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do ...@@ -140,6 +140,9 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do
author: user, author: user,
project: project, project: project,
commit_id: ci_pipeline.sha) commit_id: ci_pipeline.sha)
create(:event, target: milestone, project: project, action: Event::CREATED, author: user)
project project
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