got rid of removedpost, restore classic is_deleted mechanics
This commit is contained in:
@@ -33,6 +33,16 @@ class PostModerationController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def delete
|
||||
@post = Post.find(params[:post_id])
|
||||
@post.delete!
|
||||
end
|
||||
|
||||
def undelete
|
||||
@post = Post.find(params[:post_id])
|
||||
@post.undelete!
|
||||
end
|
||||
|
||||
private
|
||||
def disapproval_error(e)
|
||||
respond_to do |format|
|
||||
|
||||
@@ -5,6 +5,14 @@ class Cache
|
||||
ActiveRecord::Base.logger.debug('MemCache Incr %s' % [key])
|
||||
end
|
||||
|
||||
def self.decr(key, expiry = 0)
|
||||
val = Cache.get(key, expiry)
|
||||
if val.to_i > 0
|
||||
Cache.put(key, val.to_i - 1)
|
||||
end
|
||||
ActiveRecord::Base.logger.debug('MemCache Decr %s' % [key])
|
||||
end
|
||||
|
||||
def self.get_multi(keys, prefix, expiry = 0)
|
||||
key_to_sanitized_key_hash = keys.inject({}) do |hash, x|
|
||||
hash[x] = "#{prefix}:#{Cache.sanitize(x)}"
|
||||
|
||||
@@ -27,6 +27,7 @@ class Post < ActiveRecord::Base
|
||||
validate :validate_parent_does_not_have_a_parent
|
||||
attr_accessible :source, :rating, :tag_string, :old_tag_string, :last_noted_at
|
||||
scope :pending, where(["is_pending = ?", true])
|
||||
scope :undeleted, where(["is_deleted = ?", false])
|
||||
scope :visible, lambda {|user| Danbooru.config.can_user_see_post_conditions(user)}
|
||||
scope :commented_before, lambda {|date| where("last_commented_at < ?", date).order("last_commented_at DESC")}
|
||||
scope :available_for_moderation, lambda {where(["id NOT IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id])}
|
||||
@@ -237,6 +238,10 @@ class Post < ActiveRecord::Base
|
||||
end
|
||||
|
||||
module PresenterMethods
|
||||
def presenter
|
||||
@presenter ||= PostPresenter.new(self)
|
||||
end
|
||||
|
||||
def pretty_rating
|
||||
case rating
|
||||
when "q"
|
||||
@@ -480,11 +485,7 @@ class Post < ActiveRecord::Base
|
||||
q = Tag.parse_query(q)
|
||||
end
|
||||
|
||||
if q[:status] == "deleted"
|
||||
relation = RemovedPost.scoped
|
||||
else
|
||||
relation = Post.scoped
|
||||
end
|
||||
relation = Post.scoped
|
||||
|
||||
relation = add_range_relation(q[:post_id], "posts.id", relation)
|
||||
relation = add_range_relation(q[:mpixels], "posts.width * posts.height / 1000000.0", relation)
|
||||
@@ -507,6 +508,8 @@ class Post < ActiveRecord::Base
|
||||
relation = relation.where("posts.is_pending = TRUE")
|
||||
elsif q[:status] == "flagged"
|
||||
relation = relation.where("posts.is_flagged = TRUE")
|
||||
elsif q[:status] == "deleted"
|
||||
relation = relation.where("posts.is_deleted = TRUE")
|
||||
end
|
||||
|
||||
if q[:source].is_a?(String)
|
||||
@@ -641,13 +644,31 @@ class Post < ActiveRecord::Base
|
||||
end
|
||||
|
||||
module CountMethods
|
||||
def get_count_from_cache(tags)
|
||||
Cache.get(count_cache_key(tags))
|
||||
end
|
||||
|
||||
def set_count_in_cache(tags, count)
|
||||
if count < 100
|
||||
expiry = 0
|
||||
else
|
||||
expiry = (count * 4).minutes
|
||||
end
|
||||
|
||||
Cache.put(count_cache_key(tags), count, expiry)
|
||||
end
|
||||
|
||||
def count_cache_key(tags)
|
||||
"pfc:#{Cache.sanitize(tags)}"
|
||||
end
|
||||
|
||||
def fast_count(tags = "")
|
||||
tags = tags.to_s
|
||||
count = Cache.get("pfc:#{Cache.sanitize(tags)}")
|
||||
count = get_count_from_cache(tags)
|
||||
if count.nil?
|
||||
count = Post.tag_match("#{tags}").count
|
||||
count = Post.tag_match(tags).undeleted.count
|
||||
if count > Danbooru.config.posts_per_page * 10
|
||||
Cache.put("pfc:#{Cache.sanitize(tags)}", count, (count * 4).minutes)
|
||||
set_count_in_cache(tags, count)
|
||||
end
|
||||
end
|
||||
count
|
||||
@@ -657,9 +678,9 @@ class Post < ActiveRecord::Base
|
||||
module CacheMethods
|
||||
def expire_cache(tag_name)
|
||||
if Post.fast_count("") < 1000
|
||||
Cache.delete("pfc:")
|
||||
Cache.delete(Post.count_cache_key(""))
|
||||
end
|
||||
Cache.delete("pfc:#{Cache.sanitize(tag_name)}")
|
||||
Cache.delete(Post.count_cache_key(tag_name))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -679,14 +700,14 @@ class Post < ActiveRecord::Base
|
||||
|
||||
module ClassMethods
|
||||
def update_has_children_flag_for(post_id)
|
||||
has_children = Post.exists?(["parent_id = ?", post_id])
|
||||
has_children = Post.exists?(["is_deleted = ? AND parent_id = ?", false, post_id])
|
||||
execute_sql("UPDATE posts SET has_children = ? WHERE id = ?", has_children, post_id)
|
||||
end
|
||||
|
||||
def recalculate_has_children_for_all_posts
|
||||
transaction do
|
||||
execute_sql("UPDATE posts SET has_children = false WHERE has_children = true")
|
||||
execute_sql("UPDATE posts SET has_children = true WHERE id IN (SELECT p.parent_id FROM posts p WHERE p.parent_id IS NOT NULL)")
|
||||
execute_sql("UPDATE posts SET has_children = true WHERE id IN (SELECT p.parent_id FROM posts p WHERE p.parent_id IS NOT NULL AND is_deleted = FALSE)")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -746,22 +767,23 @@ class Post < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
module RemovalMethods
|
||||
def remove!
|
||||
module DeletionMethods
|
||||
def delete!
|
||||
Post.transaction do
|
||||
execute_sql("INSERT INTO removed_posts (#{Post.column_names.join(', ')}) SELECT #{Post.column_names.join(', ')} FROM posts WHERE posts.id = #{id}")
|
||||
give_favorites_to_parent
|
||||
update_children_on_destroy
|
||||
delete_favorites
|
||||
decrement_tag_post_counts
|
||||
execute_sql("DELETE FROM posts WHERE id = #{id}")
|
||||
update_attribute(:is_deleted, true)
|
||||
update_parent_on_destroy
|
||||
tag_array.each {|x| expire_cache(x)}
|
||||
end
|
||||
end
|
||||
|
||||
def is_removed?
|
||||
false
|
||||
def undelete!
|
||||
update_attribute(:is_deleted, false)
|
||||
tag_array.each {|x| expire_cache(x)}
|
||||
update_parent_on_save
|
||||
end
|
||||
end
|
||||
|
||||
@@ -826,17 +848,13 @@ class Post < ActiveRecord::Base
|
||||
extend CountMethods
|
||||
include CacheMethods
|
||||
include ParentMethods
|
||||
include RemovalMethods
|
||||
include DeletionMethods
|
||||
include VersionMethods
|
||||
|
||||
def reload(options = nil)
|
||||
super
|
||||
reset_tag_array_cache
|
||||
end
|
||||
|
||||
def presenter
|
||||
@presenter ||= PostPresenter.new(self)
|
||||
end
|
||||
end
|
||||
|
||||
Post.connection.extend(PostgresExtensions)
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
class RemovedPost < ActiveRecord::Base
|
||||
has_one :unapproval, :dependent => :destroy, :foreign_key => "post_id"
|
||||
|
||||
module RemovalMethods
|
||||
def unremove!
|
||||
Post.transaction do
|
||||
execute_sql("INSERT INTO posts (#{Post.column_names.join(', ')}) SELECT #{Post.column_names.join(', ')} FROM removed_posts WHERE id = #{id}")
|
||||
execute_sql("DELETE FROM removed_posts WHERE id = #{id}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def fast_count(tags)
|
||||
count = Cache.get("rpfc:#{Cache.sanitize(tags)}")
|
||||
if count.nil?
|
||||
count = RemovedPost.tag_match("#{tags}").count
|
||||
if count > Danbooru.config.posts_per_page * 10
|
||||
Cache.put("rpfc:#{Cache.sanitize(tags)}", count, (count * 4).minutes)
|
||||
end
|
||||
end
|
||||
count
|
||||
end
|
||||
|
||||
def is_removed?
|
||||
true
|
||||
end
|
||||
|
||||
include Post::FileMethods
|
||||
include Post::ImageMethods
|
||||
include Post::TagMethods
|
||||
include Post::SearchMethods
|
||||
include Post::UploaderMethods
|
||||
include Post::PoolMethods
|
||||
include Post::CountMethods
|
||||
include Post::CacheMethods
|
||||
include RemovalMethods
|
||||
end
|
||||
|
||||
@@ -9,7 +9,7 @@ class Unapproval < ActiveRecord::Base
|
||||
before_save :flag_post
|
||||
|
||||
def validate_post_is_active
|
||||
if post.is_pending? || post.is_flagged? || post.is_removed?
|
||||
if post.is_pending? || post.is_flagged? || post.is_deleted?
|
||||
errors[:post] << "is inactive"
|
||||
false
|
||||
else
|
||||
|
||||
@@ -3,7 +3,7 @@ class PostPresenter < Presenter
|
||||
flags = []
|
||||
flags << "pending" if post.is_pending?
|
||||
flags << "flagged" if post.is_flagged?
|
||||
flags << "removed" if post.is_removed?
|
||||
flags << "deleted" if post.is_deleted?
|
||||
|
||||
html = %{<article id="post_#{post.id}" data-id="#{post.id}" data-tags="#{h(post.tag_string)}" data-uploader="#{h(post.uploader_name)}" data-rating="#{post.rating}" data-width="#{post.image_width}" data-height="#{post.image_height}" data-flags="#{flags.join(' ')}">}
|
||||
html << %{<a href="/posts/#{post.id}">}
|
||||
@@ -22,7 +22,7 @@ class PostPresenter < Presenter
|
||||
end
|
||||
|
||||
def image_html(template)
|
||||
return template.content_tag("p", "This image was deleted.") if @post.is_removed? && !CurrentUser.user.is_janitor?
|
||||
return template.content_tag("p", "This image was deleted.") if @post.is_deleted? && !CurrentUser.user.is_janitor?
|
||||
return template.content_tag("p", "You need a privileged account to see this image.") if !Danbooru.config.can_see_post?(@post, CurrentUser.user)
|
||||
|
||||
if @post.is_flash?
|
||||
|
||||
3
app/views/post_moderation/delete.js.erb
Normal file
3
app/views/post_moderation/delete.js.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
$("a#delete").hide();
|
||||
$("a#undelete").show();
|
||||
$("img#delete-wait").hide();
|
||||
3
app/views/post_moderation/undelete.js.erb
Normal file
3
app/views/post_moderation/undelete.js.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
$("a#delete").show();
|
||||
$("a#undelete").hide();
|
||||
$("img#undelete-wait").hide();
|
||||
@@ -9,11 +9,8 @@
|
||||
<li><%= link_to "Disapprove", "#", :id => "disapprove" %> <%= wait_image("disapprove-wait") %></li>
|
||||
<% end %>
|
||||
<% if CurrentUser.is_moderator? %>
|
||||
<% if post.is_removed? %>
|
||||
<li><%= link_to "Undelete", "#" %></li>
|
||||
<% else %>
|
||||
<li><%= link_to "Delete", "#" %></li>
|
||||
<% end %>
|
||||
<li><%= link_to "Undelete", "#", :id => "undelete" %> <%= wait_image("undelete-wait") %></li>
|
||||
<li><%= link_to "Delete", "#", :id => "delete" %> <%= wait_image("delete-wait") %></li>
|
||||
<% end %>
|
||||
<li><%= link_to "Pool", "#" %></li>
|
||||
</ul>
|
||||
@@ -69,6 +69,7 @@
|
||||
<meta name="post-id" content="<%= @post.id %>">
|
||||
<meta name="post-is-unapprovable" content="<%= @post.is_unapprovable? %>">
|
||||
<meta name="post-is-approvable" content="<%= @post.is_approvable? %>">
|
||||
<meta name="post-is-deleted" content="<%= @post.is_deleted? %>">
|
||||
<% end %>
|
||||
|
||||
<%= render :partial => "posts/partials/common/secondary_links" %>
|
||||
|
||||
Reference in New Issue
Block a user