diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index bb9bbd01d..dee66995c 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -29,8 +29,10 @@ class PostsController < ApplicationController @post = Post.find(params[:id]) @post_flag = PostFlag.new(:post_id => @post.id) @post_appeal = PostAppeal.new(:post_id => @post.id) - @parent_post_set = PostSets::PostRelationship.new(@post.parent_id, :include_deleted => @post.is_deleted? || (@post.parent_id.present? && @post.parent.is_deleted?)) - @children_post_set = PostSets::PostRelationship.new(@post.id, :include_deleted => @post.is_deleted?) + + include_deleted = @post.is_deleted? || (@post.parent_id.present? && @post.parent.is_deleted?) || CurrentUser.user.show_deleted_children? + @parent_post_set = PostSets::PostRelationship.new(@post.parent_id, :include_deleted => include_deleted) + @children_post_set = PostSets::PostRelationship.new(@post.id, :include_deleted => include_deleted) respond_with(@post) end diff --git a/app/logical/anonymous_user.rb b/app/logical/anonymous_user.rb index 08df5cefb..2b424f2f5 100644 --- a/app/logical/anonymous_user.rb +++ b/app/logical/anonymous_user.rb @@ -205,6 +205,10 @@ class AnonymousUser nil end + def show_deleted_children? + false + end + %w(member banned gold builder platinum contributor janitor moderator admin).each do |name| define_method("is_#{name}?") do false diff --git a/app/logical/user_deletion.rb b/app/logical/user_deletion.rb index 561484713..bd8cbced4 100644 --- a/app/logical/user_deletion.rb +++ b/app/logical/user_deletion.rb @@ -45,6 +45,7 @@ private user.favorite_tags = '' user.blacklisted_tags = '' user.hide_deleted_posts = false + user.show_deleted_children = false user.time_zone = "Eastern Time (US & Canada)" user.save! end diff --git a/app/models/post.rb b/app/models/post.rb index cb2aba814..4b308d329 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -848,7 +848,8 @@ class Post < ActiveRecord::Base def update_has_children_flag_for(post_id) return if post_id.nil? has_children = Post.where("parent_id = ?", post_id).exists? - execute_sql("UPDATE posts SET has_children = ? WHERE id = ?", has_children, post_id) + has_active_children = Post.where("parent_id = ? and is_deleted = ?", post_id, false).exists? + execute_sql("UPDATE posts SET has_children = ?, has_active_children = ? WHERE id = ?", has_children, has_active_children, post_id) end end @@ -924,6 +925,13 @@ class Post < ActiveRecord::Base def parent_exists? Post.exists?(parent_id) end + + def has_visible_children? + return true if has_active_children? + return true if has_children? && CurrentUser.user.show_deleted_children? + return true if has_children? && is_deleted? + return false + end end module DeletionMethods diff --git a/app/models/user.rb b/app/models/user.rb index 68fbf134e..3563495d9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -17,7 +17,7 @@ class User < ActiveRecord::Base end attr_accessor :password, :old_password - attr_accessible :enable_privacy_mode, :enable_post_navigation, :new_post_navigation_layout, :password, :old_password, :password_confirmation, :password_hash, :email, :last_logged_in_at, :last_forum_read_at, :has_mail, :receive_email_notifications, :comment_threshold, :always_resize_images, :favorite_tags, :blacklisted_tags, :name, :ip_addr, :time_zone, :default_image_size, :enable_sequential_post_navigation, :per_page, :hide_deleted_posts, :style_usernames, :enable_auto_complete, :custom_style, :as => [:moderator, :janitor, :contributor, :gold, :member, :anonymous, :default, :builder, :admin] + attr_accessible :enable_privacy_mode, :enable_post_navigation, :new_post_navigation_layout, :password, :old_password, :password_confirmation, :password_hash, :email, :last_logged_in_at, :last_forum_read_at, :has_mail, :receive_email_notifications, :comment_threshold, :always_resize_images, :favorite_tags, :blacklisted_tags, :name, :ip_addr, :time_zone, :default_image_size, :enable_sequential_post_navigation, :per_page, :hide_deleted_posts, :style_usernames, :enable_auto_complete, :custom_style, :show_deleted_children, :as => [:moderator, :janitor, :contributor, :gold, :member, :anonymous, :default, :builder, :admin] attr_accessible :level, :as => :admin validates_length_of :name, :within => 2..100, :on => :create validates_format_of :name, :with => /\A[^\s:]+\Z/, :on => :create, :message => "cannot have whitespace or colons" @@ -520,7 +520,7 @@ class User < ActiveRecord::Base module ApiMethods def hidden_attributes - super + [:password_hash, :bcrypt_password_hash, :email, :email_verification_key, :time_zone, :updated_at, :receive_email_notifications, :last_logged_in_at, :last_forum_read_at, :has_mail, :default_image_size, :comment_threshold, :always_resize_images, :favorite_tags, :blacklisted_tags, :recent_tags, :enable_privacy_mode, :enable_post_navigation, :new_post_navigation_layout, :enable_sequential_post_navigation, :hide_deleted_posts, :per_page, :style_usernames, :enable_auto_complete, :custom_style] + super + [:password_hash, :bcrypt_password_hash, :email, :email_verification_key, :time_zone, :updated_at, :receive_email_notifications, :last_logged_in_at, :last_forum_read_at, :has_mail, :default_image_size, :comment_threshold, :always_resize_images, :favorite_tags, :blacklisted_tags, :recent_tags, :enable_privacy_mode, :enable_post_navigation, :new_post_navigation_layout, :enable_sequential_post_navigation, :hide_deleted_posts, :per_page, :style_usernames, :enable_auto_complete, :custom_style, :show_deleted_children] end def serializable_hash(options = {}) diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index 473cc86f6..2dc528e25 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -33,7 +33,7 @@ class PostPresenter < Presenter klass << " post-status-flagged" if post.is_flagged? klass << " post-status-deleted" if post.is_deleted? klass << " post-status-has-parent" if post.parent_id - klass << " post-status-has-children" if post.has_children? + klass << " post-status-has-children" if post.has_visible_children? klass end diff --git a/app/views/posts/partials/show/_image.html.erb b/app/views/posts/partials/show/_image.html.erb index 7ad50225e..5eb4bf630 100644 --- a/app/views/posts/partials/show/_image.html.erb +++ b/app/views/posts/partials/show/_image.html.erb @@ -1,3 +1,3 @@ <% if post.visible? %> - <%= image_tag(post.file_url_for(CurrentUser.user), :width => post.image_width_for(CurrentUser.user), :height => post.image_height_for(CurrentUser.user), :id => "image", "data-original-width" => post.image_width, "data-original-height" => post.image_height, "data-large-width" => post.large_image_width, "data-large-height" => post.large_image_height, "data-tags" => post.tag_string, "data-uploader" => post.uploader_name, "data-rating" => post.rating, "data-flags" => post.status_flags, "data-parent-id" => post.parent_id, "data-has-children" => post.has_children?, "data-score" => post.score, "data-fav-count" => post.fav_count) %> + <%= image_tag(post.file_url_for(CurrentUser.user), :width => post.image_width_for(CurrentUser.user), :height => post.image_height_for(CurrentUser.user), :id => "image", "data-original-width" => post.image_width, "data-original-height" => post.image_height, "data-large-width" => post.large_image_width, "data-large-height" => post.large_image_height, "data-tags" => post.tag_string, "data-uploader" => post.uploader_name, "data-rating" => post.rating, "data-flags" => post.status_flags, "data-parent-id" => post.parent_id, "data-has-children" => post.has_children?, "data-has-active-children" => post.has_active_children?, "data-score" => post.score, "data-fav-count" => post.fav_count) %> <% end %> diff --git a/app/views/posts/partials/show/_notices.html.erb b/app/views/posts/partials/show/_notices.html.erb index 82bc2de7c..69e80a7dd 100644 --- a/app/views/posts/partials/show/_notices.html.erb +++ b/app/views/posts/partials/show/_notices.html.erb @@ -52,7 +52,7 @@ <% end %> -<% if post.has_children? %> +<% if post.has_visible_children? %>
<%= has_children_message(post, @children_post_set) %>
<%= @children_post_set.presenter.post_previews_html(self) %>
diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index b4898e953..e57a962b3 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -48,6 +48,7 @@ <%= f.input :enable_sequential_post_navigation, :as => :select, :label => "Enable slideshow mode", :hint => "Show prev/next links when viewing a post", :include_blank => false %> <%= f.input :new_post_navigation_layout, :as => :select, :label => "Navigation bar position", :include_blank => false, :collection => [["Below", "true"], ["Above", "false"]], :hint => "When browsing pools or slideshows, place navigation links above or below the image" %> <%= f.input :hide_deleted_posts, :as => :select, :label => "Deleted post filter", :hint => "Remove deleted posts from search results", :include_blank => false, :collection => [["Yes", "true"], ["No", "false"]] %> + <%= f.input :show_deleted_children, :as => :select, :label => "Show deleted children", :hint => "Indicate that a post has children even if the children are deleted", :include_blank => false, :collection => [["Yes", "true"], ["No", "false"]] %> <%= f.input :enable_auto_complete, :as => :select, :collection => [["Yes", "true"], ["No", "false"]], :include_blank => false %>
diff --git a/db/migrate/20140428015134_add_show_deleted_children_to_users.rb b/db/migrate/20140428015134_add_show_deleted_children_to_users.rb new file mode 100644 index 000000000..506faa7f1 --- /dev/null +++ b/db/migrate/20140428015134_add_show_deleted_children_to_users.rb @@ -0,0 +1,8 @@ +class AddShowDeletedChildrenToUsers < ActiveRecord::Migration + def change + execute "set statement_timeout = 0" + add_column :users, :show_deleted_children, :boolean, :null => false, :default => false + add_column :posts, :has_active_children, :boolean + change_column_default(:posts, :has_active_children, false) + end +end diff --git a/script/fixes/030_calculate_has_active_children.rb b/script/fixes/030_calculate_has_active_children.rb new file mode 100644 index 000000000..af088e244 --- /dev/null +++ b/script/fixes/030_calculate_has_active_children.rb @@ -0,0 +1,13 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment')) + +ActiveRecord::Base.connection.execute("set statement_timeout = 0") + +CurrentUser.user = User.admins.first +CurrentUser.ip_addr = "127.0.0.1" + +execute_sql("UPDATE posts SET has_active_children = true WHERE id IN (SELECT p.parent_id FROM posts p WHERE p.parent_id IS NOT NULL AND p.is_deleted = FALSE)") +execute_sql("UPDATE posts SET has_active_children = false WHERE has_active_children IS NULL") + +execute_sql("ALTER TABLE posts ALTER COLUMN has_active_children SET NOT NULL")