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

28563: GraphQL product search does not consider Category Permissions configuration - Pass the context as argument #28757

Merged
merged 14 commits into from
Jul 15, 2020

Conversation

pmarjan
Copy link
Contributor

@pmarjan pmarjan commented Jun 17, 2020

Description (*)

Fixes #28563

Consider catalog permissions when searchng for products - approach by passing context as parameter

Related Pull Requests

https://github.com/magento/partners-magento2ee/pull/271
https://github.com/magento/partners-magento2-infrastructure/pull/5

Fixed Issues (if relevant)

Manual testing scenarios (*)

  1. ...
  2. ...

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Jun 17, 2020

Hi @pmarjan. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests

You can find more information about the builds here

ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

For more details, please, review the Magento Contributor Guide documentation.

@pmarjan
Copy link
Contributor Author

pmarjan commented Jun 17, 2020

@magento run all tests

@pmarjan pmarjan changed the title Graphql 28563 28563: GraphQL product search does not consider Category Permissions configuration - Pass the context as argument Jun 17, 2020
@danielrenaud danielrenaud added this to the 2.4.1 milestone Jun 17, 2020
* @return SearchResultsInterface
*/
public function getList(
SearchCriteriaInterface $searchCriteria,
SearchResultInterface $searchResult,
array $attributes = []
array $attributes = [],
ContextInterface $context
Copy link
Contributor

Choose a reason for hiding this comment

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

We have to make this optional, or put it before attributes, because attributes is optional.
\Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Product\CollectionProcessorInterface::process has attributes mandatory and we also have to make it optional

*/
public function process(
Collection $collection,
SearchCriteriaInterface $searchCriteria,
array $attributeNames
array $attributeNames,
ContextInterface $context
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's best to do here attributes and context optional, because not all implementations use it
also code becomes very complicated to pass all this around then not use it
Plus adding suppress unused params later..it all points optional is better

@ghost ghost moved this from Pending Review to Changes Requested in Pull Requests Dashboard Jun 18, 2020
@ghost ghost assigned cpartica Jun 18, 2020
@pmarjan
Copy link
Contributor Author

pmarjan commented Jun 18, 2020

@cpartica context parameter is now optional, as per your request. the PR is updated, please let me know if further adjustments are needed.

@pmarjan
Copy link
Contributor Author

pmarjan commented Jun 18, 2020

@magento run all tests

@pmarjan
Copy link
Contributor Author

pmarjan commented Jun 18, 2020

@magento run all tests

@@ -11,7 +11,8 @@
"magento/module-store": "*",
"magento/module-eav-graph-ql": "*",
"magento/module-catalog-search": "*",
"magento/framework": "*"
"magento/framework": "*",
"magento/module-graph-ql": "*"
},
"suggest": {
"magento/module-graph-ql": "*",
Copy link
Contributor

Choose a reason for hiding this comment

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

we can remove graphql from suggest


if ($this->isCustomer($currentUserId, $currentUserType)) {
try {
$customerGroupId = $this->customerRepository->getById($currentUserId)->getGroupId();
Copy link
Contributor

Choose a reason for hiding this comment

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

is this request cached when the previous Context sets the user id?
it is weird how we do do this check for group but not for the currentUserId

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would say no (although not entirely sure). As far as I can tell, if FPC does not return a result (Magento\PageCache\Model\App\FrontController\BuiltinPlugin::aroundDispatch, line 73) processing of the authorization token will always flow in the same way. Otherwise, it would not run at all.

Therefore, line 62 here if ($this->isCustomer...) is probably trying to avoid unnecessary calls to customerRepository->getById(). Reasoning is there may be many requests that are not bearing any tokens, or are bearing invalid ones, and for them we do not want to allocate resources to load entity that we know for sure will not be loaded.

Copy link
Contributor

@cpartica cpartica Jun 22, 2020

Choose a reason for hiding this comment

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

I still think this is problematic, and it will probably trigger a significant degradation in query time
it should be called somewhere else when used like getExtensionAttribute->getCustomerGroupId

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cpartica the check for the customer group is now removed.

* @param FieldSelection $fieldSelection
* @param SearchCriteriaBuilder $searchCriteriaBuilder
* @param ScopeConfigInterface $scopeConfig
*/
public function __construct(
SearchResultFactory $searchResultFactory,
ProductProvider $productDataProvider,
LayerResolver $layerResolver,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cpartica, @danielrenaud
when scanning with PHPMD for design issues, I got
The class Filter has a coupling between objects value of 13. Consider to reduce the number of dependencies under 13.

To solve for that, LayerResolver is removed, since anyway is not used anymore in this class.

But, is this a backward incompatible change? If so, please advice, what might be a good way to proceed?

As a background, the MD test fails after adding the use of the ContextInterface, so the $context to the getResult() can be properly passed with specifying its type

@param ContextInterface $context

Copy link
Contributor

@danielrenaud danielrenaud Jul 13, 2020

Choose a reason for hiding this comment

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

If the dependency is not used at all, it should be ok to remove it. In GraphQl area, we only treat schema as our public api, so we can make changes like this to code that is not marked @api

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not so bad to remove it actually
Do this change and we'll get it approved. Since this implements an interface, the class was not meant to be extended anyway.

@ghost ghost assigned danielrenaud Jul 13, 2020
* @param FieldSelection $fieldSelection
* @param SearchCriteriaBuilder $searchCriteriaBuilder
* @param ScopeConfigInterface $scopeConfig
*/
public function __construct(
SearchResultFactory $searchResultFactory,
ProductProvider $productDataProvider,
LayerResolver $layerResolver,
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not so bad to remove it actually
Do this change and we'll get it approved. Since this implements an interface, the class was not meant to be extended anyway.

@ghost ghost moved this from Merge in Progress to Changes Requested in Pull Requests Dashboard Jul 13, 2020
@ghost ghost moved this from Changes Requested to Waiting Related PRs in Pull Requests Dashboard Jul 13, 2020
@ghost ghost moved this from Waiting Related PRs to Ready for Testing in Pull Requests Dashboard Jul 14, 2020
@cpartica cpartica moved this from Ready for Testing to Testing in Progress in Pull Requests Dashboard Jul 14, 2020
@cpartica cpartica moved this from Testing in Progress to Merge in Progress in Pull Requests Dashboard Jul 14, 2020
magento-engcom-team pushed a commit that referenced this pull request Jul 15, 2020
… Permissions configuration - Pass the context as argument #28757
@magento-engcom-team magento-engcom-team merged commit fa101ac into magento:2.4-develop Jul 15, 2020
@m2-assistant
Copy link

m2-assistant bot commented Jul 15, 2020

Hi @pmarjan, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@ghost ghost moved this from Merge in Progress to Recently Merged in Pull Requests Dashboard Jul 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Pull Requests Dashboard
  
Recently Merged
Development

Successfully merging this pull request may close these issues.

GraphQL product search does not consider Category Permissions configuration
4 participants