mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 11:23:25 +08:00
FEATURE: allow staff to send multiple invites to same email
This commit is contained in:
parent
b942436d7b
commit
f571abfaaf
|
@ -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 New Issue
Block a user