Skip to content
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

Enable 'back' GET parameter management #13233

Merged
merged 16 commits into from Apr 26, 2019

Conversation

tomas862
Copy link
Contributor

@tomas862 tomas862 commented Apr 8, 2019

Questions Answers
Branch? develop
Description? adds response event listener which detects if current request stack has "back-url" parameter and redirects to it instead of using original request. If the request url is equal to response url it prevent from such action. E.g "save and stay" button click functionality case. It also adds twig function which helps to generate urls in twig which will act according to the back-url
Type? bug fix
Category? BO
BC breaks? no
Deprecations? no
Fixed ticket? #12990
How to test? Go to "admin-dev/index.php/sell/customers/1/view" (if don't have customer with id 1 select another). Click on large edit pencil which is located in the first block - it will redirect you to page "admin-dev/index.php/sell/customers/1/edit?" and in that page the "back-url" will exist in the url parameters. Click "save" button - it will point you back to original view page "admin-dev/index.php/sell/customers/1/view" with success message attached. Also repeat the same process and instead of clicking "save", click "cancel" - it will go back to the same link "admin-dev/index.php/sell/customers/1/view"
  • Write unit tests

  • Write documentation.


This change is Reviewable

@prestonBot prestonBot added develop Branch Bug Type: Bug labels Apr 8, 2019
@tomas862
Copy link
Contributor Author

tomas862 commented Apr 8, 2019

@matks its more likely like POC here. Can you have a quick look to it and let men know if I shall finalize it with tests?

@matks
Copy link
Contributor

matks commented Apr 8, 2019

🎉 very nice way to use Symfony built-in features to handle this usecase 😄

@tomas862 tomas862 marked this pull request as ready for review April 8, 2019 14:41
@tomas862 tomas862 changed the title [WIP] Enable 'back' GET parameter management Enable 'back' GET parameter management Apr 8, 2019
@tomas862 tomas862 changed the base branch from develop to 1.7.6.x April 9, 2019 06:33
@tomas862
Copy link
Contributor Author

done - waiting for response in #13233 (comment). After the response, I'll re-apply tests

/**
* @param RequestStack|null $requestStack
*/
public function __construct($requestStack)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's avoid injecting the RequestStack in services if we can 😉and here we can ! (see https://igor.io/2013/03/31/stateless-services.html for detailed explanation about this matter)

You can pass the request in public function getBackUrl(Request $request).

2 side-effects that are great benefits (apart from the benefit number one which is "do not depend on request stack"):

  • we can use this service in CLI !
  • we can use this service on multiple Requests to retrieve the back parameter, not only the one provided by RequestStack

Copy link
Contributor Author

Choose a reason for hiding this comment

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

great article! Indeed it was easy to avoid RequestStack in that service - got reduced its usage and right now it is used in PathWithBackUrlExtension twig extension only.

@tomas862
Copy link
Contributor Author

@matks - let me know if this PR can be approved. Once I know its good to go I'll add docs about it :)

arguments:
- '@twig.extension.routing'
- '@prestashop.core.uti.back_url_provider'
- '@=service("request_stack") ? service("request_stack") : null'
Copy link
Contributor

Choose a reason for hiding this comment

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

I did not know you could do that 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that's really handy if you have "optional" dependencies, like from different libraries/bundles

@matks
Copy link
Contributor

matks commented Apr 16, 2019

@matks
Copy link
Contributor

matks commented Apr 16, 2019

@tomas862 just one question: why did you change the name of the GET parameter from "back" to "back-url" ?
If we keep it to "back", this will help for backward compatibility, will it not ? 🤔

@tomas862
Copy link
Contributor Author

tomas862 commented Apr 16, 2019

@matks well "back-url" made more sence for me since for word "back" has a greater chance that it might be used in a different context.

and since it is applied only for migrated pages "backward compatability" issue does not exist - the only issue that I see is that when someone will be migrating the pages they should not forget to add "back-url" instead of using "back".

Howerer, using "back" or "back-url" does not make much impact so I can change to "back" again easily if you see its more proper :)

@matks
Copy link
Contributor

matks commented Apr 17, 2019

and since it is applied only for migrated pages "backward compatability" issue does not exist

I was thinking of people using getAdminLink(): since this is able to redirect old legacy URLs to SF urls, then a link with back parameter will still work, wouldn't it ?

@tomas862 tomas862 requested a review from a team as a code owner April 19, 2019 07:17
@tomas862
Copy link
Contributor Author

@matks you're right - there would be a chance if someone is using getAdminLink with back url parameter to loose this functionality. I just renamed back-url to back :)

@matks matks added the Waiting for QA Status: action required, waiting for test feedback label Apr 23, 2019
@matks matks added this to the 1.7.6.0 milestone Apr 23, 2019
@marionf marionf added QA ✔️ Status: check done, code approved and removed Waiting for QA Status: action required, waiting for test feedback labels Apr 24, 2019
@PierreRambaud PierreRambaud merged commit b11debb into PrestaShop:1.7.6.x Apr 26, 2019
@PierreRambaud
Copy link
Contributor

Thanks @tomas862

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Type: Bug develop Branch QA ✔️ Status: check done, code approved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants