FIX: return 422 if the invite is already redeemed

This commit is contained in:
Arpit Jalan 2015-09-16 17:27:32 +05:30
parent cc75890cd4
commit f2c1dbaa68
2 changed files with 6 additions and 3 deletions

View File

@ -60,8 +60,11 @@ class InvitesController < ApplicationController
end
# generate invite link
invite_link = Invite.generate_invite_link(params[:email], current_user, topic, group_ids)
if invite_link = Invite.generate_invite_link(params[:email], current_user, topic, group_ids)
render_json_dump(invite_link)
else
render json: failed_json, status: 422
end
end
def create_disposable_invite

View File

@ -79,7 +79,7 @@ class Invite < ActiveRecord::Base
# generate invite link
def self.generate_invite_link(email, invited_by, topic=nil, group_ids=nil)
invite = create_invite_by_email(email, invited_by, topic, group_ids, false)
return "#{Discourse.base_url}/invites/#{invite.invite_key}"
return "#{Discourse.base_url}/invites/#{invite.invite_key}" if invite
end
# Create an invite for a user, supplying an optional topic