mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
Merge pull request #2603 from techAPJ/patch-1
FEATURE: allow staff to send multiple invites to same email
This commit is contained in:
commit
7cc4a157f6
5 changed files with 37 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
#
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue