@@ -5,15 +5,23 @@ class CommentsController < ApplicationController
55
66 before_action :set_comment , only : [ :update , :destroy , :undelete , :show ]
77 before_action :set_post , only : [ :create_thread , :post_follow , :post_unfollow ]
8- before_action :set_thread ,
9- only : [ :create , :thread , :thread_content , :thread_rename , :thread_restrict , :thread_unrestrict ,
10- :thread_followers ]
11-
8+ before_action :set_thread , only : [ :create ,
9+ :thread ,
10+ :thread_content ,
11+ :thread_rename ,
12+ :archive_thread ,
13+ :delete_thread ,
14+ :follow_thread ,
15+ :lock_thread ,
16+ :thread_unrestrict ,
17+ :thread_followers ]
1218 before_action :check_post_access , only : [ :create_thread , :create ]
1319 before_action :check_privilege , only : [ :update , :destroy , :undelete ]
1420 before_action :check_create_access , only : [ :create_thread , :create ]
1521 before_action :check_reply_access , only : [ :create ]
16- before_action :check_restrict_access , only : [ :thread_restrict ]
22+ before_action :check_archive_thread_access , only : [ :archive_thread ]
23+ before_action :check_delete_thread_access , only : [ :delete_thread ]
24+ before_action :check_lock_thread_access , only : [ :lock_thread ]
1725 before_action :check_thread_access , only : [ :thread , :thread_content , :thread_followers ]
1826 before_action :check_unrestrict_access , only : [ :thread_unrestrict ]
1927 before_action :check_if_target_post_locked , only : [ :create , :post_follow ]
@@ -268,22 +276,6 @@ def unlock_thread
268276 restrict_thread_response ( @comment_thread , status )
269277 end
270278
271- def thread_restrict
272- # TODO: remove this wrapper action entirely (callbacks need to be moved, routes assigned, etc)
273- case params [ :type ]
274- when 'lock'
275- lock_thread
276- when 'archive'
277- archive_thread
278- when 'delete'
279- delete_thread
280- when 'follow'
281- follow_thread
282- else
283- not_found!
284- end
285- end
286-
287279 def thread_unrestrict
288280 # TODO: remove this wrapper action entirely (callbacks need to be moved, routes assigned, etc)
289281 case params [ :type ]
@@ -402,18 +394,20 @@ def check_reply_access
402394 end
403395 end
404396
405- def check_restrict_access
406- case params [ :type ]
407- when 'lock'
408- not_found! unless current_user . can_lock? ( @comment_thread )
409- when 'archive'
410- not_found! unless current_user . can_archive? ( @comment_thread )
411- when 'delete'
412- not_found! unless current_user . can_delete? ( @comment_thread )
413- end
397+ def check_archive_thread_access
398+ not_found! unless current_user . can_archive? ( @comment_thread )
399+ end
400+
401+ def check_delete_thread_access
402+ not_found! unless current_user . can_delete? ( @comment_thread )
403+ end
404+
405+ def check_lock_thread_access
406+ not_found! unless current_user . can_lock? ( @comment_thread )
414407 end
415408
416409 def check_unrestrict_access
410+ # TODO: split into individual checks once unrestrict_thread is split
417411 case params [ :type ]
418412 when 'lock'
419413 not_found! unless current_user . can_unlock? ( @comment_thread )
0 commit comments