mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-02-24 23:44:09 -05:00
FEATURE: allow staff to send multiple invites to same email
This commit is contained in:
parent
b942436d7b
commit
f571abfaaf
5 changed files with 37 additions and 1 deletions
|
@ -35,6 +35,11 @@ class InvitesController < ApplicationController
|
||||||
|
|
||||||
guardian.ensure_can_invite_to_forum!(group_ids)
|
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)
|
if Invite.invite_by_email(params[:email], current_user, topic=nil, group_ids)
|
||||||
render json: success_json
|
render json: success_json
|
||||||
else
|
else
|
||||||
|
|
|
@ -205,6 +205,6 @@ end
|
||||||
#
|
#
|
||||||
# Indexes
|
# 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
|
# 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?
|
user.admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def can_send_multiple_invites?(user)
|
||||||
|
user.staff?
|
||||||
|
end
|
||||||
|
|
||||||
def can_see_private_messages?(user_id)
|
def can_see_private_messages?(user_id)
|
||||||
is_admin? || (authenticated? && @user.id == user_id)
|
is_admin? || (authenticated? && @user.id == user_id)
|
||||||
end
|
end
|
||||||
|
|
|
@ -53,6 +53,14 @@ describe InvitesController do
|
||||||
response.should_not be_success
|
response.should_not be_success
|
||||||
end
|
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
|
it "allows admins to invite to groups" do
|
||||||
group = Fabricate(:group)
|
group = Fabricate(:group)
|
||||||
log_in(:admin)
|
log_in(:admin)
|
||||||
|
@ -60,6 +68,14 @@ describe InvitesController do
|
||||||
response.should be_success
|
response.should be_success
|
||||||
Invite.find_by(email: email).invited_groups.count.should == 1
|
Invite.find_by(email: email).invited_groups.count.should == 1
|
||||||
end
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue