Commit b19e60a4 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'kassio/bulkimports-epics-author' into 'master'

BulkImports: Associate mapped users to imported epics

See merge request gitlab-org/gitlab!53296
parents bb3831b4 eb75e65a
---
title: 'BulkImports: Associate mapped users to imported epics'
merge_request: 53296
author:
type: changed
...@@ -34,6 +34,9 @@ module EE ...@@ -34,6 +34,9 @@ module EE
due_date_is_fixed: dueDateIsFixed due_date_is_fixed: dueDateIsFixed
relative_position: relativePosition relative_position: relativePosition
confidential confidential
author {
public_email: publicEmail
}
parent { parent {
iid iid
} }
......
...@@ -23,7 +23,18 @@ module EE ...@@ -23,7 +23,18 @@ module EE
end end
def add_author_id(context, data) def add_author_id(context, data)
data.merge('author_id' => context.current_user.id) 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 end
def add_parent(context, data) def add_parent(context, data)
......
...@@ -3,15 +3,15 @@ ...@@ -3,15 +3,15 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe EE::BulkImports::Groups::Graphql::GetEpicsQuery do RSpec.describe EE::BulkImports::Groups::Graphql::GetEpicsQuery do
describe '#variables' do it 'has a valid query' do
let(:entity) { double(source_full_path: 'test', next_page_for: 'next_page', bulk_import: nil) } context = BulkImports::Pipeline::Context.new(create(:bulk_import_entity))
let(:context) { BulkImports::Pipeline::Context.new(entity) }
it 'returns query variables based on entity information' do result = GitlabSchema.execute(
expected = { full_path: entity.source_full_path, cursor: entity.next_page_for } described_class.to_s,
variables: described_class.variables(context)
).to_h
expect(described_class.variables(context)).to eq(expected) expect(result['errors']).to be_blank
end
end end
describe '#data_path' do describe '#data_path' do
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe EE::BulkImports::Groups::Transformers::EpicAttributesTransformer do RSpec.describe EE::BulkImports::Groups::Transformers::EpicAttributesTransformer do
let(:user) { create(:user) } let_it_be(:importer_user) { create(:user) }
let(:group) { create(:group) } let_it_be(:group) { create(:group) }
let(:bulk_import) { create(:bulk_import, user: user) } let_it_be(:bulk_import) { create(:bulk_import, user: importer_user) }
let(:entity) { create(:bulk_import_entity, bulk_import: bulk_import, group: group) } let_it_be(:entity) { create(:bulk_import_entity, bulk_import: bulk_import, group: group) }
let(:context) { ::BulkImports::Pipeline::Context.new(entity) } let_it_be(:context) { ::BulkImports::Pipeline::Context.new(entity) }
describe '#transform' do describe '#transform' do
it 'transforms the epic attributes' do it 'transforms the epic attributes' do
...@@ -27,7 +27,7 @@ RSpec.describe EE::BulkImports::Groups::Transformers::EpicAttributesTransformer ...@@ -27,7 +27,7 @@ RSpec.describe EE::BulkImports::Groups::Transformers::EpicAttributesTransformer
'relative_position' => 1073716855, 'relative_position' => 1073716855,
'confidential' => false, 'confidential' => false,
'group_id' => group.id, 'group_id' => group.id,
'author_id' => user.id, 'author_id' => importer_user.id,
'parent' => nil, 'parent' => nil,
'children' => [], 'children' => [],
'labels' => [] 'labels' => []
...@@ -67,7 +67,58 @@ RSpec.describe EE::BulkImports::Groups::Transformers::EpicAttributesTransformer ...@@ -67,7 +67,58 @@ RSpec.describe EE::BulkImports::Groups::Transformers::EpicAttributesTransformer
end end
end end
def epic_data(parent_iid: nil, children_iids: [], labels_titles: []) 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: '')
{ {
'title' => 'title', 'title' => 'title',
'description' => 'description', 'description' => 'description',
...@@ -81,6 +132,9 @@ RSpec.describe EE::BulkImports::Groups::Transformers::EpicAttributesTransformer ...@@ -81,6 +132,9 @@ 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