@@ -3,7 +3,7 @@ class CommentsController < ApplicationController
33 before_action :authenticate_user! , except : [ :post , :show , :thread , :thread_content ]
44
55 before_action :set_comment , only : [ :update , :destroy , :undelete , :show ]
6- before_action :set_post , only : [ :create_thread ]
6+ before_action :set_post , only : [ :create_thread , :post_follow , :post_unfollow ]
77 before_action :set_thread ,
88 only : [ :create , :thread , :thread_content , :thread_rename , :thread_restrict , :thread_unrestrict ,
99 :thread_followers ]
@@ -259,29 +259,33 @@ def thread_unrestrict
259259
260260 def post
261261 @post = Post . find ( params [ :post_id ] )
262- @comment_threads = if current_user &.at_least_moderator? || current_user &.post_privilege? ( 'flag_curate' , @post )
263- CommentThread
264- else
265- CommentThread . undeleted
266- end . where ( post : @post ) . order ( deleted : :asc , archived : :asc , reply_count : :desc )
262+ @comment_threads = CommentThread . accessible_to ( current_user , @post )
263+ . where ( post : @post )
264+ . order ( deleted : :asc , archived : :asc , reply_count : :desc )
267265 respond_to do |format |
268266 format . html { render layout : false }
269267 format . json { render json : @comment_threads }
270268 end
271269 end
272270
273271 def post_follow
274- @post = Post . find ( params [ :post_id ] )
275272 if ThreadFollower . where ( post : @post , user : current_user ) . none?
276273 ThreadFollower . create ( post : @post , user : current_user )
277274 end
278- redirect_to post_path ( @post )
275+
276+ respond_to do |format |
277+ format . html { redirect_to post_path ( @post ) }
278+ format . json { render json : { status : 'success' } }
279+ end
279280 end
280281
281282 def post_unfollow
282- @post = Post . find ( params [ :post_id ] )
283283 ThreadFollower . where ( post : @post , user : current_user ) . destroy_all
284- redirect_to post_path ( @post )
284+
285+ respond_to do |format |
286+ format . html { redirect_to post_path ( @post ) }
287+ format . json { render json : { status : 'success' } }
288+ end
285289 end
286290
287291 def pingable
@@ -297,7 +301,7 @@ def comment_params
297301 end
298302
299303 def set_comment
300- @comment = Comment . unscoped . find params [ :id ]
304+ @comment = Comment . unscoped . find ( params [ :id ] )
301305 end
302306
303307 def set_post
0 commit comments