BURs: reduce autorejection timeout from 60 days to 45 days.
This commit is contained in:
@@ -1,12 +1,18 @@
|
|||||||
# Rejects bulk update requests that haven't been approved in 60 days.
|
# Rejects bulk update requests that haven't been approved in 45 days.
|
||||||
module BulkUpdateRequestPruner
|
module BulkUpdateRequestPruner
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
|
# How many days before a bulk update request should be automatically rejected.
|
||||||
|
EXPIRATION_PERIOD = 45.days
|
||||||
|
|
||||||
|
# How many days before we should warn about upcoming rejections.
|
||||||
|
WARNING_PERIOD = 5.days
|
||||||
|
|
||||||
# Posts a warning when a bulk update request is pending automatic rejection in 5 days.
|
# Posts a warning when a bulk update request is pending automatic rejection in 5 days.
|
||||||
def warn_old
|
def warn_old
|
||||||
BulkUpdateRequest.old.pending.find_each do |bulk_update_request|
|
upcoming_expired_requests.find_each do |bulk_update_request|
|
||||||
if bulk_update_request.forum_topic
|
if bulk_update_request.forum_topic
|
||||||
body = "This bulk update request is pending automatic rejection in 5 days."
|
body = "This bulk update request is pending automatic rejection in #{WARNING_PERIOD.inspect}."
|
||||||
unless bulk_update_request.forum_topic.forum_posts.where(creator_id: User.system.id, body: body).exists?
|
unless bulk_update_request.forum_topic.forum_posts.where(creator_id: User.system.id, body: body).exists?
|
||||||
bulk_update_request.forum_updater.update(body)
|
bulk_update_request.forum_updater.update(body)
|
||||||
end
|
end
|
||||||
@@ -14,12 +20,12 @@ module BulkUpdateRequestPruner
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Rejects bulk update requests that haven't been approved in 60 days.
|
# Rejects bulk update requests that haven't been approved in 45 days.
|
||||||
def reject_expired
|
def reject_expired
|
||||||
BulkUpdateRequest.expired.pending.find_each do |bulk_update_request|
|
expired_requests.find_each do |bulk_update_request|
|
||||||
ApplicationRecord.transaction do
|
ApplicationRecord.transaction do
|
||||||
if bulk_update_request.forum_topic
|
if bulk_update_request.forum_topic
|
||||||
body = "This bulk update request has been rejected because it was not approved within 60 days."
|
body = "This bulk update request has been rejected because it was not approved within #{EXPIRATION_PERIOD.inspect}."
|
||||||
bulk_update_request.forum_updater.update(body)
|
bulk_update_request.forum_updater.update(body)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -27,4 +33,12 @@ module BulkUpdateRequestPruner
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def expired_requests
|
||||||
|
BulkUpdateRequest.pending.where("created_at < ?", EXPIRATION_PERIOD.ago)
|
||||||
|
end
|
||||||
|
|
||||||
|
def upcoming_expired_requests
|
||||||
|
BulkUpdateRequest.pending.where("created_at >= ? and created_at < ?", EXPIRATION_PERIOD.ago, (EXPIRATION_PERIOD - WARNING_PERIOD).ago)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ class BulkUpdateRequest < ApplicationRecord
|
|||||||
scope :approved, -> { where(status: "approved") }
|
scope :approved, -> { where(status: "approved") }
|
||||||
scope :rejected, -> { where(status: "rejected") }
|
scope :rejected, -> { where(status: "rejected") }
|
||||||
scope :has_topic, -> { where.not(forum_topic: nil) }
|
scope :has_topic, -> { where.not(forum_topic: nil) }
|
||||||
scope :expired, -> {where("created_at < ?", TagRelationship::EXPIRY.days.ago)}
|
|
||||||
scope :old, -> {where("created_at between ? and ?", TagRelationship::EXPIRY.days.ago, TagRelationship::EXPIRY_WARNING.days.ago)}
|
|
||||||
|
|
||||||
module SearchMethods
|
module SearchMethods
|
||||||
def default_order
|
def default_order
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
class TagRelationship < ApplicationRecord
|
class TagRelationship < ApplicationRecord
|
||||||
self.abstract_class = true
|
self.abstract_class = true
|
||||||
|
|
||||||
EXPIRY = 60
|
|
||||||
EXPIRY_WARNING = 55
|
|
||||||
|
|
||||||
belongs_to :creator, class_name: "User"
|
belongs_to :creator, class_name: "User"
|
||||||
belongs_to :approver, class_name: "User", optional: true
|
belongs_to :approver, class_name: "User", optional: true
|
||||||
belongs_to :forum_post, optional: true
|
belongs_to :forum_post, optional: true
|
||||||
@@ -15,8 +12,6 @@ class TagRelationship < ApplicationRecord
|
|||||||
|
|
||||||
scope :active, -> {where(status: "active")}
|
scope :active, -> {where(status: "active")}
|
||||||
scope :deleted, -> {where(status: "deleted")}
|
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)}
|
|
||||||
scope :retired, -> {where(status: "retired")}
|
scope :retired, -> {where(status: "retired")}
|
||||||
|
|
||||||
before_validation :normalize_names
|
before_validation :normalize_names
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ class BulkUpdateRequestPrunerTest < ActiveSupport::TestCase
|
|||||||
context '#warn_old' do
|
context '#warn_old' do
|
||||||
should "update the forum topic for a bulk update request" do
|
should "update the forum topic for a bulk update request" do
|
||||||
forum_topic = as(create(:user)) { create(:forum_topic) }
|
forum_topic = as(create(:user)) { create(:forum_topic) }
|
||||||
bur = create(:bulk_update_request, status: "pending", forum_topic: forum_topic, created_at: (TagRelationship::EXPIRY_WARNING + 1).days.ago)
|
bur = create(:bulk_update_request, status: "pending", forum_topic: forum_topic, created_at: (BulkUpdateRequestPruner::EXPIRATION_PERIOD - 1.day).ago)
|
||||||
|
|
||||||
BulkUpdateRequestPruner.warn_old
|
BulkUpdateRequestPruner.warn_old
|
||||||
assert_equal("pending", bur.reload.status)
|
assert_equal("pending", bur.reload.status)
|
||||||
@@ -15,11 +15,11 @@ class BulkUpdateRequestPrunerTest < ActiveSupport::TestCase
|
|||||||
context '#reject_expired' do
|
context '#reject_expired' do
|
||||||
should "reject the bulk update request" do
|
should "reject the bulk update request" do
|
||||||
forum_topic = as(create(:user)) { create(:forum_topic) }
|
forum_topic = as(create(:user)) { create(:forum_topic) }
|
||||||
bur = create(:bulk_update_request, status: "pending", forum_topic: forum_topic, created_at: (TagRelationship::EXPIRY + 1).days.ago)
|
bur = create(:bulk_update_request, status: "pending", forum_topic: forum_topic, created_at: (BulkUpdateRequestPruner::EXPIRATION_PERIOD + 1.day).ago)
|
||||||
|
|
||||||
BulkUpdateRequestPruner.reject_expired
|
BulkUpdateRequestPruner.reject_expired
|
||||||
assert_equal("rejected", bur.reload.status)
|
assert_equal("rejected", bur.reload.status)
|
||||||
assert_match(/rejected because it was not approved within 60 days/, ForumPost.second.body)
|
assert_match(/rejected because it was not approved within \d+ days/, ForumPost.second.body)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user