mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Merge pull request #1495 from cored/refactor-topic-invite-by-email
Refactor: Topic model
This commit is contained in:
commit
f8625b5510
@ -436,11 +436,7 @@ class Topic < ActiveRecord::Base
|
|||||||
invite = Invite.create(invited_by: invited_by, email: lower_email)
|
invite = Invite.create(invited_by: invited_by, email: lower_email)
|
||||||
unless invite.valid?
|
unless invite.valid?
|
||||||
|
|
||||||
# If the email already exists, grant permission to that user
|
grant_permission_to_user(lower_email) if email_already_exists_for?(invite)
|
||||||
if invite.email_already_exists and private_message?
|
|
||||||
user = User.where(email: lower_email).first
|
|
||||||
topic_allowed_users.create!(user_id: user.id)
|
|
||||||
end
|
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -454,6 +450,15 @@ class Topic < ActiveRecord::Base
|
|||||||
invite
|
invite
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def email_already_exists_for?(invite)
|
||||||
|
invite.email_already_exists and private_message?
|
||||||
|
end
|
||||||
|
|
||||||
|
def grant_permission_to_user(lower_email)
|
||||||
|
user = User.where(email: lower_email).first
|
||||||
|
topic_allowed_users.create!(user_id: user.id)
|
||||||
|
end
|
||||||
|
|
||||||
def max_post_number
|
def max_post_number
|
||||||
posts.maximum(:post_number).to_i
|
posts.maximum(:post_number).to_i
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user