Commit 1823fe46 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Merge branch 'kassio/bulkimports-remove-epic-author-finding-duplication' into 'master'

BulkImports: Remove epics author finding duplication

See merge request gitlab-org/gitlab!57606
parents f8c05de7 038301fb
...@@ -11,6 +11,8 @@ module EE ...@@ -11,6 +11,8 @@ module EE
query: EE::BulkImports::Groups::Graphql::GetEpicsQuery query: EE::BulkImports::Groups::Graphql::GetEpicsQuery
transformer ::BulkImports::Common::Transformers::ProhibitedAttributesTransformer transformer ::BulkImports::Common::Transformers::ProhibitedAttributesTransformer
transformer ::BulkImports::Common::Transformers::UserReferenceTransformer,
reference: :author
transformer EE::BulkImports::Groups::Transformers::EpicAttributesTransformer transformer EE::BulkImports::Groups::Transformers::EpicAttributesTransformer
def transform(_, data) def transform(_, data)
......
...@@ -7,7 +7,6 @@ module EE ...@@ -7,7 +7,6 @@ module EE
class EpicAttributesTransformer class EpicAttributesTransformer
def transform(context, data) def transform(context, data)
data data
.then { |data| add_author_id(context, data) }
.then { |data| add_parent(context, data) } .then { |data| add_parent(context, data) }
.then { |data| add_children(context, data) } .then { |data| add_children(context, data) }
.then { |data| add_labels(context, data) } .then { |data| add_labels(context, data) }
...@@ -15,21 +14,6 @@ module EE ...@@ -15,21 +14,6 @@ module EE
private private
def add_author_id(context, data)
user = find_user_by_email(context, data.dig('author', 'public_email'))
author_id = user&.id || context.current_user.id
data
.merge('author_id' => author_id)
.except('author')
end
def find_user_by_email(context, email)
return if email.blank?
context.group.users.find_by_any_email(email, confirmed: true)
end
def add_parent(context, data) def add_parent(context, data)
data.merge( data.merge(
'parent' => context.group.epics.find_by_iid(data.dig('parent', 'iid')) 'parent' => context.group.epics.find_by_iid(data.dig('parent', 'iid'))
......
...@@ -125,6 +125,7 @@ RSpec.describe EE::BulkImports::Groups::Pipelines::EpicsPipeline, :clean_gitlab_ ...@@ -125,6 +125,7 @@ RSpec.describe EE::BulkImports::Groups::Pipelines::EpicsPipeline, :clean_gitlab_
expect(described_class.transformers) expect(described_class.transformers)
.to contain_exactly( .to contain_exactly(
{ klass: BulkImports::Common::Transformers::ProhibitedAttributesTransformer, options: nil }, { klass: BulkImports::Common::Transformers::ProhibitedAttributesTransformer, options: nil },
{ klass: BulkImports::Common::Transformers::UserReferenceTransformer, options: { reference: :author } },
{ klass: EE::BulkImports::Groups::Transformers::EpicAttributesTransformer, options: nil } { klass: EE::BulkImports::Groups::Transformers::EpicAttributesTransformer, options: nil }
) )
end end
......
...@@ -27,7 +27,6 @@ RSpec.describe EE::BulkImports::Groups::Transformers::EpicAttributesTransformer ...@@ -27,7 +27,6 @@ RSpec.describe EE::BulkImports::Groups::Transformers::EpicAttributesTransformer
'due_date_is_fixed' => false, 'due_date_is_fixed' => false,
'relative_position' => 1073716855, 'relative_position' => 1073716855,
'confidential' => false, 'confidential' => false,
'author_id' => importer_user.id,
'parent' => nil, 'parent' => nil,
'children' => [], 'children' => [],
'labels' => [] 'labels' => []
...@@ -67,57 +66,6 @@ RSpec.describe EE::BulkImports::Groups::Transformers::EpicAttributesTransformer ...@@ -67,57 +66,6 @@ RSpec.describe EE::BulkImports::Groups::Transformers::EpicAttributesTransformer
end end
end end
context 'epic author' do
it 'finds user by primary confirmed email' do
member_user = create(:user, email: 'member@email.com')
group.add_owner(member_user)
data = epic_data(public_email: member_user.email)
transformed_data = subject.transform(context, data)
expect(transformed_data['author_id']).to eq(member_user.id)
end
it 'falls back to the importer user if primary email is not confirmed' do
member_user = create(:user, :unconfirmed, email: 'member@email.com')
group.add_owner(member_user)
data = epic_data(public_email: member_user.email)
transformed_data = subject.transform(context, data)
expect(transformed_data['author_id']).to eq(importer_user.id)
end
it 'findes user by secondary confirmed email' do
secondary_email = 'other@email.com'
member_user = create(:user, email: 'member@email.com')
create(:email, :confirmed, user: member_user, email: secondary_email)
group.add_owner(member_user)
data = epic_data(public_email: secondary_email)
transformed_data = subject.transform(context, data)
expect(transformed_data['author_id']).to eq(member_user.id)
end
it 'falls back to the importer user if secondary email is not confirmed' do
secondary_email = 'other@email.com'
member_user = create(:user, email: 'member@email.com')
create(:email, user: member_user, email: secondary_email)
group.add_owner(member_user)
data = epic_data(public_email: secondary_email)
transformed_data = subject.transform(context, data)
expect(transformed_data['author_id']).to eq(importer_user.id)
end
end
def epic_data(parent_iid: nil, children_iids: [], labels_titles: [], public_email: '') def epic_data(parent_iid: nil, children_iids: [], labels_titles: [], public_email: '')
{ {
'title' => 'title', 'title' => 'title',
...@@ -132,9 +80,6 @@ RSpec.describe EE::BulkImports::Groups::Transformers::EpicAttributesTransformer ...@@ -132,9 +80,6 @@ RSpec.describe EE::BulkImports::Groups::Transformers::EpicAttributesTransformer
'due_date_is_fixed' => false, 'due_date_is_fixed' => false,
'relative_position' => 1073716855, 'relative_position' => 1073716855,
'confidential' => false, 'confidential' => false,
'author' => {
'public_email' => public_email
},
'parent' => { 'parent' => {
'iid' => parent_iid 'iid' => parent_iid
}, },
......
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