mirror of
https://github.com/discourse/discourse.git
synced 2026-08-09 04:28:29 -05:00
FIX: Validate duration minutes values for topic timer (#12040)
Add server and client side validations to ensure topic timer durations cannot exceed 2 years and cannot be less than or equal to 0.
This commit is contained in:
@@ -475,19 +475,23 @@ class TopicsController < ApplicationController
|
||||
options.merge!(duration_minutes: params[:duration_minutes].to_i) if params[:duration_minutes].present?
|
||||
options.merge!(duration: params[:duration].to_i) if params[:duration].present?
|
||||
|
||||
topic_status_update = topic.set_or_create_timer(
|
||||
status_type,
|
||||
params[:time],
|
||||
**options
|
||||
)
|
||||
begin
|
||||
topic_timer = topic.set_or_create_timer(
|
||||
status_type,
|
||||
params[:time],
|
||||
**options
|
||||
)
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
return render_json_error(e.message)
|
||||
end
|
||||
|
||||
if topic.save
|
||||
render json: success_json.merge!(
|
||||
execute_at: topic_status_update&.execute_at,
|
||||
duration_minutes: topic_status_update&.duration_minutes,
|
||||
based_on_last_post: topic_status_update&.based_on_last_post,
|
||||
execute_at: topic_timer&.execute_at,
|
||||
duration_minutes: topic_timer&.duration_minutes,
|
||||
based_on_last_post: topic_timer&.based_on_last_post,
|
||||
closed: topic.closed,
|
||||
category_id: topic_status_update&.category_id
|
||||
category_id: topic_timer&.category_id
|
||||
)
|
||||
else
|
||||
render_json_error(topic)
|
||||
|
||||
Reference in New Issue
Block a user