FEATURE: auto-close topics based on last post

This commit is contained in:
Régis Hanol
2014-10-10 18:21:44 +02:00
parent ac72b0bcf6
commit 5754e8dd0f
28 changed files with 242 additions and 146 deletions

View File

@@ -178,12 +178,20 @@ class TopicsController < ApplicationController
end
def autoclose
raise Discourse::InvalidParameters.new(:auto_close_time) unless params.has_key?(:auto_close_time)
params.permit(:auto_close_time)
params.require(:auto_close_based_on_last_post)
topic = Topic.find_by(id: params[:topic_id].to_i)
guardian.ensure_can_moderate!(topic)
topic.auto_close_based_on_last_post = params[:auto_close_based_on_last_post]
topic.set_auto_close(params[:auto_close_time], current_user)
if topic.save
render json: success_json.merge!(auto_close_at: topic.auto_close_at)
render json: success_json.merge!({
auto_close_at: topic.auto_close_at,
auto_close_hours: topic.auto_close_hours
})
else
render_json_error(topic)
end