@@ -10,6 +10,7 @@ class CommentsController < ApplicationController
1010
1111 before_action :check_post_access , only : [ :create_thread , :create ]
1212 before_action :check_privilege , only : [ :update , :destroy , :undelete ]
13+ before_action :check_create_access , only : [ :create_thread , :create ]
1314 before_action :check_reply_access , only : [ :create ]
1415 before_action :check_restrict_access , only : [ :thread_restrict ]
1516 before_action :check_thread_access , only : [ :thread , :thread_content , :thread_followers ]
@@ -34,13 +35,6 @@ def create_thread
3435
3536 pings = check_for_pings @comment_thread , body
3637
37- rate_limited , limit_message = helpers . comment_rate_limited? ( current_user , @post )
38- if rate_limited
39- flash [ :danger ] = limit_message
40- redirect_to helpers . generic_share_link ( @post )
41- return
42- end
43-
4438 success = ActiveRecord ::Base . transaction do
4539 @comment_thread . save!
4640 @comment . save!
@@ -74,13 +68,6 @@ def create
7468 @comment = Comment . new ( post : @post , content : body , user : current_user ,
7569 comment_thread : @comment_thread , has_reference : false )
7670
77- rate_limited , limit_message = helpers . comment_rate_limited? ( current_user , @post )
78- if rate_limited
79- flash [ :danger ] = limit_message
80- redirect_to helpers . generic_share_link ( @post )
81- return
82- end
83-
8471 status = @comment . save
8572
8673 if status
@@ -338,6 +325,14 @@ def check_privilege
338325 end
339326 end
340327
328+ def check_create_access
329+ rate_limited , limit_message = helpers . comment_rate_limited? ( current_user , @post )
330+ if rate_limited
331+ flash [ :danger ] = limit_message
332+ redirect_to helpers . generic_share_link ( @post )
333+ end
334+ end
335+
341336 def check_reply_access
342337 if @comment_thread . read_only? && current_user &.standard?
343338 respond_to do |format |
0 commit comments