diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index e89d919d90..98cefa1d01 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -55,8 +55,10 @@ def check_blocked def check_pseud_ownership return unless params[:comment][:pseud_id] + pseud = Pseud.find(params[:comment][:pseud_id]) return if pseud && current_user && current_user.pseuds.include?(pseud) + flash[:error] = ts("You can't comment with that pseud.") redirect_to root_path end @@ -180,14 +182,17 @@ def check_not_replying_to_spam def check_permission_to_review parent = find_parent return if logged_in_as_admin? || current_user_owns?(parent) + flash[:error] = ts("Sorry, you don't have permission to see those unreviewed comments.") redirect_to logged_in? ? root_path : new_user_session_path(return_to: request.fullpath) end def check_permission_to_access_single_unreviewed return unless @comment.unreviewed? + parent = find_parent return if logged_in_as_admin? || current_user_owns?(parent) || current_user_owns?(@comment) + flash[:error] = ts("Sorry, that comment is currently in moderation.") redirect_to logged_in? ? root_path : new_user_session_path(return_to: request.fullpath) end @@ -384,7 +389,10 @@ def create elsif @comment.unreviewed? redirect_to_all_comments(@commentable) else - redirect_to_comment(@comment, { view_full_work: (params[:view_full_work] == "true"), page: params[:page] }) + # keep the user in chapter by chapter view if that was the view they were in when they commented + # An entire work view url would look like works/:id + user_chose_to_view_full_work = (current_user.try(:preference).try(:view_full_works) && request.referer&.match(/chapters/).nil?) + redirect_to_comment(@comment, { view_full_work: (params[:view_full_work] == "true" || user_chose_to_view_full_work), page: params[:page] }) end end end @@ -689,8 +697,9 @@ def redirect_to_all_comments(commentable, options = {}) page: options[:page], anchor: options[:anchor]) else - if commentable.is_a?(Chapter) && (options[:view_full_work] || current_user.try(:preference).try(:view_full_works)) - commentable = commentable.work + if commentable.is_a?(Chapter) + user_chose_to_view_full_work = current_user.try(:preference).try(:view_full_works) && options[:view_full_work] != false + commentable = commentable.work if options[:view_full_work] || user_chose_to_view_full_work end redirect_to polymorphic_path(commentable, options.slice(:show_comments, diff --git a/app/controllers/works_controller.rb b/app/controllers/works_controller.rb index b42c7470c4..82d17b1ffb 100755 --- a/app/controllers/works_controller.rb +++ b/app/controllers/works_controller.rb @@ -191,7 +191,7 @@ def show # Users must explicitly okay viewing of entire work if @work.chaptered? - if params[:view_full_work] || (logged_in? && current_user.preference.try(:view_full_works)) + if params[:view_full_work] == "true" || (logged_in? && current_user.preference.try(:view_full_works) && params[:view_full_works] != "false") @chapters = @work.chapters_in_order( include_drafts: (logged_in_as_admin? || @work.user_is_owner_or_invited?(current_user)) diff --git a/features/comments_and_kudos/comments_redirect.feature b/features/comments_and_kudos/comments_redirect.feature index ec20253a7f..6b3b392996 100644 --- a/features/comments_and_kudos/comments_redirect.feature +++ b/features/comments_and_kudos/comments_redirect.feature @@ -49,8 +49,7 @@ Scenario: Posting top level comment on a chaptered work, with view full work in And I post a comment "Woohoo" Then I should see "Woohoo" And I should see "Chapter 2" within "div#chapters" - # Once you've commented, it defaults back to your preference - And I should see "Chapter 1" within "div#chapters" + And I should not see "Chapter 1" within "div#chapters" # REPLY COMMENTS