mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 10:02:33 +08:00
486bbe9cc2
https://meta.discourse.org/t/topic-closed-temporarily-due-to-community-flags-overwrites-category-auto-close-timer/77421
24 lines
614 B
Ruby
24 lines
614 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)
|
|
topic.update_status('autoclosed', state, user)
|
|
topic.inherit_auto_close_from_category if state == false
|
|
end
|
|
end
|
|
end
|
|
end
|