This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if mark_invite_redeemed == 1 | |
... | |
private | |
def mark_invite_redeemed | |
Invite.update_all('redeemed_at = CURRENT_TIMESTAMP', | |
['id = ? AND redeemed_at IS NULL AND created_at >= ?', invite.id, SiteSetting.invite_expiry_days.days.ago]) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def redeem | |
result = nil | |
Invite.transaction do | |
if mark_invite_redeemed == 1 | |
# Create the user if we are redeeming the invite and the user doesn't exist | |
result = create_user_if_missing | |
# If there are topic invites for private topics | |
allow_access_to_private_topics(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def invited_user | |
@invited_user ||= get_existing_user | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def invite_was_redeemed? | |
mark_invite_redeemed == 1 | |
end | |
#results in the new if clause | |
if invite_was_redeemed? | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def process_invitation | |
add_to_private_topics_if_invited | |
add_user_to_invited_topics | |
send_welcome_message | |
notify_invitee | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
InviteRedeemer = Struct.new(:invite) do | |
def redeem | |
result = invited_user | |
Invite.transaction do | |
if mark_invite_redeemed == 1 | |
# Create the user if we are redeeming the invite and the user doesn't exist | |
result = create_user_if_missing | |
# If there are topic invites for private topics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def redeem | |
result = invited_user | |
Invite.transaction do | |
if invite_was_redeemed? | |
result = create_user_if_missing | |
process_invitation | |
end | |
end | |
result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def invited_user | |
@invited_user ||= get_invited_user | |
end | |
def get_invited_user | |
result = get_existing_user | |
result ||= create_new_user | |
result.send_welcome_message = false | |
result | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
InviteRedeemer = Struct.new(:invite) do | |
def redeem | |
Invite.transaction do | |
process_invitation if invite_was_redeemed? | |
end | |
invited_user | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SearchObserver < ActiveRecord::Observer | |
observe :topic, :post, :user, :category | |
def self.scrub_html_for_search(html) | |
HtmlScrubber.scrub(html) | |
end | |
def self.update_index(table, id, search_data) | |
table_name = "#{table}_search_data" | |
foreign_key = "#{table}_id" |