Commit e77c72dc authored by Doug Stull's avatar Doug Stull

Observe secondary email addresses when adding a member

- needed to match UI functionality and desired
  functionality.

Changelog: changed
parent 3f535e69
......@@ -334,7 +334,7 @@ class Member < ApplicationRecord
return User.find_by(id: user) if user.is_a?(Integer)
User.find_by(email: user) || user
User.find_by_any_email(user) || user
end
def retrieve_member(source, user, existing_members)
......
---
title: Observe secondary email addresses when adding a member
merge_request: 62024
author:
type: changed
......@@ -580,6 +580,18 @@ RSpec.describe Member do
end
end
context 'when called with a known user secondary email' do
let(:secondary_email) { create(:email, email: 'secondary@example.com', user: user) }
it 'adds the user as a member' do
expect(source.users).not_to include(user)
described_class.add_user(source, secondary_email.email, :maintainer)
expect(source.users.reload).to include(user)
end
end
context 'when called with an unknown user email' do
it 'creates an invited member' do
expect(source.users).not_to include(user)
......
......@@ -3,7 +3,7 @@
require 'spec_helper'
RSpec.describe Members::InviteService, :aggregate_failures, :clean_gitlab_redis_shared_state, :sidekiq_inline do
let_it_be(:project) { create(:project) }
let_it_be(:project, reload: true) { create(:project) }
let_it_be(:user) { project.owner }
let_it_be(:project_user) { create(:user) }
let_it_be(:namespace) { project.namespace }
......@@ -23,6 +23,18 @@ RSpec.describe Members::InviteService, :aggregate_failures, :clean_gitlab_redis_
it_behaves_like 'records an onboarding progress action', :user_added
end
context 'when email belongs to an existing user as a secondary email' do
let(:secondary_email) { create(:email, email: 'secondary@example.com', user: project_user) }
let(:params) { { email: secondary_email.email } }
it 'adds an existing user to members', :aggregate_failures do
expect_to_create_members(count: 1)
expect(result[:status]).to eq(:success)
expect(project.users).to include project_user
expect(project.members.last).not_to be_invite
end
end
context 'when email is not a valid email' do
let(:params) { { email: '_bogus_' } }
......
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