Skip to content

Instantly share code, notes, and snippets.

@bplexico
Created May 26, 2013 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bplexico/5653913 to your computer and use it in GitHub Desktop.
Save bplexico/5653913 to your computer and use it in GitHub Desktop.
Before refactoring Post to remove duplication
# 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
# Ensure new users can not put too many images in a post
def max_images_validator
return if acting_user.present? && acting_user.has_trust_level?(:basic)
errors.add(:base, I18n.t(:too_many_images, count: SiteSetting.newuser_max_images)) if image_count > SiteSetting.newuser_max_images
end
# Ensure new users can not put too many links in a post
def max_links_validator
return if acting_user.present? && acting_user.has_trust_level?(:basic)
errors.add(:base, I18n.t(:too_many_links, count: SiteSetting.newuser_max_links)) if link_count > SiteSetting.newuser_max_links
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment