FIX: better error message when invited user already exists

This commit is contained in:
Arpit Jalan 2017-03-22 00:57:25 +05:30
parent e8fc8f0bb6
commit 295cf8839e
5 changed files with 5 additions and 6 deletions

View File

@ -2,7 +2,7 @@
{{#if model.error}} {{#if model.error}}
<div class="alert alert-error"> <div class="alert alert-error">
<button class="close" data-dismiss="alert">×</button> <button class="close" data-dismiss="alert">×</button>
{{errorMessage}} {{{errorMessage}}}
</div> </div>
{{/if}} {{/if}}
{{#if model.finished}} {{#if model.finished}}

View File

@ -103,7 +103,7 @@ class Invite < ActiveRecord::Base
if user if user
extend_permissions(topic, user, invited_by) if topic extend_permissions(topic, user, invited_by) if topic
return nil raise StandardError.new I18n.t("invite.user_exists", email: lower_email, username: user.username)
end end
invite = Invite.with_deleted invite = Invite.with_deleted

View File

@ -138,6 +138,7 @@ en:
invite: invite:
not_found: "Your invite token is invalid. Please contact the site's administrator." not_found: "Your invite token is invalid. Please contact the site's administrator."
user_exists: "There's no need to invite <b>%{email}</b>, they <a href='/users/%{username}/summary'>already have an account!</a>"
bulk_invite: bulk_invite:
file_should_be_csv: "The uploaded file should be of csv format." file_should_be_csv: "The uploaded file should be of csv format."

View File

@ -152,11 +152,10 @@ describe Invite do
context 'an existing user' do context 'an existing user' do
let(:topic) { Fabricate(:topic, category_id: nil, archetype: 'private_message') } let(:topic) { Fabricate(:topic, category_id: nil, archetype: 'private_message') }
let(:coding_horror) { Fabricate(:coding_horror) } let(:coding_horror) { Fabricate(:coding_horror) }
let!(:invite) { topic.invite_by_email(topic.user, coding_horror.email) }
it "works" do it "works" do
# doesn't create an invite # doesn't create an invite
expect(invite).to be_blank expect { topic.invite_by_email(topic.user, coding_horror.email) }.to raise_error(StandardError)
# gives the user permission to access the topic # gives the user permission to access the topic
expect(topic.allowed_users.include?(coding_horror)).to eq(true) expect(topic.allowed_users.include?(coding_horror)).to eq(true)

View File

@ -1773,8 +1773,7 @@ describe Topic do
it "should add user to the group" do it "should add user to the group" do
expect(Guardian.new(walter).can_see?(group_private_topic)).to be_falsey expect(Guardian.new(walter).can_see?(group_private_topic)).to be_falsey
invite = group_private_topic.invite(group_manager, walter.email) expect { group_private_topic.invite(group_manager, walter.email) }.to raise_error(StandardError)
expect(invite).to be_nil
expect(walter.groups).to include(group) expect(walter.groups).to include(group)
expect(Guardian.new(walter).can_see?(group_private_topic)).to be_truthy expect(Guardian.new(walter).can_see?(group_private_topic)).to be_truthy
end end