Skip to content

Fix For Issue:Incorrect redirect navigate on the review edit page #29318 #30436

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

Open
wants to merge 5 commits into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions app/code/Magento/Customer/Block/Adminhtml/Edit/BackButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@
*/
class BackButton extends GenericButton implements ButtonProviderInterface
{
/**
* @var Form
*/
private $form;
/**
* @var \Magento\Framework\Url\DecoderInterface
*/
private $decoder;

public function __construct(
\Magento\Framework\Url\DecoderInterface $decoder,
\Magento\Customer\Block\Adminhtml\Edit\Form $form,
\Magento\Backend\Block\Widget\Context $context,
\Magento\Framework\Registry $registry
) {
parent::__construct($context, $registry);
$this->form = $form;
$this->decoder = $decoder;
}

/**
* @return array
*/
Expand All @@ -32,6 +52,12 @@ public function getButtonData()
*/
public function getBackUrl()
{
if ($fromPath=$this->decoder->decode($this->form->getRequest()->getParam('fromPath'))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of adding this parameter from the request, can't we use the RedirectInterface and the method getRefererUrl? This should return the URL that the request came from.

Copy link
Contributor

@engcom-Foxtrot engcom-Foxtrot Feb 12, 2021

Choose a reason for hiding this comment

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

@gabrieldagama I don't think it's a good idea. This will cause redirect to any previously opened page and works as the 'back' button in the browser.

return $this->getUrl(
$fromPath,
['id' => $this->form->getRequest()->getParam('review_id')]
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we need a universal solution for similar cases instead of fixing particular places. We see the same situation when we go to the customer information page from the order view page. So, we may have a couple more places in the admin panel where we have the same issue with the back button.

It would be great if we could find out how to solve this issue for all occurrences.

Hope it makes sense

Copy link
Contributor

@engcom-Foxtrot engcom-Foxtrot Oct 28, 2020

Choose a reason for hiding this comment

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

Hello, @rogyar! I've done some investigation and I don't see the possibility to make a universal and reasonable solution for all "Back" buttons.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @engcom-Foxtrot. I've been reflected on that for some time and you are right. It's not an easy task unless we have the same name for an entity identifier.

Anyway, thank you for checking!

);
}
return $this->getUrl('*/*/');
}
}
18 changes: 17 additions & 1 deletion app/code/Magento/Review/Block/Adminhtml/Edit/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class Form extends \Magento\Backend\Block\Widget\Form\Generic
* @var \Magento\Store\Model\System\Store
*/
protected $_systemStore;
/**
* @var \Magento\Framework\Url\EncoderInterface
*/
private $urlEncoder;

/**
* @param \Magento\Backend\Block\Template\Context $context
Expand All @@ -45,6 +49,7 @@ class Form extends \Magento\Backend\Block\Widget\Form\Generic
* @param \Magento\Customer\APi\CustomerRepositoryInterface $customerRepository
* @param \Magento\Catalog\Model\ProductFactory $productFactory
* @param \Magento\Review\Helper\Data $reviewData
* @param \Magento\Framework\Url\EncoderInterface $urlEncoder
* @param array $data
*/
public function __construct(
Expand All @@ -55,12 +60,14 @@ public function __construct(
\Magento\Customer\Api\CustomerRepositoryInterface $customerRepository,
\Magento\Catalog\Model\ProductFactory $productFactory,
\Magento\Review\Helper\Data $reviewData,
\Magento\Framework\Url\EncoderInterface $urlEncoder,
array $data = []
) {
$this->_reviewData = $reviewData;
$this->customerRepository = $customerRepository;
$this->_productFactory = $productFactory;
$this->_systemStore = $systemStore;
$this->urlEncoder = $urlEncoder;
parent::__construct($context, $registry, $formFactory, $data);
}

Expand Down Expand Up @@ -120,10 +127,19 @@ protected function _prepareForm()
);

try {
$fromPath=$this->urlEncoder->encode('review/product/edit');
$customer = $this->customerRepository->getById($review->getCustomerId());
$customerText = __(
'<a href="%1" onclick="this.target=\'blank\'">%2 %3</a> <a href="mailto:%4">(%4)</a>',
$this->getUrl('customer/index/edit', ['id' => $customer->getId(), 'active_tab' => 'review']),
$this->getUrl(
'customer/index/edit',
[
'id' => $customer->getId(),
'active_tab' => 'review',
'fromPath' => $fromPath,
'review_id' => $this->getRequest()->getParam('id')
]
),
$this->escapeHtml($customer->getFirstname()),
$this->escapeHtml($customer->getLastname()),
$this->escapeHtml($customer->getEmail())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminOpenCustomerPageFromReviewActionGroup">
<annotations>
<description>Open Customer Page of Review author.</description>
</annotations>

<see selector="{{AdminHeaderSection.pageTitle}}" userInput="Edit Review" stepKey="assertOnReviewPage"/>
<click selector="{{AdminReviewDetailsSection.authorName}}" stepKey="goToCustomerEditPage"/>
<switchToNextTab stepKey="switchToNextTab"/>
<waitForPageLoad stepKey="waitForCustomerEditPage"/>
</actionGroup>
</actionGroups>
14 changes: 14 additions & 0 deletions app/code/Magento/Review/Test/Mftf/Page/AdminEditReviewPage.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<pages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/PageObject.xsd">
<page name="AdminEditReviewPage" url="review/product/edit/id/{{reviewId}}/" area="admin" module="Review" parameterized="true">
<section name="AdminReviewDetailsSection"/>
</page>
</pages>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
<section name="AdminReviewDetailsSection">
<element name="authorName" type="button" selector="//*[@id='customer']/a[1]"/>
<element name="authorEmail" type="select" selector="//*[@id='customer']/a[2]"/>
</section>
</sections>
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="AdminReviewCorrectBackButtonTest">
<annotations>
<features value="Review"/>
<stories value="Review By Customers"/>
<title value="Admin review correct back button test"/>
<description value="Verify 'Back' button redirects on correct page if Customer page opened from Review page."/>
<severity value="MAJOR"/>
<testCaseId value="MC-36271"/>
</annotations>
<before>
<createData entity="SimpleSubCategory" stepKey="createCategory"/>
<createData entity="SimpleProduct" stepKey="createProduct">
<requiredEntity createDataKey="createCategory"/>
</createData>
<createData entity="Simple_US_Customer" stepKey="createCustomer"/>
<actionGroup ref="AdminLoginActionGroup" stepKey="LoginAsAdmin"/>
</before>
<after>
<actionGroup ref="AdminOpenReviewsPageActionGroup" stepKey="openAllReviewsPage"/>
<actionGroup ref="AdminDeleteReviewsByUserNicknameActionGroup" stepKey="deleteCustomerReview"/>
<actionGroup ref="ClearFiltersAdminDataGridActionGroup" stepKey="clearNickNameReviewFilters"/>
<deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/>
<deleteData createDataKey="createProduct" stepKey="deleteProduct"/>
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
</after>
<!-- Create Review on Storefront -->
<actionGroup ref="LoginToStorefrontActionGroup" stepKey="storefrontCustomerLogin">
<argument name="Customer" value="$$createCustomer$$"/>
</actionGroup>
<actionGroup ref="StorefrontOpenProductPageActionGroup" stepKey="openStorefrontProductPage">
<argument name="productUrl" value="$$createProduct.custom_attributes[url_key]$$"/>
</actionGroup>
<actionGroup ref="StorefrontAddProductReviewActionGroup" stepKey="addReview"/>

<!-- Grab Review's id -->
<actionGroup ref="AdminOpenPendingReviewsPageActionGroup" stepKey="openReviewsPage"/>
<actionGroup ref="ClearFiltersAdminDataGridActionGroup" stepKey="clearFilters"/>
<actionGroup ref="AdminOpenReviewByUserNicknameActionGroup" stepKey="openFirstCustomerReviews"/>
<grabFromCurrentUrl regex="~/id/(\d+)/~" stepKey="grabReviewId"/>

<!-- Check if "Back" button works correctly if Customer page opened from Review page -->
<actionGroup ref="AdminOpenCustomerPageFromReviewActionGroup" stepKey="openCustomerPageFromReview"/>
<actionGroup ref="AdminClickBackButtonActionGroup" stepKey="clickBackToEditReviewPage">
<argument name="expectedPageUrl" value="{{AdminEditReviewPage.url('$grabReviewId')}}"/>
</actionGroup>

<!-- Check if "Back" button works correctly if Customer page opened not from Review page -->
<actionGroup ref="AdminOpenCustomerEditPageActionGroup" stepKey="openCustomerEditPage">
<argument name="customerId" value="$$createCustomer.id$$"/>
</actionGroup>
<actionGroup ref="AdminClickBackButtonActionGroup" stepKey="clickBackToCustomerIndexPage">
<argument name="expectedPageUrl" value="{{AdminCustomerPage.url}}"/>
</actionGroup>
</test>
</tests>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminClickBackButtonActionGroup">
<annotations>
<description>Click on 'Back' button. Validate correct page opened.</description>
</annotations>
<arguments>
<argument name="expectedPageUrl" type="string"/>
</arguments>

<click selector="{{AdminGridMainControls.back}}" stepKey="clickBackButton"/>
<waitForPageLoad stepKey="waitForPageLoad"/>
<seeInCurrentUrl url="{{expectedPageUrl}}" stepKey="assertOnExpectedPage"/>
</actionGroup>
</actionGroups>