forked from e621ng/e621ng
[Posts] Prevent deletion with guidelines reason autofilled
This commit is contained in:
parent
690750d020
commit
b50bc1fdd5
@ -10,8 +10,9 @@ module Moderator
|
||||
|
||||
def confirm_delete
|
||||
@post = ::Post.find(params[:id])
|
||||
@reason = @post.flags.where(is_resolved: false)&.last&.reason || ''
|
||||
@reason = "Inferior version/duplicate of post ##{@post.parent_id}" if @post.parent_id && @reason == ''
|
||||
@reason = @post.pending_flag&.reason || ""
|
||||
@reason = "Inferior version/duplicate of post ##{@post.parent_id}" if @post.parent_id && @reason == ""
|
||||
@reason = "" if @reason =~ /uploading_guidelines/
|
||||
end
|
||||
|
||||
def delete
|
||||
|
@ -1246,12 +1246,15 @@ class Post < ApplicationRecord
|
||||
end
|
||||
|
||||
if reason.blank?
|
||||
last_flag = flags.unresolved.order(id: :desc).first
|
||||
if last_flag.blank?
|
||||
self.errors.add(:base, "Cannot flag with blank reason when no active flag exists.")
|
||||
return false
|
||||
if pending_flag.blank?
|
||||
errors.add(:base, "Cannot delete with given reason when no active flag exists.")
|
||||
return
|
||||
end
|
||||
reason = last_flag.reason
|
||||
if pending_flag.reason =~ /uploading_guidelines/
|
||||
errors.add(:base, "Cannot delete with given reason when the flag is for uploading guidelines.")
|
||||
return
|
||||
end
|
||||
reason = pending_flag.reason
|
||||
end
|
||||
|
||||
force_flag = options.fetch(:force, false)
|
||||
@ -1314,6 +1317,10 @@ class Post < ApplicationRecord
|
||||
def deletion_flag
|
||||
flags.order(id: :desc).first
|
||||
end
|
||||
|
||||
def pending_flag
|
||||
flags.unresolved.order(id: :desc).first
|
||||
end
|
||||
end
|
||||
|
||||
module VersionMethods
|
||||
|
@ -6,12 +6,14 @@
|
||||
|
||||
<% if CurrentUser.can_approve_posts? %>
|
||||
<div>
|
||||
<%= link_to "Delete", confirm_delete_moderator_post_post_path(post), class: 'button btn-neutral' %> |
|
||||
<%= tag.a "Unflag", href: '#', 'data-pid': post.id, 'data-type': 'none', class: 'unflag-post-link button btn-neutral' %> |
|
||||
<%= link_to "Delete", confirm_delete_moderator_post_post_path(post), class: 'button btn-neutral' %>
|
||||
| <%= tag.a "Unflag", href: '#', 'data-pid': post.id, 'data-type': 'none', class: 'unflag-post-link button btn-neutral' %>
|
||||
<% if post.is_approvable? %>
|
||||
<%= tag.a "Unflag+approve", href: '#', 'data-pid': post.id, 'data-type': 'approve', class: 'unflag-post-link button btn-neutral' %> |
|
||||
| <%= tag.a "Unflag+approve", href: '#', 'data-pid': post.id, 'data-type': 'approve', class: 'unflag-post-link button btn-neutral' %>
|
||||
<% end %>
|
||||
<% unless post.pending_flag&.reason =~ /uploading_guidelines/ %>
|
||||
| <%= tag.a "Delete with given reason", href: '#', 'data-post-id': post.id, class: 'delete-with-reason-link button btn-neutral', 'data-reason': '', 'data-prompt': 'given reason' %>
|
||||
<% end %>
|
||||
<%= tag.a "Delete with given reason", href: '#', 'data-post-id': post.id, class: 'delete-with-reason-link button btn-neutral', 'data-reason': '', 'data-prompt': 'given reason' %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user