0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-06 05:42:36 +08:00
discourse/app/jobs/regular/open_topic.rb
Mark VanLandingham 1171b86bb7
FEATURE: Allow topic_timers_allowed_groups to manage topic timers (#41126)
Previously managing topic timers was staff + TL4 only. This moves the
logic to a group site setting so that other groups can set timers.
2026-06-23 12:46:56 -05:00

41 lines
1.2 KiB
Ruby
Vendored

# frozen_string_literal: true
module Jobs
class OpenTopic < ::Jobs::TopicTimerBase
def execute_timer_action(topic_timer, topic)
user = topic_timer.user
if !Guardian.new(user).can_set_topic_timer?(topic) || topic.open?
topic_timer.destroy!
topic.reload
topic.inherit_auto_close_from_category(timer_type: :close)
return
end
# guards against reopening a topic too early if the topic has
# been auto closed because of reviewables/reports, this will
# just update the existing topic timer and push it down the line
if topic.auto_close_threshold_reached?
topic.set_or_create_timer(
TopicTimer.types[:open],
SiteSetting.num_hours_to_close_topic,
by_user: Discourse.system_user,
)
else
# autoclosed, false is just another way of saying open.
# this handles deleting the topic timer as well, see TopicStatusUpdater
topic.update_status("autoclosed", false, user)
end
topic.inherit_auto_close_from_category(timer_type: :close)
MessageBus.publish(
"/topic/#{topic.id}",
{ reload_topic: true },
topic.secure_audience_publish_messages,
)
end
end
end