SingleUseLinksViewerController current_ability behavior fixes #6739
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds initially failing tests for current_ability in SingleUseLinksViewerController to demonstrate the issue, and then makes it so the current_ability can be retrieved when a SingleUseLink has already been consumed and adds current_user to it.
There is also a full backtrace logged at ERROR level every time a stale SingleUseLink is accessed that I wouldn't mind reducing to a short warning, which I can add to the PR if the reviewer thinks that's a good idea, but it seems intentional currently.
Guidance for testing, such as acceptance criteria or new user interface behaviors:
To replicate the issue in dassie, on
main
temporarily edit_footer.html.erb
to add<%= current_ability.current_user %>
anywhere in it. Then create a single use link and access it twice. On the second access it will produce the following error page:Then check out this branch and access the link again, and it should give the
Single Use Link Expired or Not Found
page instead. (unrelated to this issue, but the page is displaying html with a link to a help page doesn't exist)Type of change (for release notes)
notes-bugfix
Detailed Description
This issue isn't readily apparent in hyrax itself, but in a local application that modifies parts of the template (in our case the footer) to make use of current_ability, it causes the page to error out and log a FATAL exception in addition to a more expected ERROR from the controller itself.
In both cases, the root of the error is:
ActionView::Template::Error (Couldn't find SingleUseLink)
Which originates from:
https://github.com/samvera/hyrax/blob/main/app/controllers/hyrax/single_use_links_viewer_controller.rb#L87
Which throws an error due to single_use_link not existing anymore. This does not appear to be the expected behavior, since the Ability class below seems to expect to receive unset single_use_links:
https://github.com/samvera/hyrax/blob/main/app/controllers/hyrax/single_use_links_viewer_controller.rb#L108
Changes proposed in this pull request:
@samvera/hyrax-code-reviewers