-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Redirects: Fixes self referencing redirects (closes #20139) #20767
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
Conversation
AndyButland
left a comment
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.
This looks good @NillasKA, but I just have a little doubt as to where you've placed the code. The reasons is that RedirecUrlService now has a dependency on IPublishedUrlProvider, and the implementation of that requires an Umbraco context. That's the reason you've had to modify the tests.
But that also means the Register method can no longer be called by something outside of Umbraco - like a background thread - as it'll throw an exception when it can't get a required Umbraco context. And there could be solutions out there that rely on that.
Perhaps you can solve this by moving the logic that removes an existing redirect to RedirectTracker. That already depends on and makes calls to IPublishedUrlProvider, so we aren't regressing anything there. And it would seem we can avoid calling this twice, as we have already looked up the new URL for the content here.
So I'm thinking, in RedirectTracker.CreateRedirects, you could do this:
- Get the new route (line 105).
- Check it's valid (lines 106-109)
- Apply the look up and delete logic you have added here, but instead of calling methods on
IRedirectUrlRepositoryuse the ones onIRedirectUrlService(or introduce ones on this service if you need them). - Register the new redirect (line 111).
I haven't tried this so it needs investigation, but do you think this would work?
|
This sounds good. I think it will work I'll be trying it out today |
|
My latest commit is not my final. I do want to write a few more tests for the |
|
@AndyButland pushed some expanding tests Had to mock quite a bit to get the |
…em if we have a valid route to create a redirect for.
AndyButland
left a comment
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.
Great work @NillasKA, especially on getting this under test. I pushed a few small updates, nothing significant but you can take a look. Have tested manually too and works as expected.
Description
Addresses: #20139
This also happens on 13. This exact code implemented in 13 will also fix it there if cherry picked to V13.
A bug was found, where if you name a document something, that it has previously been named a self referencing redirect is made.
This PR makes a check, that sees if a redirect is being made that references to the current document URL. If there is, we'll remove that redirect since its not needed.
I am at a loss on how to test this, therefore this is a draft for now until i figured it out.
Integration Test obscurity
Trying to create an integration test for this was obscure to me. My problem was, that when X published a document, the URL generated for this newly published document is the one we run through the service, to see if there exists any redirect to this new URL.
My problem with the tests, was to in essence publish a document with an URL to create this redirect, and then publish it back to the old URL to see if this redirect was deleted, i couldn't figure out how. So what i did instead was to mock some data, to ensure a self referencing redirect already exists through mocked data, and to ensure that the Register() method deletes the self referencing redirect.
I added comments to the test to ensure clarity on what is happening.
Testing
Create a document, like "Test1"
Rename it to "Test2" and see that a redirect has been made.
Name it back to "Test1" and see that no self referencing redirect exists.