-
Notifications
You must be signed in to change notification settings - Fork 788
AO3-7219 Keep users with 'show the whole work by default' enabled in chapter by chapter mode when commenting #5524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Comment on lines
+700
to
+702
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently, this can leak a "view_full_work" param that is set to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That suggestion summarizes to the following decision tree to me:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current decision tree here is this is mostly the same as my suggested decision tree, the only difference is the view_full_work param possibly being set when redirecting to a chapter. But the current code took me ages to parse. Not sure if that is a me issue or not, so I'm leaving this analysis here and you can decide how you integrate my suggestion and whether you change how the checks here are done or not
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed on not setting view_full_work unless it's true. I can edit. I also had trouble following what we were doing with view_full_work, and honestly, I'm a bit concerned that this could have been the intended behavior because the comments_redirect test was specifically checking that users reverted back to full works view.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That's a fair concern! I went digging into the history of that test, and it looks like AO3-4487 added those comments and solidified this behaviour and doesn't have any context on whether there was a discussion on whether it was wanted, it's a simple "fix test to match existing behaviour" issue. The initial PR that added this behaviour is #327 and the relevant Jira issues are AO3-1514, AO3-1515. Neither of those explicitly defines the behaviour here, so I think we aren't undoing a specific past decision. Besides, when this Jira issue was discussed before getting created, it was a very short "Yup, definitely a bug." discussion so even if we considered this intended approximately 10 years ago, we no longer do now. |
||
| end | ||
| redirect_to polymorphic_path(commentable, | ||
| options.slice(:show_comments, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. First thing I noticed here is that it should be However, from what I can tell, that second check doesn't need to do anything to fix the issue here: If we're in chapter by chapter mode and want to stay there, then the comments controller redirects to the chapter directly. So we should never end up in this controller with So I would remove the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for the careful review. It's been a while, but I think not having that second check was causing some unexpected behaviors. I'm trying to get set back up so I can test. |
||
| @chapters = @work.chapters_in_order( | ||
| include_drafts: (logged_in_as_admin? || | ||
| @work.user_is_owner_or_invited?(current_user)) | ||
|
|
||
There was a problem hiding this comment.
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