fixes
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
class ForumPost < ActiveRecord::Base
|
||||
attr_accessible :body, :topic_id, :as => [:member, :privileged, :contributor, :janitor, :admin, :moderator, :default]
|
||||
attr_accessible :is_locked, :is_sticky, :as => [:admin, :moderator]
|
||||
attr_accessible :is_locked, :is_sticky, :is_deleted, :as => [:admin, :moderator]
|
||||
belongs_to :creator, :class_name => "User"
|
||||
belongs_to :topic, :class_name => "ForumTopic"
|
||||
before_validation :initialize_creator, :on => :create
|
||||
before_validation :initialize_updater
|
||||
before_validation :initialize_is_deleted, :on => :create
|
||||
after_save :update_topic_updated_at
|
||||
validates_presence_of :body, :creator_id
|
||||
validate :validate_topic_is_unlocked
|
||||
before_destroy :validate_topic_is_unlocked
|
||||
scope :body_matches, lambda {|body| where(["forum_posts.text_index @@ plainto_tsquery(?)", body])}
|
||||
scope :for_user, lambda {|user_id| where("forum_posts.creator_id = ?", user_id)}
|
||||
scope :active, where("is_deleted = false")
|
||||
search_methods :body_matches
|
||||
|
||||
def self.new_reply(params)
|
||||
@@ -55,6 +57,10 @@ class ForumPost < ActiveRecord::Base
|
||||
self.updater_id = CurrentUser.id
|
||||
end
|
||||
|
||||
def initialize_is_deleted
|
||||
self.is_deleted = false if is_deleted.nil?
|
||||
end
|
||||
|
||||
def build_response
|
||||
dup.tap do |x|
|
||||
x.body = "[quote]\n#{x.body}\n[/quote]\n\n"
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
class ForumTopic < ActiveRecord::Base
|
||||
attr_accessible :title, :original_post_attributes, :as => [:member, :privileged, :contributor, :janitor, :moderator, :admin, :default]
|
||||
attr_accessible :is_sticky, :is_locked, :as => [:admin, :moderator]
|
||||
attr_accessible :is_sticky, :is_locked, :is_deleted, :as => [:admin, :moderator]
|
||||
belongs_to :creator, :class_name => "User"
|
||||
belongs_to :updater, :class_name => "User"
|
||||
has_many :posts, :class_name => "ForumPost", :order => "forum_posts.id asc", :foreign_key => "topic_id", :dependent => :destroy
|
||||
has_one :original_post, :class_name => "ForumPost", :order => "forum_posts.id asc", :foreign_key => "topic_id"
|
||||
before_validation :initialize_creator, :on => :create
|
||||
before_validation :initialize_updater
|
||||
before_validation :initialize_is_deleted, :on => :create
|
||||
validates_presence_of :title, :creator_id
|
||||
validates_associated :original_post
|
||||
scope :title_matches, lambda {|title| where(["text_index @@ plainto_tsquery(?)", title])}
|
||||
scope :active, where("is_deleted = false")
|
||||
search_methods :title_matches
|
||||
accepts_nested_attributes_for :original_post
|
||||
|
||||
@@ -17,6 +19,10 @@ class ForumTopic < ActiveRecord::Base
|
||||
creator_id == user.id || user.is_moderator?
|
||||
end
|
||||
|
||||
def initialize_is_deleted
|
||||
self.is_deleted = false if is_deleted.nil?
|
||||
end
|
||||
|
||||
def initialize_creator
|
||||
self.creator_id = CurrentUser.id
|
||||
end
|
||||
|
||||
@@ -8,10 +8,12 @@ class Pool < ActiveRecord::Base
|
||||
has_many :versions, :class_name => "PoolVersion", :dependent => :destroy, :order => "pool_versions.id ASC"
|
||||
before_validation :normalize_name
|
||||
before_validation :normalize_post_ids
|
||||
before_validation :initialize_is_active, :on => :create
|
||||
before_validation :initialize_creator, :on => :create
|
||||
after_save :create_version
|
||||
before_destroy :create_mod_action_for_destroy
|
||||
attr_accessible :name, :description, :post_ids, :post_id_array, :is_active, :post_count
|
||||
scope :active, where("is_active = true")
|
||||
|
||||
def self.name_to_id(name)
|
||||
if name =~ /^\d+$/
|
||||
@@ -52,6 +54,10 @@ class Pool < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def initialize_is_active
|
||||
self.is_active = true if is_active.nil?
|
||||
end
|
||||
|
||||
def initialize_creator
|
||||
self.creator_id = CurrentUser.id
|
||||
end
|
||||
|
||||
@@ -586,7 +586,7 @@ class Post < ActiveRecord::Base
|
||||
def pools
|
||||
@pools ||= begin
|
||||
pool_ids = pool_string.scan(/\d+/)
|
||||
Pool.where(["id in (?)", pool_ids])
|
||||
Pool.where(["is_active = true and id in (?)", pool_ids])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user