Refactor: Topic#invite_by_email

Extract Topic#email_already_existas_for? and Topic#grant_permission_to_user
This commit is contained in:
Rafael George 2013-10-03 17:06:14 -04:00
parent db1f8370ee
commit 26c090439d
1 changed files with 10 additions and 5 deletions

View File

@ -426,11 +426,7 @@ class Topic < ActiveRecord::Base
invite = Invite.create(invited_by: invited_by, email: lower_email)
unless invite.valid?
# If the email already exists, grant permission to that user
if invite.email_already_exists and private_message?
user = User.where(email: lower_email).first
topic_allowed_users.create!(user_id: user.id)
end
grant_permission_to_user if email_already_exists_for?(invite)
return
end
@ -444,6 +440,15 @@ class Topic < ActiveRecord::Base
invite
end
def email_already_exists_for?(invite)
invite.email_already_exists and private_message?
end
def grant_permission_to_user
User.where(email: lower_email).first
topic_allowed_users.create!(user_id: user.id)
end
def max_post_number
posts.maximum(:post_number).to_i
end