BURs: refactor implication wiki page validations.
Move the validation that the tags in an implication must have wiki pages back into the TagImplication model. Use validation contexts to only run the validation when the BUR is created, not when the BUR is approved.
This commit is contained in:
@@ -73,6 +73,7 @@ class BulkUpdateRequest < ApplicationRecord
|
||||
def approve!(approver)
|
||||
transaction do
|
||||
CurrentUser.scoped(approver) do
|
||||
processor.validate!(:approval)
|
||||
processor.process!(approver)
|
||||
update!(status: "approved", approver: approver)
|
||||
forum_updater.update("The #{bulk_update_request_link} (forum ##{forum_post.id}) has been approved by @#{approver.name}.")
|
||||
@@ -107,7 +108,7 @@ class BulkUpdateRequest < ApplicationRecord
|
||||
end
|
||||
|
||||
def validate_script
|
||||
if processor.invalid?
|
||||
if processor.invalid?(:request)
|
||||
errors[:base] << processor.errors.full_messages.join("; ")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,6 +7,7 @@ class TagImplication < TagRelationship
|
||||
validate :absence_of_transitive_relation
|
||||
validate :antecedent_is_not_aliased
|
||||
validate :consequent_is_not_aliased
|
||||
validate :has_wiki_page, on: :request
|
||||
|
||||
concerning :HierarchyMethods do
|
||||
class_methods do
|
||||
@@ -91,6 +92,16 @@ class TagImplication < TagRelationship
|
||||
errors[:base] << "Consequent tag must not be aliased to another tag"
|
||||
end
|
||||
end
|
||||
|
||||
def has_wiki_page
|
||||
if !antecedent_tag.empty? && antecedent_wiki.blank?
|
||||
errors[:base] << "'#{antecedent_name}' must have a wiki page"
|
||||
end
|
||||
|
||||
if !consequent_tag.empty? && consequent_wiki.blank?
|
||||
errors[:base] << "'#{consequent_name}' must have a wiki page"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
concerning :ApprovalMethods do
|
||||
|
||||
Reference in New Issue
Block a user