Adding post details in preparation for the API importer code.

This commit is contained in:
James Edward Gray II
2013-10-15 09:21:30 -05:00
parent 20039860eb
commit 1aa9fc982d
6 changed files with 65 additions and 0 deletions

View File

@ -34,6 +34,8 @@ class Post < ActiveRecord::Base
has_one :post_search_data
has_many :post_details
validates_with ::Validators::PostValidator
# We can pass several creating options to a post via attributes
@ -56,6 +58,17 @@ class Post < ActiveRecord::Base
@types ||= Enum.new(:regular, :moderator_action)
end
def self.find_by_detail(key, value)
includes(:post_details).where( "post_details.key = ? AND " +
"post_details.value = ?",
key,
value ).first
end
def add_detail(key, value, extra = nil)
post_details.build(key: key, value: value, extra: extra)
end
def limit_posts_per_day
if user.created_at > 1.day.ago && post_number > 1
RateLimiter.new(user, "first-day-replies-per-day:#{Date.today.to_s}", SiteSetting.max_replies_in_first_day, 1.day.to_i)

View File

@ -0,0 +1,6 @@
class PostDetail < ActiveRecord::Base
belongs_to :post
validates_presence_of :key, :value
validates_uniqueness_of :key, scope: :post_id
end