Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ def check_blocked

def check_pseud_ownership
return unless params[:comment][:pseud_id]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added some whitespace only rubocop auto corrects

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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be nice to have a unified way to see when a user wanted to to view full work vs chaptered view. But all the different helper methods and endpoints had slightly different ways we would need to use to identify them.

commentable = commentable.work if options[:view_full_work] || user_chose_to_view_full_work
end
redirect_to polymorphic_path(commentable,
options.slice(:show_comments,
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/works_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 1 addition & 2 deletions features/comments_and_kudos/comments_redirect.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading