@@ -56,11 +56,13 @@ def create_thread
5656 def create
5757 @comment_thread = CommentThread . find ( params [ :id ] )
5858 @post = @comment_thread . post
59- if @post . comments_disabled && !current_user . is_moderator && !current_user . is_admin
60- render json : { status : 'failed' , message : 'Comments have been disabled on this post.' } , status : :forbidden
61- return
62- elsif !@post . can_access? ( current_user )
63- return not_found
59+ unless @post . nil?
60+ if @post . comments_disabled && !current_user . is_moderator && !current_user . is_admin
61+ render json : { status : 'failed' , message : 'Comments have been disabled on this post.' } , status : :forbidden
62+ return
63+ elsif !@post . can_access? ( current_user )
64+ return not_found
65+ end
6466 end
6567
6668 body = params [ :content ]
@@ -82,10 +84,12 @@ def create
8284 . where ( 'link LIKE ?' , "#{ thread_url } %" )
8385 next if existing_notification . exists?
8486
85- title = @post . parent . nil? ? @post . title : @post . parent . title
86- follower . user . create_notification ( "There are new comments in a followed thread '#{ @comment_thread . title } ' " \
87- "on the post '#{ title } '" ,
88- helpers . comment_link ( @comment ) )
87+ unless @post . nil?
88+ title = @post . parent . nil? ? @post . title : @post . parent . title
89+ follower . user . create_notification ( "There are new comments in a followed thread '#{ @comment_thread . title } ' " \
90+ "on the post '#{ title } '" ,
91+ helpers . comment_link ( @comment ) )
92+ end
8993 end
9094 else
9195 flash [ :danger ] = @comment . errors . full_messages . join ( ', ' )
@@ -94,6 +98,12 @@ def create
9498 end
9599
96100 def update
101+ if @comment_thread . is_private
102+ flash [ :danger ] = 'This action is not permitted.'
103+ redirect_to comment_thread_path ( @comment_thread . id )
104+ return
105+ end
106+
97107 before = @comment . content
98108 if @comment . update comment_params
99109 unless current_user . id == @comment . user_id
@@ -110,6 +120,12 @@ def update
110120 end
111121
112122 def destroy
123+ if @comment_thread . is_private
124+ flash [ :danger ] = 'This action is not permitted.'
125+ redirect_to comment_thread_path ( @comment_thread . id )
126+ return
127+ end
128+
113129 if @comment . update ( deleted : true )
114130 @comment_thread = @comment . comment_thread
115131 unless current_user . id == @comment . user_id
@@ -123,6 +139,12 @@ def destroy
123139 end
124140
125141 def undelete
142+ if @comment_thread . is_private
143+ flash [ :danger ] = 'This action is not permitted.'
144+ redirect_to comment_thread_path ( @comment_thread . id )
145+ return
146+ end
147+
126148 if @comment . update ( deleted : false )
127149 @comment_thread = @comment . comment_thread
128150 unless current_user . id == @comment . user_id
@@ -169,11 +191,23 @@ def thread_rename
169191 return
170192 end
171193
194+ if @comment_thread . is_private && !current_user . is_moderator
195+ flash [ :danger ] = 'This action is not permitted.'
196+ redirect_to comment_thread_path ( @comment_thread . id )
197+ return
198+ end
199+
172200 @comment_thread . update title : params [ :title ]
173201 redirect_to comment_thread_path ( @comment_thread . id )
174202 end
175203
176204 def thread_restrict
205+ if @comment_thread . is_private && !current_user . is_moderator
206+ flash [ :danger ] = 'This action is not permitted.'
207+ redirect_to comment_thread_path ( @comment_thread . id )
208+ return
209+ end
210+
177211 case params [ :type ]
178212 when 'lock'
179213 return not_found unless current_user . privilege? ( 'flag_curate' ) && !@comment_thread . locked?
@@ -204,6 +238,12 @@ def thread_restrict
204238 end
205239
206240 def thread_unrestrict
241+ if @comment_thread . is_private && !current_user . is_moderator
242+ flash [ :danger ] = 'This action is not permitted.'
243+ redirect_to comment_thread_path ( @comment_thread . id )
244+ return
245+ end
246+
207247 case params [ :type ]
208248 when 'lock'
209249 return not_found unless current_user . privilege? ( 'flag_curate' ) && @comment_thread . locked?
@@ -278,7 +318,7 @@ def check_if_parent_post_locked
278318 end
279319
280320 def check_if_target_post_locked
281- check_if_locked ( Post . find ( params [ :post_id ] ) )
321+ params [ :post_id ] . present? && check_if_locked ( Post . find ( params [ :post_id ] ) )
282322 end
283323
284324 def check_for_pings ( thread , content )
@@ -302,12 +342,14 @@ def apply_pings(pings)
302342 end
303343
304344 def comment_rate_limited
345+ return false if @comment_thread &.is_private
346+
305347 recent_comments = Comment . where ( created_at : 24 . hours . ago ..DateTime . now , user : current_user ) . where \
306348 . not ( post : Post . includes ( :parent ) . where ( parents_posts : { user_id : current_user . id } ) ) \
307349 . where . not ( post : Post . where ( user_id : current_user . id ) ) . count
308350 max_comments_per_day = SiteSetting [ current_user . privilege? ( 'unrestricted' ) ? 'RL_Comments' : 'RL_NewUserComments' ]
309351
310- if ( !@post . user_id == current_user . id || @post &.parent &.user_id == current_user . id ) \
352+ if ( !@post & .user_id == current_user . id || @post &.parent &.user_id == current_user . id ) \
311353 && recent_comments >= max_comments_per_day
312354 comment_limit_msg = "You have used your daily comment limit of #{ recent_comments } comments." \
313355 ' Come back tomorrow to continue commenting. Comments on own posts and on answers' \
0 commit comments