mirror of
https://github.com/discourse/discourse.git
synced 2024-11-28 05:23:43 +08:00
b58867b6e9
Includes support for flags, reviewable users and queued posts, with REST API backwards compatibility. Co-Authored-By: romanrizzi <romanalejandro@gmail.com> Co-Authored-By: jjaffeux <j.jaffeux@gmail.com>
33 lines
886 B
Ruby
33 lines
886 B
Ruby
module Jobs
|
|
class ToggleTopicClosed < Jobs::Base
|
|
def execute(args)
|
|
topic_timer = TopicTimer.find_by(id: args[:topic_timer_id] || args[:topic_status_update_id])
|
|
state = !!args[:state]
|
|
|
|
if topic_timer.blank? ||
|
|
topic_timer.execute_at > Time.zone.now ||
|
|
(topic = topic_timer.topic).blank? ||
|
|
topic.closed == state
|
|
|
|
return
|
|
end
|
|
|
|
user = topic_timer.user
|
|
|
|
if Guardian.new(user).can_close?(topic)
|
|
if state == false && 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
|
|
topic.update_status('autoclosed', state, user)
|
|
end
|
|
|
|
topic.inherit_auto_close_from_category if state == false
|
|
end
|
|
end
|
|
end
|
|
end
|