Merge pull request #2603 from techAPJ/patch-1

FEATURE: allow staff to send multiple invites to same email
This commit is contained in:
Robin Ward 2014-07-29 14:58:39 -04:00
commit 7cc4a157f6
5 changed files with 37 additions and 1 deletions

View file

@ -35,6 +35,11 @@ class InvitesController < ApplicationController
guardian.ensure_can_invite_to_forum!(group_ids)
invite_exists = Invite.where(email: params[:email], invited_by_id: current_user.id).first
if invite_exists
guardian.ensure_can_send_multiple_invites!(current_user)
end
if Invite.invite_by_email(params[:email], current_user, topic=nil, group_ids)
render json: success_json
else

View file

@ -205,6 +205,6 @@ end
#
# Indexes
#
# index_invites_on_email_and_invited_by_id (email,invited_by_id) UNIQUE
# index_invites_on_email_and_invited_by_id (email,invited_by_id)
# index_invites_on_invite_key (invite_key) UNIQUE
#

View file

@ -0,0 +1,11 @@
class RemoveUniqueConstraintFromInvitesIndex < ActiveRecord::Migration
def up
remove_index :invites, [:email, :invited_by_id]
add_index :invites, [:email, :invited_by_id], unique: false
end
def down
remove_index :invites, [:email, :invited_by_id]
add_index :invites, [:email, :invited_by_id], unique: true
end
end

View file

@ -214,6 +214,10 @@ class Guardian
user.admin?
end
def can_send_multiple_invites?(user)
user.staff?
end
def can_see_private_messages?(user_id)
is_admin? || (authenticated? && @user.id == user_id)
end

View file

@ -53,6 +53,14 @@ describe InvitesController do
response.should_not be_success
end
it "fails for normal user if invite email already exists" do
user = log_in(:elder)
invite = Invite.invite_by_email("invite@example.com", user)
invite.reload
post :create, email: invite.email
response.should_not be_success
end
it "allows admins to invite to groups" do
group = Fabricate(:group)
log_in(:admin)
@ -60,6 +68,14 @@ describe InvitesController do
response.should be_success
Invite.find_by(email: email).invited_groups.count.should == 1
end
it "allows admin to send multiple invites to same email" do
user = log_in(:admin)
invite = Invite.invite_by_email("invite@example.com", user)
invite.reload
post :create, email: invite.email
response.should be_success
end
end
end