From dd5a96588484339e1d8eee5612a19de8292ec0cb Mon Sep 17 00:00:00 2001 From: albert Date: Mon, 12 Mar 2012 17:50:45 -0400 Subject: [PATCH] fixes --- Gemfile | 2 +- Gemfile.lock | 102 +++++++++--------- app/controllers/forum_posts_controller.rb | 11 +- app/controllers/forum_topics_controller.rb | 2 +- app/controllers/pools_controller.rb | 2 +- app/models/forum_post.rb | 8 +- app/models/forum_topic.rb | 8 +- app/models/pool.rb | 6 ++ app/models/post.rb | 2 +- app/views/forum_posts/_forum_post.html.erb | 13 ++- app/views/forum_posts/undelete.js.erb | 1 + app/views/forum_topics/show.html.erb | 7 +- app/views/pools/edit.html.erb | 1 + config/routes.rb | 9 +- .../20100221003655_create_forum_topics.rb | 1 + .../20100221005812_create_forum_posts.rb | 1 + script/upgrade_schema.sql | 5 +- 17 files changed, 118 insertions(+), 63 deletions(-) create mode 100644 app/views/forum_posts/undelete.js.erb diff --git a/Gemfile b/Gemfile index 3f6b024c0..9e8d66ac8 100644 --- a/Gemfile +++ b/Gemfile @@ -14,7 +14,7 @@ group :assets do gem "therubyracer" end -gem "rails", "3.2.1" +gem "rails", "3.2.2" gem "pg" gem "memcache-client", :require => "memcache" gem "delayed_job" diff --git a/Gemfile.lock b/Gemfile.lock index c4b1954ad..c92e4c63a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -29,19 +29,19 @@ GIT GIT remote: http://github.com/EmmanuelOga/ffaker.git - revision: 0a281092f4ed985b7f7ae6eb2d03677fbcfc722d + revision: a2bff9d77503a9cf61eb274725b12e5683b2826c specs: - ffaker (1.12.1) + ffaker (1.13.0) GEM remote: http://gemcutter.org/ specs: - actionmailer (3.2.1) - actionpack (= 3.2.1) + actionmailer (3.2.2) + actionpack (= 3.2.2) mail (~> 2.4.0) - actionpack (3.2.1) - activemodel (= 3.2.1) - activesupport (= 3.2.1) + actionpack (3.2.2) + activemodel (= 3.2.2) + activesupport (= 3.2.2) builder (~> 3.0.0) erubis (~> 2.7.0) journey (~> 1.0.1) @@ -49,21 +49,21 @@ GEM rack-cache (~> 1.1) rack-test (~> 0.6.1) sprockets (~> 2.1.2) - activemodel (3.2.1) - activesupport (= 3.2.1) + activemodel (3.2.2) + activesupport (= 3.2.2) builder (~> 3.0.0) - activerecord (3.2.1) - activemodel (= 3.2.1) - activesupport (= 3.2.1) - arel (~> 3.0.0) + activerecord (3.2.2) + activemodel (= 3.2.2) + activesupport (= 3.2.2) + arel (~> 3.0.2) tzinfo (~> 0.3.29) - activeresource (3.2.1) - activemodel (= 3.2.1) - activesupport (= 3.2.1) - activesupport (3.2.1) + activeresource (3.2.2) + activemodel (= 3.2.2) + activesupport (= 3.2.2) + activesupport (3.2.2) i18n (~> 0.6) multi_json (~> 1.0) - arel (3.0.0) + arel (3.0.2) awesome_print (1.0.2) builder (3.0.0) chronic (0.6.7) @@ -79,54 +79,54 @@ GEM erubis (2.7.0) execjs (1.3.0) multi_json (~> 1.0) - factory_girl (2.5.2) + factory_girl (2.6.3) activesupport (>= 2.3.9) hike (1.2.1) i18n (0.6.0) - journey (1.0.1) + journey (1.0.3) json (1.6.5) libv8 (3.3.10.4) - mail (2.4.1) + mail (2.4.3) i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) memcache-client (1.8.5) metaclass (0.0.1) - method_source (0.7.0) + method_source (0.7.1) mime-types (1.17.2) - mocha (0.10.4) + mocha (0.10.5) metaclass (~> 0.0.1) - multi_json (1.0.4) + multi_json (1.1.0) net-http-digest_auth (1.2) - net-http-persistent (2.5.1) - nokogiri (1.5.0) + net-http-persistent (2.5.2) + nokogiri (1.5.2) ntlm-http (0.1.1) - pg (0.13.0) + pg (0.13.2) polyamorous (0.5.0) activerecord (~> 3.0) polyglot (0.3.3) - pry (0.9.8.2) + pry (0.9.8.4) coderay (~> 1.0.5) - method_source (~> 0.7) + method_source (~> 0.7.1) slop (>= 2.4.4, < 3) rack (1.4.1) - rack-cache (1.1) + rack-cache (1.2) rack (>= 0.4) rack-ssl (1.3.2) rack rack-test (0.6.1) rack (>= 1.0) - rails (3.2.1) - actionmailer (= 3.2.1) - actionpack (= 3.2.1) - activerecord (= 3.2.1) - activeresource (= 3.2.1) - activesupport (= 3.2.1) + rails (3.2.2) + actionmailer (= 3.2.2) + actionpack (= 3.2.2) + activerecord (= 3.2.2) + activeresource (= 3.2.2) + activesupport (= 3.2.2) bundler (~> 1.0) - railties (= 3.2.1) - railties (3.2.1) - actionpack (= 3.2.1) - activesupport (= 3.2.1) + railties (= 3.2.2) + railties (3.2.2) + actionpack (= 3.2.2) + activesupport (= 3.2.2) rack-ssl (~> 1.3.2) rake (>= 0.8.7) rdoc (~> 3.4) @@ -140,13 +140,17 @@ GEM railties (~> 3.2.0) sass (>= 3.1.10) tilt (~> 1.3) - shoulda (2.11.3) + shoulda (3.0.1) + shoulda-context (~> 1.0.0) + shoulda-matchers (~> 1.0.0) + shoulda-context (1.0.0) + shoulda-matchers (1.0.0) silent-postgres (0.1.1) - simple_form (1.5.2) + simple_form (2.0.1) actionpack (~> 3.0) activemodel (~> 3.0) - simplecov (0.5.4) - multi_json (~> 1.0.3) + simplecov (0.6.1) + multi_json (~> 1.0) simplecov-html (~> 0.5.3) simplecov-html (0.5.3) slop (2.4.4) @@ -157,22 +161,22 @@ GEM super_exception_notifier (3.0.13) actionmailer rake - therubyracer (0.9.9) + therubyracer (0.9.10) libv8 (~> 3.3.10) thor (0.14.6) tilt (1.3.3) treetop (1.4.10) polyglot polyglot (>= 0.3.1) - tzinfo (0.3.31) + tzinfo (0.3.32) uglifier (1.2.3) execjs (>= 0.3.0) multi_json (>= 1.0.2) - unf (0.0.4) + unf (0.0.5) unf_ext unf_ext (0.0.4) webrobots (0.0.13) - whenever (0.7.2) + whenever (0.7.3) activesupport (>= 2.3.4) chronic (~> 0.6.3) @@ -193,7 +197,7 @@ DEPENDENCIES nokogiri pg pry - rails (= 3.2.1) + rails (= 3.2.2) rmagick sanitize! sass-rails (~> 3.2.3) diff --git a/app/controllers/forum_posts_controller.rb b/app/controllers/forum_posts_controller.rb index 252dd14cc..974be319c 100644 --- a/app/controllers/forum_posts_controller.rb +++ b/app/controllers/forum_posts_controller.rb @@ -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 diff --git a/app/controllers/forum_topics_controller.rb b/app/controllers/forum_topics_controller.rb index 37984062a..d15da0dcf 100644 --- a/app/controllers/forum_topics_controller.rb +++ b/app/controllers/forum_topics_controller.rb @@ -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 diff --git a/app/controllers/pools_controller.rb b/app/controllers/pools_controller.rb index 082789548..b1dc92fbe 100644 --- a/app/controllers/pools_controller.rb +++ b/app/controllers/pools_controller.rb @@ -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 diff --git a/app/models/forum_post.rb b/app/models/forum_post.rb index 29587efe6..467f1f08c 100644 --- a/app/models/forum_post.rb +++ b/app/models/forum_post.rb @@ -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" diff --git a/app/models/forum_topic.rb b/app/models/forum_topic.rb index 1a6d48ef9..fd1e14707 100644 --- a/app/models/forum_topic.rb +++ b/app/models/forum_topic.rb @@ -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 diff --git a/app/models/pool.rb b/app/models/pool.rb index 5f27fac94..548f10b49 100644 --- a/app/models/pool.rb +++ b/app/models/pool.rb @@ -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 diff --git a/app/models/post.rb b/app/models/post.rb index daf97f93a..c5b672d7e 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -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 diff --git a/app/views/forum_posts/_forum_post.html.erb b/app/views/forum_posts/_forum_post.html.erb index 265330786..e328d34e4 100644 --- a/app/views/forum_posts/_forum_post.html.erb +++ b/app/views/forum_posts/_forum_post.html.erb @@ -1,6 +1,11 @@
-

<%= link_to forum_post.creator.name, user_path(forum_post.creator_id) %>

+

+ <%= link_to forum_post.creator.name, user_path(forum_post.creator_id) %> + <% if forum_post.is_deleted? %> + (deleted) + <% end %> +

<%= time_ago_in_words(forum_post.created_at) %> ago

@@ -12,7 +17,11 @@
  • <%= link_to "Quote", new_forum_post_path(:post_id => forum_post.id) %>
  • <% if CurrentUser.user.is_janitor? || CurrentUser.user.id == forum_post.creator_id %> -
  • <%= link_to "Delete", forum_post_path(forum_post.id), :confirm => "Do you really want to delete this post?", :method => :delete, :remote => true %>
  • + <% if forum_post.is_deleted %> +
  • <%= link_to "Undelete", undelete_forum_post_path(forum_post.id), :method => :post, :remote => true %>
  • + <% else %> +
  • <%= link_to "Delete", forum_post_path(forum_post.id), :confirm => "Do you really want to delete this post?", :method => :delete, :remote => true %>
  • + <% end %>
  • <%= link_to "Edit", edit_forum_post_path(forum_post.id) %>
  • <% end %>
    diff --git a/app/views/forum_posts/undelete.js.erb b/app/views/forum_posts/undelete.js.erb new file mode 100644 index 000000000..345366b9b --- /dev/null +++ b/app/views/forum_posts/undelete.js.erb @@ -0,0 +1 @@ +location.reload(); diff --git a/app/views/forum_topics/show.html.erb b/app/views/forum_topics/show.html.erb index dfe455e9d..c7ccff099 100644 --- a/app/views/forum_topics/show.html.erb +++ b/app/views/forum_topics/show.html.erb @@ -1,6 +1,11 @@
    -

    Topic: <%= @forum_topic.title %>

    +

    + Topic: <%= @forum_topic.title %> + <% if @forum_topic.is_deleted? %> + (deleted) + <% end %> +

    <% if @forum_topic.is_locked? %>
    diff --git a/app/views/pools/edit.html.erb b/app/views/pools/edit.html.erb index 52160f76a..f4bc1b012 100644 --- a/app/views/pools/edit.html.erb +++ b/app/views/pools/edit.html.erb @@ -5,6 +5,7 @@ <%= f.input :name %> <%= f.input :description %> <%= f.input :post_ids, :label => "Posts" %> + <%= f.input :is_active %> <%= f.button :submit %> <% end %>
    diff --git a/config/routes.rb b/config/routes.rb index df2f22199..a2b367905 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -75,11 +75,18 @@ Danbooru::Application.routes.draw do resource :dtext_preview, :only => [:create] resources :favorites resources :forum_posts do + member do + post :undelete + end collection do get :search end end - resources :forum_topics + resources :forum_topics do + member do + post :undelete + end + end resources :ip_bans resources :janitor_trials do collection do diff --git a/db/migrate/20100221003655_create_forum_topics.rb b/db/migrate/20100221003655_create_forum_topics.rb index 4c727dfc8..73219279b 100644 --- a/db/migrate/20100221003655_create_forum_topics.rb +++ b/db/migrate/20100221003655_create_forum_topics.rb @@ -7,6 +7,7 @@ class CreateForumTopics < ActiveRecord::Migration t.column :response_count, :integer, :null => false, :default => 0 t.column :is_sticky, :boolean, :null => false, :default => false t.column :is_locked, :boolean, :null => false, :default => false + t.column :is_deleted, :boolean, :null => false, :default => false t.column :text_index, "tsvector", :null => false t.timestamps end diff --git a/db/migrate/20100221005812_create_forum_posts.rb b/db/migrate/20100221005812_create_forum_posts.rb index b2bd2b0af..a204d20a6 100644 --- a/db/migrate/20100221005812_create_forum_posts.rb +++ b/db/migrate/20100221005812_create_forum_posts.rb @@ -6,6 +6,7 @@ class CreateForumPosts < ActiveRecord::Migration t.column :updater_id, :integer, :null => false t.column :body, :text, :null => false t.column :text_index, "tsvector", :null => false + t.column :is_deleted, :boolean, :null => false, :default => false t.timestamps end diff --git a/script/upgrade_schema.sql b/script/upgrade_schema.sql index 2cb5ba303..ba65401d4 100755 --- a/script/upgrade_schema.sql +++ b/script/upgrade_schema.sql @@ -2883,7 +2883,8 @@ CREATE TABLE forum_topics ( text_index tsvector NOT NULL, created_at timestamp without time zone, updated_at timestamp without time zone, - original_post_id integer not null + original_post_id integer not null, + is_deleted boolean DEFAULT false NOT NULL ); CREATE SEQUENCE forum_topics_id_seq START WITH 1 @@ -2904,7 +2905,7 @@ CREATE TRIGGER trigger_forum_topics_on_update FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger('text_index', 'pg_catalog.english', 'title'); update forum_posts set creator_id = 1 where creator_id is null; -insert into forum_topics (creator_id, updater_id, title, response_count, is_sticky, is_locked, text_index, created_at, updated_at, original_post_id) select forum_posts.creator_id, forum_posts.creator_id, forum_posts.title, forum_posts.response_count, forum_posts.is_sticky, forum_posts.is_locked, forum_posts.text_search_index, forum_posts.created_at, forum_posts.updated_at, forum_posts.id from forum_posts where parent_id is null; +insert into forum_topics (creator_id, updater_id, title, response_count, is_sticky, is_locked, text_index, created_at, updated_at, original_post_id, is_deleted) select forum_posts.creator_id, forum_posts.creator_id, forum_posts.title, forum_posts.response_count, forum_posts.is_sticky, forum_posts.is_locked, forum_posts.text_search_index, forum_posts.created_at, forum_posts.updated_at, forum_posts.id, forum_posts.is_deleted from forum_posts where parent_id is null; alter table forum_posts drop constraint forum_posts_creator_id_fkey; alter table forum_posts drop constraint forum_posts_last_updated_by_fkey;