FIX: Automatically add user to groups after updating email address

This commit is contained in:
Gerhard Schlager 2018-05-08 21:23:45 +02:00
parent dc93c1b433
commit 52db0b31c1
2 changed files with 12 additions and 2 deletions

View File

@ -86,6 +86,7 @@ class EmailUpdater
when EmailChangeRequest.states[:authorizing_new]
change_req.update_column(:change_state, EmailChangeRequest.states[:complete])
user.primary_email.update!(email: token.email)
user.set_automatic_groups
confirm_result = :complete
end
else

View File

@ -61,6 +61,15 @@ describe UsersEmailController do
expect(user.user_stat.reset_bounce_score_after).to eq(nil)
end
it 'automatically adds the user to a group when the email matches' do
group = Fabricate(:group, automatic_membership_email_domains: "example.com")
get "/u/authorize-email/#{user.email_tokens.last.token}"
expect(response).to be_success
expect(group.reload.users.include?(user)).to eq(true)
end
context 'second factor required' do
let!(:second_factor) { Fabricate(:user_second_factor, user: user) }
@ -93,8 +102,8 @@ describe UsersEmailController do
response_body = response.body
expect(response.body).not_to include(I18n.t("login.second_factor_title"))
expect(response.body).not_to include(I18n.t("login.invalid_second_factor_code"))
expect(response_body).not_to include(I18n.t("login.second_factor_title"))
expect(response_body).not_to include(I18n.t("login.invalid_second_factor_code"))
end
end
end