Commit c368cb60 authored by Rémy Coutable's avatar Rémy Coutable

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
parents b37a8d8f e7319d0a
......@@ -35,6 +35,7 @@ v 8.9.5 (unreleased)
- Improve the request / withdraw access button. !4860
- Fix assigning shared runners as admins. !4961
- Show "locked" label for locked runners on runners admin. !4961
- Fixes issues importing events in Import/Export. Import/Export version bumped to 0.1.1
v 8.9.4
- Fix privilege escalation issue with OAuth external users.
......
......@@ -19,6 +19,8 @@ class Issue < ActiveRecord::Base
belongs_to :project
belongs_to :moved_to, class_name: 'Issue'
has_many :events, as: :target, dependent: :destroy
validates :project, presence: true
scope :cared, ->(user) { where(assignee_id: user) }
......
......@@ -12,6 +12,8 @@ class MergeRequest < ActiveRecord::Base
has_one :merge_request_diff, dependent: :destroy
has_many :events, as: :target, dependent: :destroy
serialize :merge_params, Hash
after_create :create_merge_request_diff, unless: :importing
......
......@@ -17,6 +17,7 @@ class Milestone < ActiveRecord::Base
has_many :labels, -> { distinct.reorder('labels.title') }, through: :issues
has_many :merge_requests
has_many :participants, -> { distinct.reorder('users.name') }, through: :issues, source: :assignee
has_many :events, as: :target, dependent: :destroy
scope :active, -> { with_state(:active) }
scope :closed, -> { with_state(:closed) }
......
......@@ -21,6 +21,7 @@ class Note < ActiveRecord::Base
belongs_to :updated_by, class_name: "User"
has_many :todos, dependent: :destroy
has_many :events, as: :target, dependent: :destroy
delegate :gfm_reference, :local_reference, to: :noteable
delegate :name, to: :project, prefix: true
......
......@@ -2,7 +2,7 @@ module Gitlab
module ImportExport
extend self
VERSION = '0.1.0'
VERSION = '0.1.1'
def export_path(relative_path:)
File.join(storage_path, relative_path)
......
# Model relationships to be included in the project import/export
project_tree:
- issues:
- :events
- notes:
:author
- :author
- :events
- :labels
- :milestones
- milestones:
- :events
- snippets:
- notes:
:author
- :releases
- :events
- project_members:
- :user
- merge_requests:
- notes:
:author
- :author
- :events
- :merge_request_diff
- :events
- pipelines:
- notes:
:author
- :author
- :events
- :statuses
- :variables
- :triggers
......
......@@ -33,6 +33,7 @@ module Gitlab
update_user_references
update_project_references
reset_ci_tokens if @relation_name == 'Ci::Trigger'
@relation_hash['data'].deep_symbolize_keys! if @relation_name == :events && @relation_hash['data']
generate_imported_object
end
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -24,6 +24,12 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do
expect(Ci::Pipeline.first.notes).not_to be_empty
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
......@@ -34,7 +34,7 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do
end
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
it 'has milestones' do
......@@ -132,7 +132,7 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do
statuses: [commit_status])
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: merge_request, project: project)
create(:note, noteable: snippet, project: project)
......@@ -140,6 +140,9 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do
author: user,
project: project,
commit_id: ci_pipeline.sha)
create(:event, target: milestone, project: project, action: Event::CREATED, author: user)
project
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