mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 23:36:11 +08:00
Adding post details in preparation for the API importer code.
This commit is contained in:
@ -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)
|
||||
|
6
app/models/post_detail.rb
Normal file
6
app/models/post_detail.rb
Normal 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
|
Reference in New Issue
Block a user