BURs: add processing and failed states.
When a BUR is approved, put it in a `processing` state. After it successfully finishes processing, put it in the `approved` state. If it fails processing, put it in the `failed` state. If approving the BUR fails with a validation error, for example because the alias already exists or an implication lacks a wiki, then leave the BUR in the `pending` state. The `failed` state is only for unexpected errors during processing.
This commit is contained in:
@@ -171,6 +171,11 @@ class BulkUpdateRequestProcessor
|
||||
raise Error, "Unknown command: #{command}"
|
||||
end
|
||||
end
|
||||
|
||||
bulk_update_request.update!(status: "approved")
|
||||
rescue StandardError
|
||||
bulk_update_request.update!(status: "failed")
|
||||
raise
|
||||
end
|
||||
|
||||
# The list of tags in the script. Used for search BURs by tag.
|
||||
|
||||
@@ -146,12 +146,19 @@ class DText
|
||||
embedded_script = "[expand]#{obj.processor.to_dtext}[/expand]"
|
||||
end
|
||||
|
||||
if obj.is_approved?
|
||||
case obj.status
|
||||
when "approved"
|
||||
"The \"bulk update request ##{obj.id}\":#{Routes.bulk_update_request_path(obj)} has been approved by <@#{obj.approver.name}>.\n\n#{embedded_script}"
|
||||
elsif obj.is_pending?
|
||||
when "pending"
|
||||
"The \"bulk update request ##{obj.id}\":#{Routes.bulk_update_request_path(obj)} is pending approval.\n\n#{embedded_script}"
|
||||
elsif obj.is_rejected?
|
||||
when "rejected"
|
||||
"The \"bulk update request ##{obj.id}\":#{Routes.bulk_update_request_path(obj)} has been rejected.\n\n#{embedded_script}"
|
||||
when "processing"
|
||||
"The \"bulk update request ##{obj.id}\":#{Routes.bulk_update_request_path(obj)} is being processed.\n\n#{embedded_script}"
|
||||
when "failed"
|
||||
"The \"bulk update request ##{obj.id}\":#{Routes.bulk_update_request_path(obj)} has failed.\n\n#{embedded_script}"
|
||||
else
|
||||
raise ArgumentError, "unknown bulk update request status"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
class BulkUpdateRequest < ApplicationRecord
|
||||
STATUSES = %w[pending approved rejected processing failed]
|
||||
|
||||
attr_accessor :title, :reason
|
||||
|
||||
belongs_to :user
|
||||
@@ -10,16 +12,18 @@ class BulkUpdateRequest < ApplicationRecord
|
||||
validates :script, presence: true
|
||||
validates :title, presence: true, if: ->(rec) { rec.forum_topic_id.blank? }
|
||||
validates :forum_topic, presence: true, if: ->(rec) { rec.forum_topic_id.present? }
|
||||
validates :status, inclusion: { in: %w[pending approved rejected] }
|
||||
validates :status, inclusion: { in: STATUSES }
|
||||
validate :validate_script, if: :script_changed?
|
||||
|
||||
before_save :update_tags, if: :script_changed?
|
||||
after_create :create_forum_topic
|
||||
|
||||
scope :pending_first, -> { order(Arel.sql("(case status when 'pending' then 0 when 'approved' then 1 else 2 end)")) }
|
||||
scope :pending_first, -> { order(Arel.sql("(case status when 'failed' then 0 when 'processing' then 1 when 'pending' then 2 when 'approved' then 3 when 'rejected' then 4 else 5 end)")) }
|
||||
scope :pending, -> {where(status: "pending")}
|
||||
scope :approved, -> { where(status: "approved") }
|
||||
scope :rejected, -> { where(status: "rejected") }
|
||||
scope :processing, -> { where(status: "processing") }
|
||||
scope :failed, -> { where(status: "failed") }
|
||||
scope :has_topic, -> { where.not(forum_topic: nil) }
|
||||
|
||||
module SearchMethods
|
||||
@@ -62,7 +66,7 @@ class BulkUpdateRequest < ApplicationRecord
|
||||
transaction do
|
||||
CurrentUser.scoped(approver) do
|
||||
processor.validate!(:approval)
|
||||
update!(status: "approved", approver: approver)
|
||||
update!(status: "processing", approver: approver)
|
||||
processor.process_later!
|
||||
forum_updater.update("The #{bulk_update_request_link} (forum ##{forum_post.id}) has been approved by @#{approver.name}.")
|
||||
end
|
||||
@@ -116,7 +120,7 @@ class BulkUpdateRequest < ApplicationRecord
|
||||
end
|
||||
|
||||
def is_approved?
|
||||
status == "approved"
|
||||
status.in?(%w[approved processing])
|
||||
end
|
||||
|
||||
def is_rejected?
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
class TagRelationship < ApplicationRecord
|
||||
STATUSES = %w[active deleted retired]
|
||||
|
||||
self.abstract_class = true
|
||||
|
||||
belongs_to :creator, class_name: "User"
|
||||
@@ -15,7 +17,7 @@ class TagRelationship < ApplicationRecord
|
||||
scope :retired, -> {where(status: "retired")}
|
||||
|
||||
before_validation :normalize_names
|
||||
validates :status, inclusion: { in: %w[active deleted retired] }
|
||||
validates :status, inclusion: { in: STATUSES }
|
||||
validates :antecedent_name, presence: true
|
||||
validates :consequent_name, presence: true
|
||||
validates :approver, presence: { message: "must exist" }, if: -> { approver_id.present? }
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<%= f.input :user_name, label: "Creator", input_html: { value: params[:search][:user_name], data: { autocomplete: "user" } } %>
|
||||
<%= f.input :approver_name, label: "Approver", input_html: { value: params[:search][:approver_name], data: { autocomplete: "user" } } %>
|
||||
<%= f.input :tags_include_any, label: "Tags", input_html: { value: params[:search][:tags_include_any], data: { autocomplete: "tag-query" } } %>
|
||||
<%= f.input :status, label: "Status", collection: %w[pending approved rejected], include_blank: true, selected: params[:search][:status] %>
|
||||
<%= f.input :status, label: "Status", collection: %w[pending approved rejected processing failed], include_blank: true, selected: params[:search][:status] %>
|
||||
<%= f.input :order, collection: [%w[Status status_desc], %w[Last\ updated updated_at_desc], %w[Newest id_desc], %w[Oldest id_asc]], include_blank: false, selected: params[:search][:order] %>
|
||||
<%= f.submit "Search" %>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user