From 430967c3549a9af264052132d5033d7564e6cc63 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Thu, 9 Oct 2014 20:14:15 +0530 Subject: [PATCH] FIX: invite email should be verified against email_domains_blacklist --- app/jobs/regular/bulk_invite.rb | 8 +++++++- app/models/invite.rb | 1 + spec/models/invite_spec.rb | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/jobs/regular/bulk_invite.rb b/app/jobs/regular/bulk_invite.rb index 54c67ec9ccb..835ac0e6c75 100644 --- a/app/jobs/regular/bulk_invite.rb +++ b/app/jobs/regular/bulk_invite.rb @@ -98,7 +98,13 @@ module Jobs email = csv_info[0] group_ids = get_group_ids(csv_info[1], csv_line_number) topic = get_topic(csv_info[2], csv_line_number) - Invite.invite_by_email(email, @current_user, topic, group_ids) + begin + Invite.invite_by_email(email, @current_user, topic, group_ids) + rescue => e + log "Error inviting '#{email}' -- #{e}" + @sent -= 1 + @failed += 1 + end end def log(message) diff --git a/app/models/invite.rb b/app/models/invite.rb index 1fdc17453a0..0c526ae0762 100644 --- a/app/models/invite.rb +++ b/app/models/invite.rb @@ -10,6 +10,7 @@ class Invite < ActiveRecord::Base has_many :topic_invites has_many :topics, through: :topic_invites, source: :topic validates_presence_of :invited_by_id + validates :email, email: true before_create do self.invite_key ||= SecureRandom.hex diff --git a/spec/models/invite_spec.rb b/spec/models/invite_spec.rb index 8fbdfd96faa..d710bc3a80d 100644 --- a/spec/models/invite_spec.rb +++ b/spec/models/invite_spec.rb @@ -21,6 +21,21 @@ describe Invite do end + context 'email validators' do + let(:coding_horror) { Fabricate(:coding_horror) } + let(:invite) { Invite.create(email: "test@mailinator.com", invited_by: coding_horror) } + + it "should not allow an invite with blacklisted email" do + invite.should_not be_valid + end + + it "should allow an invite with non-blacklisted email" do + invite = Fabricate(:invite, email: "test@mail.com", invited_by: coding_horror) + invite.should be_valid + end + + end + context '#create' do context 'saved' do