keep track of post approvals to prevent approval cycles

This commit is contained in:
Albert Yi
2016-10-31 17:51:44 -07:00
parent 03fd48c989
commit 2dbb869188
7 changed files with 159 additions and 4 deletions

View File

@@ -15,6 +15,7 @@ class DailyMaintenance
TagAlias.update_cached_post_counts_for_all
PostDisapproval.dmail_messages!
Tag.clean_up_negative_post_counts!
PostApproval.prune!
SuperVoter.init!
AntiVoter.init!
end

View File

@@ -274,7 +274,7 @@ class Post < ActiveRecord::Base
module ApprovalMethods
def is_approvable?
!is_status_locked? && (is_pending? || is_flagged? || is_deleted?) && approver_id != CurrentUser.id
!is_status_locked? && (is_pending? || is_flagged? || is_deleted?) && !PostApproval.approved?(CurrentUser.id, id)
end
def flag!(reason, options = {})
@@ -314,7 +314,7 @@ class Post < ActiveRecord::Base
raise ApprovalError.new("You cannot approve a post you uploaded")
end
if approver_id == CurrentUser.id
if approver_id == CurrentUser.id || PostApproval.approved?(CurrentUser.id, id)
errors.add(:approver, "have already approved this post")
raise ApprovalError.new("You have previously approved this post and cannot approve it again")
end
@@ -324,6 +324,9 @@ class Post < ActiveRecord::Base
self.is_pending = false
self.is_deleted = false
self.approver_id = CurrentUser.id
PostApproval.create(user_id: CurrentUser.id, post_id: id)
save!
end
@@ -1362,7 +1365,7 @@ class Post < ActiveRecord::Base
end
if !CurrentUser.is_admin?
if approver_id == CurrentUser.id
if approver_id == CurrentUser.id || PostApproval.approved?(CurrentUser.id, id)
raise ApprovalError.new("You have previously approved this post and cannot undelete it")
elsif uploader_id == CurrentUser.id
raise ApprovalError.new("You cannot undelete a post you uploaded")

View File

@@ -0,0 +1,12 @@
class PostApproval < ActiveRecord::Base
belongs_to :user
belongs_to :post
def self.prune!
where("created_at < ?", 1.month.ago).delete_all
end
def self.approved?(user_id, post_id)
where(user_id: user_id, post_id: post_id).exists?
end
end

View File

@@ -148,7 +148,9 @@
<meta name="favorites" content="<%= @post.fav_string %>">
<meta name="pools" content="<%= @post.pool_string %>">
<meta name="post-id" content="<%= @post.id %>">
<meta name="post-is-approvable" content="<%= @post.is_approvable? %>">
<% if CurrentUser.can_approve_posts? %>
<meta name="post-is-approvable" content="<%= @post.is_approvable? %>">
<% end %>
<meta name="post-is-deleted" content="<%= @post.is_deleted? %>">
<meta name="post-is-flagged" content="<%= @post.is_flagged? %>">
<meta name="config-large-width" content="<%= Danbooru.config.large_image_width %>">