2 added 2685 characters in body
source | link
  • I made a start that should be helping you a bit further: I did extend but you are welcome to use plugin of course:

Theand then I think it will be better to extends the function getDatagetSearchCriteria function needs essentially to validate whether the data can be displayed or not for the logged in backend user. See code below:

<?php    
namespace Mbs\CustomerTakeOver\Ui\Component;

use Magento\Customer\Ui\Component\Listing\AttributeRepository;
use Magento\Framework\Api\FilterBuilder;
use Magento\Framework\Api\Search\SearchCriteriaBuilder;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\View\Element\UiComponent\DataProvider\Reporting;

class CustomerGridDataProvider extends \Magento\Customer\Ui\Component\DataProvider
{
    /**
     * @var \Magento\Backend\Model\Auth\Session
     */
    private $authSession;

    public function __construct(
        $name,
        $primaryFieldName,
        $requestFieldName,
        Reporting $reporting,
        SearchCriteriaBuilder $searchCriteriaBuilder,
        RequestInterface $request,
        FilterBuilder $filterBuilder,
        AttributeRepository $attributeRepository,
        \Magento\Backend\Model\Auth\Session $authSession,
        array $meta = [],
        array $data = []
    ) {
        parent::__construct($name, $primaryFieldName, $requestFieldName, $reporting, $searchCriteriaBuilder, $request,
            $filterBuilder, $attributeRepository, $meta, $data);
        $this->authSession = $authSession;
    }

    /**
     * {@inheritdoc}
     */
    public function getSearchCriteria()
    {
        if (!$this->searchCriteria) {
            $filter = $this->filterBuilder->setField('user_creator')
                    ->setConditionType('eq')
                    ->setValue($this->getUserIdFromLoggedInBackend());
            $this->searchCriteria->setFilterGroups([$filter]);

            $this->searchCriteria = $this->searchCriteriaBuilder->create();
            $this->searchCriteria->setRequestName($this->name);
        }
        return $this->searchCriteria;
    }

    private function getUserIdFromLoggedInBackend()
    {
        return $this->authSession->getUser()->getId();
    }
}

It isI have not a simple querytest the search criteria code and I suspect some issues with pagination butdo know the filter builder can be fiddly at least these steps will help youtimes. UnfortunatelyBut hopefully, the deadline you have forwill get the query does not fit my diary. Bestgist of luckthis solution now.

The getData function needs essentially to validate whether the data can be displayed or not for the logged in backend user.

It is not a simple query and I suspect some issues with pagination but at least these steps will help you. Unfortunately, the deadline you have for the query does not fit my diary. Best of luck

  • I made a start that should be helping you a bit further: I did extend but you are welcome to use plugin of course:

and then I think it will be better to extends the function getSearchCriteria. See code below:

<?php    
namespace Mbs\CustomerTakeOver\Ui\Component;

use Magento\Customer\Ui\Component\Listing\AttributeRepository;
use Magento\Framework\Api\FilterBuilder;
use Magento\Framework\Api\Search\SearchCriteriaBuilder;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\View\Element\UiComponent\DataProvider\Reporting;

class CustomerGridDataProvider extends \Magento\Customer\Ui\Component\DataProvider
{
    /**
     * @var \Magento\Backend\Model\Auth\Session
     */
    private $authSession;

    public function __construct(
        $name,
        $primaryFieldName,
        $requestFieldName,
        Reporting $reporting,
        SearchCriteriaBuilder $searchCriteriaBuilder,
        RequestInterface $request,
        FilterBuilder $filterBuilder,
        AttributeRepository $attributeRepository,
        \Magento\Backend\Model\Auth\Session $authSession,
        array $meta = [],
        array $data = []
    ) {
        parent::__construct($name, $primaryFieldName, $requestFieldName, $reporting, $searchCriteriaBuilder, $request,
            $filterBuilder, $attributeRepository, $meta, $data);
        $this->authSession = $authSession;
    }

    /**
     * {@inheritdoc}
     */
    public function getSearchCriteria()
    {
        if (!$this->searchCriteria) {
            $filter = $this->filterBuilder->setField('user_creator')
                    ->setConditionType('eq')
                    ->setValue($this->getUserIdFromLoggedInBackend());
            $this->searchCriteria->setFilterGroups([$filter]);

            $this->searchCriteria = $this->searchCriteriaBuilder->create();
            $this->searchCriteria->setRequestName($this->name);
        }
        return $this->searchCriteria;
    }

    private function getUserIdFromLoggedInBackend()
    {
        return $this->authSession->getUser()->getId();
    }
}

I have not test the search criteria code and I do know the filter builder can be fiddly at times. But hopefully, you will get the gist of this solution now.

1
source | link

step 1: create a new customer attribute that keeps track of the admin user who has created the customer. For customers created from frontend, I guess you may come up with a business rule whether they show or not..

step 2: extends the class: \Magento\Customer\Ui\Component\DataProvider or write a plugin for it.

The getData function needs essentially to validate whether the data can be displayed or not for the logged in backend user.

It is not a simple query and I suspect some issues with pagination but at least these steps will help you. Unfortunately, the deadline you have for the query does not fit my diary. Best of luck