fixes #2114
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 = {})
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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 %>
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if post.has_children? %>
|
||||
<% if post.has_visible_children? %>
|
||||
<div class="ui-corner-all ui-state-highlight notice notice-parent">
|
||||
<%= has_children_message(post, @children_post_set) %>
|
||||
<div id="has-children-relationship-preview"><%= @children_post_set.presenter.post_previews_html(self) %></div>
|
||||
|
||||
@@ -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 %>
|
||||
<div class="input text optional field_with_hint">
|
||||
<label class="text optional" for="user_favorite_tags">Frequent tags</label>
|
||||
|
||||
@@ -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
|
||||
13
script/fixes/030_calculate_has_active_children.rb
Normal file
13
script/fixes/030_calculate_has_active_children.rb
Normal file
@@ -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")
|
||||
Reference in New Issue
Block a user