mirror of
https://github.com/opf/openproject.git
synced 2026-06-14 03:30:14 +00:00
[JIM-112] Capital letters in user email or login break import with error.
https://community.openproject.org/wp/JIM-112
This commit is contained in:
@@ -51,8 +51,8 @@ module Import
|
|||||||
|
|
||||||
def try_to_find_existing_op_users
|
def try_to_find_existing_op_users
|
||||||
op_attributes = to_op_attributes
|
op_attributes = to_op_attributes
|
||||||
User.where(login: op_attributes[:login]).or(
|
User.by_login(op_attributes[:login]).or(
|
||||||
User.where(mail: op_attributes[:mail])
|
User.where("LOWER(mail) = ?", op_attributes[:mail]&.downcase)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -384,10 +384,16 @@ module Import
|
|||||||
|
|
||||||
jira_user = Import::JiraUser.find_by(jira_user_key:, jira_import: @jira_import)
|
jira_user = Import::JiraUser.find_by(jira_user_key:, jira_import: @jira_import)
|
||||||
if jira_user
|
if jira_user
|
||||||
JiraOpenProjectReference.find_by!(
|
reference = JiraOpenProjectReference.find_by(
|
||||||
jira_entity_class: "Import::JiraUser",
|
jira_entity_class: jira_user.class.to_s,
|
||||||
jira_entity_id: jira_user.id
|
jira_entity_id: jira_user.id
|
||||||
).op_leg
|
)
|
||||||
|
if reference
|
||||||
|
reference.op_leg
|
||||||
|
else
|
||||||
|
raise "Import::JiraOpenProjectReference with jira_entity_class #{jira_user.class} " \
|
||||||
|
"and jira_entity_id #{jira_user.id} not found!"
|
||||||
|
end
|
||||||
else
|
else
|
||||||
raise "Import::JiraUser with jira_user_key #{jira_user_key} not found!"
|
raise "Import::JiraUser with jira_user_key #{jira_user_key} not found!"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -110,6 +110,69 @@ RSpec.describe Import::JiraUser do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#try_to_find_existing_op_users" do
|
||||||
|
subject(:result) { jira_user.try_to_find_existing_op_users }
|
||||||
|
|
||||||
|
let(:payload) { { "displayName" => "Test User", "name" => "testuser", "emailAddress" => "test@example.com" } }
|
||||||
|
|
||||||
|
context "when no matching user exists" do
|
||||||
|
it "returns an empty relation" do
|
||||||
|
expect(result).to be_empty
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when a user with matching login exists (case-insensitive)" do
|
||||||
|
let!(:existing_user) { create(:user, login: "TestUser", mail: "other@example.com") }
|
||||||
|
|
||||||
|
it "finds the user" do
|
||||||
|
expect(result).to contain_exactly(existing_user)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when a user with matching email exists (case-insensitive)" do
|
||||||
|
let!(:existing_user) { create(:user, login: "otherlogin", mail: "TEST@EXAMPLE.COM") }
|
||||||
|
|
||||||
|
it "finds the user" do
|
||||||
|
expect(result).to contain_exactly(existing_user)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when a user matches both login and email" do
|
||||||
|
let!(:existing_user) { create(:user, login: "TESTUSER", mail: "TEST@example.com") }
|
||||||
|
|
||||||
|
it "finds the user once" do
|
||||||
|
expect(result).to contain_exactly(existing_user)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when different users match login and email respectively" do
|
||||||
|
let!(:user_by_login) { create(:user, login: "TESTUSER", mail: "different@example.com") }
|
||||||
|
let!(:user_by_email) { create(:user, login: "differentlogin", mail: "TEST@EXAMPLE.COM") }
|
||||||
|
|
||||||
|
it "finds both users" do
|
||||||
|
expect(result).to contain_exactly(user_by_login, user_by_email)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when email is nil in payload" do
|
||||||
|
let(:payload) { { "displayName" => "Test User", "name" => "testuser", "emailAddress" => nil } }
|
||||||
|
let!(:existing_user) { create(:user, login: "TESTUSER", mail: "any@example.com") }
|
||||||
|
|
||||||
|
it "still finds users by login" do
|
||||||
|
expect(result).to contain_exactly(existing_user)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when email separator is used" do
|
||||||
|
let(:payload) { { "displayName" => "Test User", "name" => "othername", "emailAddress" => "any@example.com" } }
|
||||||
|
let!(:existing_user) { create(:user, login: "testname", mail: "any+test@example.com") }
|
||||||
|
|
||||||
|
it "considers the email to be different and does not find it this user account" do
|
||||||
|
expect(result).to be_empty
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#sanitize_name (private)" do
|
describe "#sanitize_name (private)" do
|
||||||
subject(:jira_user) { described_class.new(payload: {}) }
|
subject(:jira_user) { described_class.new(payload: {}) }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user