Fix #4359: Allow builders to move small (artist) tags manually.
Allow builders to approve artist alias BURs. The BUR must contain only artist aliases or mass updates and each artist must have less than 100 posts.
This commit is contained in:
@@ -117,6 +117,22 @@ class BulkUpdateRequestProcessor
|
||||
[]
|
||||
end
|
||||
|
||||
def is_tag_move_allowed?
|
||||
tokens.all? do |type, *args|
|
||||
case type
|
||||
when :create_alias
|
||||
BulkUpdateRequestProcessor.is_tag_move_allowed?(args[0], args[1])
|
||||
when :mass_update
|
||||
lhs = PostQueryBuilder.new(args[0])
|
||||
rhs = PostQueryBuilder.new(args[1])
|
||||
|
||||
lhs.is_simple_tag? && rhs.is_simple_tag? && BulkUpdateRequestProcessor.is_tag_move_allowed?(args[0], args[1])
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def to_dtext
|
||||
tokens.map do |token|
|
||||
case token[0]
|
||||
@@ -132,5 +148,15 @@ class BulkUpdateRequestProcessor
|
||||
end.join("\n")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.is_tag_move_allowed?(antecedent_name, consequent_name)
|
||||
antecedent_tag = Tag.find_by_name(Tag.normalize_name(antecedent_name))
|
||||
consequent_tag = Tag.find_by_name(Tag.normalize_name(consequent_name))
|
||||
|
||||
(antecedent_tag.blank? || antecedent_tag.empty? || (antecedent_tag.artist? && antecedent_tag.post_count <= 100)) &&
|
||||
(consequent_tag.blank? || consequent_tag.empty? || (consequent_tag.artist? && consequent_tag.post_count <= 100))
|
||||
end
|
||||
|
||||
memoize :tokens
|
||||
end
|
||||
|
||||
@@ -136,6 +136,10 @@ class BulkUpdateRequest < ApplicationRecord
|
||||
@processor ||= BulkUpdateRequestProcessor.new(script, forum_topic_id: forum_topic_id, skip_secondary_validations: skip_secondary_validations)
|
||||
end
|
||||
|
||||
def is_tag_move_allowed?
|
||||
processor.is_tag_move_allowed?
|
||||
end
|
||||
|
||||
def is_pending?
|
||||
status == "pending"
|
||||
end
|
||||
|
||||
@@ -8,7 +8,7 @@ class BulkUpdateRequestPolicy < ApplicationPolicy
|
||||
end
|
||||
|
||||
def approve?
|
||||
user.is_admin? && !record.is_approved?
|
||||
unbanned? && !record.is_approved? && (user.is_admin? || (user.is_builder? && record.is_tag_move_allowed?))
|
||||
end
|
||||
|
||||
def destroy?
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
<%# bur %>
|
||||
|
||||
<% if policy(bur).approve? %>
|
||||
<%= link_to "Approve", approve_bulk_update_request_path(bur), remote: true, method: :post, "data-confirm": "Are you sure you want to approve this bulk update request?" %> |
|
||||
<% end %>
|
||||
<%= link_to_if policy(bur).approve?, "Approve", approve_bulk_update_request_path(bur), remote: true, method: :post, "data-confirm": "Are you sure you want to approve this bulk update request?" %> |
|
||||
<% if policy(bur).destroy? %>
|
||||
<%= link_to "Reject", bur, remote: true, method: :delete, "data-confirm": "Are you sure you want to reject this bulk update request?" %> |
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user