Merge 52a142ac63 into 38fdd842f5
This commit is contained in:
commit
39ef66db3c
@ -187,7 +187,7 @@
|
||||
{{i18n "category.num_auto_bump_daily"}}
|
||||
</label>
|
||||
<NumberField
|
||||
@number={{this.category.custom_fields.num_auto_bump_daily}}
|
||||
@number={{this.category.category_setting.num_auto_bump_daily}}
|
||||
@id="category-number-daily-bump"
|
||||
@type="number"
|
||||
@min="0"
|
||||
|
||||
@ -406,7 +406,7 @@ class CategoriesController < ApplicationController
|
||||
:read_only_banner,
|
||||
:default_list_filter,
|
||||
:reviewable_by_group_id,
|
||||
category_setting_attributes: %i[auto_bump_cooldown_days],
|
||||
category_setting_attributes: %i[auto_bump_cooldown_days num_auto_bump_daily],
|
||||
custom_fields: [custom_field_params],
|
||||
permissions: [*p.try(:keys)],
|
||||
allowed_tags: [],
|
||||
|
||||
@ -18,11 +18,9 @@ class Category < ActiveRecord::Base
|
||||
|
||||
REQUIRE_TOPIC_APPROVAL = "require_topic_approval"
|
||||
REQUIRE_REPLY_APPROVAL = "require_reply_approval"
|
||||
NUM_AUTO_BUMP_DAILY = "num_auto_bump_daily"
|
||||
|
||||
register_custom_field_type(REQUIRE_TOPIC_APPROVAL, :boolean)
|
||||
register_custom_field_type(REQUIRE_REPLY_APPROVAL, :boolean)
|
||||
register_custom_field_type(NUM_AUTO_BUMP_DAILY, :integer)
|
||||
|
||||
belongs_to :topic
|
||||
belongs_to :topic_only_relative_url,
|
||||
@ -48,7 +46,11 @@ class Category < ActiveRecord::Base
|
||||
|
||||
has_one :category_setting, dependent: :destroy
|
||||
|
||||
delegate :auto_bump_cooldown_days, to: :category_setting, allow_nil: true
|
||||
delegate :auto_bump_cooldown_days,
|
||||
:num_auto_bump_daily,
|
||||
:num_auto_bump_daily=,
|
||||
to: :category_setting,
|
||||
allow_nil: true
|
||||
|
||||
has_and_belongs_to_many :web_hooks
|
||||
|
||||
@ -632,14 +634,6 @@ class Category < ActiveRecord::Base
|
||||
custom_fields[REQUIRE_REPLY_APPROVAL]
|
||||
end
|
||||
|
||||
def num_auto_bump_daily
|
||||
custom_fields[NUM_AUTO_BUMP_DAILY]
|
||||
end
|
||||
|
||||
def num_auto_bump_daily=(v)
|
||||
custom_fields[NUM_AUTO_BUMP_DAILY] = v
|
||||
end
|
||||
|
||||
def auto_bump_limiter
|
||||
return nil if num_auto_bump_daily.to_i == 0
|
||||
RateLimiter.new(nil, "auto_bump_limit_#{self.id}", 1, 86_400 / num_auto_bump_daily.to_i)
|
||||
@ -650,22 +644,11 @@ class Category < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def self.auto_bump_topic!
|
||||
bumped = false
|
||||
|
||||
auto_bumps =
|
||||
CategoryCustomField
|
||||
.where(name: Category::NUM_AUTO_BUMP_DAILY)
|
||||
.where('NULLIF(value, \'\')::int > 0')
|
||||
.pluck(:category_id)
|
||||
|
||||
if (auto_bumps.length > 0)
|
||||
auto_bumps.shuffle.each do |category_id|
|
||||
bumped = Category.find_by(id: category_id)&.auto_bump_topic!
|
||||
break if bumped
|
||||
end
|
||||
end
|
||||
|
||||
bumped
|
||||
Category
|
||||
.joins(:category_setting)
|
||||
.where("category_settings.num_auto_bump_daily > 0")
|
||||
.shuffle
|
||||
.any?(&:auto_bump_topic!)
|
||||
end
|
||||
|
||||
# will automatically bump a single topic
|
||||
|
||||
@ -26,7 +26,7 @@ end
|
||||
# category_id :bigint not null
|
||||
# require_topic_approval :boolean
|
||||
# require_reply_approval :boolean
|
||||
# num_auto_bump_daily :integer
|
||||
# num_auto_bump_daily :integer default(0)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# auto_bump_cooldown_days :integer default(1)
|
||||
|
||||
@ -0,0 +1,23 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ChangeCategorySettingNumAutoBumpDailyDefault < ActiveRecord::Migration[7.0]
|
||||
def up
|
||||
change_column_default :category_settings, :num_auto_bump_daily, 0
|
||||
|
||||
execute(<<~SQL)
|
||||
UPDATE category_settings
|
||||
SET num_auto_bump_daily = 0
|
||||
WHERE num_auto_bump_daily IS NULL;
|
||||
SQL
|
||||
end
|
||||
|
||||
def down
|
||||
change_column_default :category_settings, :num_auto_bump_daily, nil
|
||||
|
||||
execute(<<~SQL)
|
||||
UPDATE category_settings
|
||||
SET num_auto_bump_daily = NULL
|
||||
WHERE num_auto_bump_daily = 0;
|
||||
SQL
|
||||
end
|
||||
end
|
||||
@ -974,10 +974,10 @@ RSpec.describe Category do
|
||||
category =
|
||||
Fabricate(
|
||||
:category_with_definition,
|
||||
num_auto_bump_daily: 2,
|
||||
created_at: 1.minute.ago,
|
||||
category_setting_attributes: {
|
||||
auto_bump_cooldown_days: 1,
|
||||
num_auto_bump_daily: 2,
|
||||
},
|
||||
)
|
||||
category.clear_auto_bump_cache!
|
||||
|
||||
@ -750,7 +750,6 @@ RSpec.describe CategoriesController do
|
||||
it "updates per-category settings correctly" do
|
||||
category.custom_fields[Category::REQUIRE_TOPIC_APPROVAL] = false
|
||||
category.custom_fields[Category::REQUIRE_REPLY_APPROVAL] = false
|
||||
category.custom_fields[Category::NUM_AUTO_BUMP_DAILY] = 0
|
||||
|
||||
category.navigate_to_first_post_after_read = false
|
||||
category.save!
|
||||
@ -764,6 +763,8 @@ RSpec.describe CategoriesController do
|
||||
custom_fields: {
|
||||
require_reply_approval: true,
|
||||
require_topic_approval: true,
|
||||
},
|
||||
category_setting_attributes: {
|
||||
num_auto_bump_daily: 10,
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user