aliases/implications: remove processing state.
Remove the `processing` state from aliases and implications. This state was used to mark when an alias or implication had been approved but the alias or implication was still being processed. Aliases in the processing state were still considered active, so there was no functional difference between the active state and the processing state. This fixes a problem where it was possible for implications to get stuck in the processing state. This happened when a BUR contained a duplicate implication. Transitioning from the processing state to the active state failed in this case because we used `update` instead of `update!`, which meant validation errors were silently ignored.
This commit is contained in:
@@ -15,9 +15,8 @@ class TagAlias < TagRelationship
|
||||
end
|
||||
|
||||
def process!(approver)
|
||||
update!(approver: approver, status: "processing")
|
||||
update!(approver: approver, status: "active")
|
||||
TagMover.new(antecedent_name, consequent_name, user: User.system).move!
|
||||
update!(status: "active")
|
||||
rescue Exception => e
|
||||
update!(status: "error: #{e}")
|
||||
DanbooruLogger.log(e, tag_alias_id: id, antecedent_name: antecedent_name, consequent_name: consequent_name)
|
||||
|
||||
@@ -126,9 +126,8 @@ class TagImplication < TagRelationship
|
||||
end
|
||||
|
||||
CurrentUser.scoped(User.system) do
|
||||
update(approver: approver, status: "processing")
|
||||
update!(approver: approver, status: "active")
|
||||
update_posts
|
||||
update(status: "active")
|
||||
end
|
||||
rescue Exception => e
|
||||
update(status: "error: #{e}")
|
||||
|
||||
@@ -15,8 +15,7 @@ class TagRelationship < ApplicationRecord
|
||||
belongs_to :antecedent_wiki, class_name: "WikiPage", foreign_key: "antecedent_name", primary_key: "title", optional: true
|
||||
belongs_to :consequent_wiki, class_name: "WikiPage", foreign_key: "consequent_name", primary_key: "title", optional: true
|
||||
|
||||
scope :active, -> {approved}
|
||||
scope :approved, -> {where(status: %w[active processing])}
|
||||
scope :active, -> {where(status: "active")}
|
||||
scope :deleted, -> {where(status: "deleted")}
|
||||
scope :expired, -> {where("created_at < ?", EXPIRY.days.ago)}
|
||||
scope :old, -> {where("created_at >= ? and created_at < ?", EXPIRY.days.ago, EXPIRY_WARNING.days.ago)}
|
||||
@@ -24,7 +23,7 @@ class TagRelationship < ApplicationRecord
|
||||
scope :retired, -> {where(status: "retired")}
|
||||
|
||||
before_validation :normalize_names
|
||||
validates_format_of :status, :with => /\A(active|deleted|pending|processing|retired|error: .*)\Z/
|
||||
validates_format_of :status, :with => /\A(active|deleted|pending|retired|error: .*)\Z/
|
||||
validates_presence_of :antecedent_name, :consequent_name
|
||||
validates :approver, presence: { message: "must exist" }, if: -> { approver_id.present? }
|
||||
validates :forum_topic, presence: { message: "must exist" }, if: -> { forum_topic_id.present? }
|
||||
@@ -35,10 +34,6 @@ class TagRelationship < ApplicationRecord
|
||||
self.consequent_name = consequent_name.mb_chars.downcase.tr(" ", "_")
|
||||
end
|
||||
|
||||
def is_approved?
|
||||
status.in?(%w[active processing])
|
||||
end
|
||||
|
||||
def is_rejected?
|
||||
status.in?(%w[retired deleted])
|
||||
end
|
||||
@@ -73,13 +68,7 @@ class TagRelationship < ApplicationRecord
|
||||
end
|
||||
|
||||
def status_matches(status)
|
||||
status = status.downcase
|
||||
|
||||
if status == "approved"
|
||||
where(status: %w[active processing])
|
||||
else
|
||||
where(status: status)
|
||||
end
|
||||
where(status: status.downcase)
|
||||
end
|
||||
|
||||
def tag_matches(field, params)
|
||||
@@ -89,7 +78,7 @@ class TagRelationship < ApplicationRecord
|
||||
|
||||
def pending_first
|
||||
# unknown statuses return null and are sorted first
|
||||
order(Arel.sql("array_position(array['processing', 'pending', 'active', 'deleted', 'retired'], status::text) NULLS FIRST, id DESC"))
|
||||
order(Arel.sql("array_position(array['pending', 'active', 'deleted', 'retired'], status::text) NULLS FIRST, id DESC"))
|
||||
end
|
||||
|
||||
def search(params)
|
||||
|
||||
Reference in New Issue
Block a user