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