This commit is contained in:
albert
2012-03-12 17:50:45 -04:00
parent d5569bed5b
commit dd5a965884
17 changed files with 118 additions and 63 deletions

View File

@@ -15,7 +15,7 @@ class ForumPostsController < ApplicationController
end
def index
@search = ForumPost.search(params[:search])
@search = ForumPost.active.search(params[:search])
@forum_posts = @search.paginate(params[:page]).order("forum_posts.id desc")
respond_with(@forum_posts)
end
@@ -44,7 +44,14 @@ class ForumPostsController < ApplicationController
def destroy
@forum_post = ForumPost.find(params[:id])
check_privilege(@forum_post)
@forum_post.destroy
@forum_post.update_attribute(:is_deleted, true)
respond_with(@forum_post)
end
def undelete
@forum_post = ForumPost.find(params[:id])
check_privilege(@forum_post)
@forum_post.update_attribute(:is_deleted, false)
respond_with(@forum_post)
end

View File

@@ -18,7 +18,7 @@ class ForumTopicsController < ApplicationController
end
def index
@search = ForumTopic.search(params[:search])
@search = ForumTopic.active.search(params[:search])
@forum_topics = @search.paginate(params[:page]).order("is_sticky DESC, updated_at DESC")
respond_with(@forum_topics)
end

View File

@@ -15,7 +15,7 @@ class PoolsController < ApplicationController
end
def index
@search = Pool.search(params[:search])
@search = Pool.active.search(params[:search])
@pools = @search.paginate(params[:page])
respond_with(@pools)
end

View File

@@ -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"

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -1,6 +1,11 @@
<article data-forum-post-id="<%= forum_post.id %>">
<div class="author">
<h4><%= link_to forum_post.creator.name, user_path(forum_post.creator_id) %></h4>
<h4>
<%= link_to forum_post.creator.name, user_path(forum_post.creator_id) %>
<% if forum_post.is_deleted? %>
(deleted)
<% end %>
</h4>
<p>
<%= time_ago_in_words(forum_post.created_at) %> ago
</p>
@@ -12,7 +17,11 @@
<menu>
<li><%= link_to "Quote", new_forum_post_path(:post_id => forum_post.id) %></li>
<% if CurrentUser.user.is_janitor? || CurrentUser.user.id == forum_post.creator_id %>
<li><%= link_to "Delete", forum_post_path(forum_post.id), :confirm => "Do you really want to delete this post?", :method => :delete, :remote => true %></li>
<% if forum_post.is_deleted %>
<li><%= link_to "Undelete", undelete_forum_post_path(forum_post.id), :method => :post, :remote => true %></li>
<% else %>
<li><%= link_to "Delete", forum_post_path(forum_post.id), :confirm => "Do you really want to delete this post?", :method => :delete, :remote => true %></li>
<% end %>
<li><%= link_to "Edit", edit_forum_post_path(forum_post.id) %></li>
<% end %>
</menu>

View File

@@ -0,0 +1 @@
location.reload();

View File

@@ -1,6 +1,11 @@
<div id="c-forum-topics">
<div id="a-show">
<h1>Topic: <%= @forum_topic.title %></h1>
<h1>
Topic: <%= @forum_topic.title %>
<% if @forum_topic.is_deleted? %>
(deleted)
<% end %>
</h1>
<% if @forum_topic.is_locked? %>
<div class="notice">

View File

@@ -5,6 +5,7 @@
<%= f.input :name %>
<%= f.input :description %>
<%= f.input :post_ids, :label => "Posts" %>
<%= f.input :is_active %>
<%= f.button :submit %>
<% end %>
</div>