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
# Ensure maximum amount of mentions in a post | |
def max_mention_validator | |
if acting_user.present? && acting_user.has_trust_level?(:basic) | |
errors.add(:base, I18n.t(:too_many_mentions, count: SiteSetting.max_mentions_per_post)) if raw_mentions.size > SiteSetting.max_mentions_per_post | |
else | |
errors.add(:base, I18n.t(:too_many_mentions_newuser, count: SiteSetting.newuser_max_mentions_per_post)) if raw_mentions.size > SiteSetting.newuser_max_mentions_per_post | |
end | |
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 add_error_if_count_exceeded(key_for_translation, current_count, max_count) | |
errors.add(:base, I18n.t(key_for_translation, count: max_count)) if current_count > max_count | |
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 acting_user_is_trusted? | |
acting_user.present? && acting_user.has_trust_level?(:basic) | |
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
# Ensure maximum amount of mentions in a post | |
def max_mention_validator | |
if acting_user_is_trusted? | |
errors.add(:base, I18n.t(:too_many_mentions, count: SiteSetting.max_mentions_per_post)) if raw_mentions.size > SiteSetting.max_mentions_per_post | |
else | |
errors.add(:base, I18n.t(:too_many_mentions_newuser, count: SiteSetting.newuser_max_mentions_per_post)) if raw_mentions.size > SiteSetting.newuser_max_mentions_per_post | |
end | |
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
# Ensure maximum amount of mentions in a post | |
def max_mention_validator | |
if acting_user_is_trusted? | |
add_error_if_count_exceeded(:too_many_mentions, raw_mentions.size, SiteSetting.max_mentions_per_post) | |
else | |
add_error_if_count_exceeded(:too_many_mentions_newuser, raw_mentions.size, SiteSetting.newuser_max_mentions_per_post) | |
end | |
end | |
# Ensure new users can not put too many images in a post |
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 | |
end | |
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 | |
InviteRedeemer.new(self).redeem unless expired? || destroyed? | |
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 | |
# Avoid a race condition | |
row_count = Invite.update_all('redeemed_at = CURRENT_TIMESTAMP', | |
['id = ? AND redeemed_at IS NULL AND created_at >= ?', invite.id, SiteSetting.invite_expiry_days.days.ago]) | |
if row_count == 1 | |
# Create the user if we are redeeming the invite and the user doesn't exist |
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 | |
# Avoid a race condition | |
row_count = Invite.update_all('redeemed_at = CURRENT_TIMESTAMP', | |
['id = ? AND redeemed_at IS NULL AND created_at >= ?', id, SiteSetting.invite_expiry_days.days.ago]) | |
if row_count == 1 | |
# Create the user if we are redeeming the invite and the user doesn't exist |
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 = nil | |
Invite.transaction do | |
# Avoid a race condition | |
row_count = Invite.update_all('redeemed_at = CURRENT_TIMESTAMP', | |
['id = ? AND redeemed_at IS NULL AND created_at >= ?', invite.id, SiteSetting.invite_expiry_days.days.ago]) | |
if row_count == 1 |
OlderNewer