2017-03-22 11:12:02 +08:00
|
|
|
module Jobs
|
|
|
|
class ToggleTopicClosed < Jobs::Base
|
|
|
|
def execute(args)
|
|
|
|
topic_status_update = TopicStatusUpdate.find_by(id: args[:topic_status_update_id])
|
2017-04-04 14:29:47 +08:00
|
|
|
state = !!args[:state]
|
2017-03-22 11:12:02 +08:00
|
|
|
|
2017-04-04 14:29:47 +08:00
|
|
|
if topic_status_update.blank? ||
|
|
|
|
topic_status_update.execute_at > Time.zone.now ||
|
|
|
|
(topic = topic_status_update.topic).blank? ||
|
|
|
|
topic.closed == state
|
2017-03-22 11:12:02 +08:00
|
|
|
|
2017-04-04 14:29:47 +08:00
|
|
|
return
|
|
|
|
end
|
2017-03-22 11:12:02 +08:00
|
|
|
|
|
|
|
user = topic_status_update.user
|
|
|
|
|
|
|
|
if Guardian.new(user).can_close?(topic)
|
|
|
|
topic.update_status('autoclosed', state, user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|