automatically approve invited users on forum where moderators must approve (keep in mind only moderators can invite)

speed up specs a touch
allow invite controller to accept an email in absence of user (cleans up API)
This commit is contained in:
Sam
2013-07-11 11:21:39 +10:00
parent 7792b7da48
commit 1aef6de4b0
5 changed files with 42 additions and 24 deletions

View File

@ -190,12 +190,20 @@ class TopicsController < ApplicationController
end
def invite
params.require(:user)
username_or_email = params[:user]
if username_or_email
# provides a level of protection for hashes
params.require(:user)
else
params.require(:email)
username_or_email = params[:email]
end
topic = Topic.where(id: params[:topic_id]).first
guardian.ensure_can_invite_to!(topic)
if topic.invite(current_user, params[:user])
user = User.find_by_username_or_email(params[:user])
if topic.invite(current_user, username_or_email)
user = User.find_by_username_or_email(username_or_email)
if user
render_json_dump BasicUserSerializer.new(user, scope: guardian, root: 'user')
else