2017-03-21 22:12:02 -05: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 01:29:47 -05:00
|
|
|
state = !!args[:state]
|
2017-03-21 22:12:02 -05:00
|
|
|
|
2017-04-04 01:29:47 -05: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-21 22:12:02 -05:00
|
|
|
|
2017-04-04 01:29:47 -05:00
|
|
|
return
|
|
|
|
end
|
2017-03-21 22:12:02 -05:00
|
|
|
|
|
|
|
user = topic_status_update.user
|
|
|
|
|
|
|
|
if Guardian.new(user).can_close?(topic)
|
|
|
|
topic.update_status('autoclosed', state, user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|