AO3-7388 Redirect to user skin page with error if trying to preview a skin you can't use#5776
AO3-7388 Redirect to user skin page with error if trying to preview a skin you can't use#5776zrei wants to merge 11 commits intootwcode:masterfrom
Conversation
… skin you can't use
…h if skin cannot be previewed
|
I added a |
Bilka2
left a comment
There was a problem hiding this comment.
Thank you for working on this! Two minor things about the code and then some requests for testing additions
| if @skin.is_a?(WorkSkin) || @skin.unusable? | ||
| flash[:error] = t("skins.preview.cannot_preview") | ||
|
|
||
| redirect_to skin_path(@skin) and return |
There was a problem hiding this comment.
I believe this should redirect to the user skin page per the Jira issue (so the user's skins index page), not the page of that specific skin
There was a problem hiding this comment.
Updated! For logged-out users, it redirects to the public site skins page. Will update the PR description.
| it_behaves_like "a non-public skin that cannot be previewed" | ||
| end | ||
| end | ||
| end |
There was a problem hiding this comment.
To cover the (very welcome!) change regarding visibility for the preview action, could you add a variant for an official site skin that is fully accessible and one for a previewable skin by a user with it_behaves_like "an action only the skin author can access"? That way we know that the happy path still works
There was a problem hiding this comment.
The redirect action for the shared example "an action only the skin author can access" is different from the redirect for preview, so I recreated it for the previewable skin by a user.
There was a problem hiding this comment.
Missed that detail, thanks for the better test changes!
| it_behaves_like "a non-public skin that cannot be previewed" | ||
| end | ||
| end | ||
| end |
There was a problem hiding this comment.
Missed that detail, thanks for the better test changes!
| let(:notice) { ["You are previewing the skin #{skin.title}. This is a randomly chosen page.", "Go back or click any link to remove the skin.", "Tip: You can preview any archive page you want by tacking on '?site_skin=[skin_id]' like you can see in the url above.", "<a href='#{skin_path(skin)}' class='action' role='button'>Return To Skin To Use</a>"] } | ||
| let(:success) { it_redirects_to_with_notice(tag_works_path(tag, site_skin: skin.id), notice) } |
There was a problem hiding this comment.
if you wanted to simplify this, you could skip checking the notice with it_redirects_to_simple. It's checked in a cucumber test, so we'd be fine skipping it here
| if @skin.is_a?(WorkSkin) || @skin.unusable? | ||
| flash[:error] = t(".cannot_preview") | ||
|
|
||
| redirect_to skins_path(skin_type: "Site") and return if current_user.nil? |
There was a problem hiding this comment.
Sorry to change the requirements under you, but you bringing up that we can't redirect to a user's page if they're not logged in made me ask whether we even want to allow guests and admins to preview any skins at all. Turns out we don't! I've updated the Jira issue accordingly, so please update the code to make this action users_only
Pull Request Checklist
as the first thing in your pull request title (e.g.
AO3-1234 Fix thing)until they are reviewed and merged before creating new pull requests.
Issue
https://otwarchive.atlassian.net/browse/AO3-7388
Purpose
Redirects to the user skins page when trying to preview a skin that can't be used but can be viewed while logged in as a user. This includes parent-only site skins and work skins. For skins that a logged-in user cannot view (not owned and not public), they are redirected to their dashboard with an error.
Changed preview to a user-only action. Redirects to the login page with an error when trying to preview any skin while logged out. Redirects to the root page with an error when trying to preview any skin while logged in as an admin.
Testing Instructions
For site skins, refer to Jira.
For work skins:
a. Hi, username! > My Dashboard > Skins > Create Work Skin
b. Fill in required information
c. Press “Submit” to save
For not owned, not public skins:
a. Hi, username! > My Dashboard > Skins > Create Site Skin
b. Fill in required information
c. Press “Submit” to save
Credit
zrei (she/they)