keep track of post approvals to prevent approval cycles
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
12
app/models/post_approval.rb
Normal file
12
app/models/post_approval.rb
Normal 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
|
||||
@@ -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 %>">
|
||||
|
||||
Reference in New Issue
Block a user