Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/dev/1.9' into 1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrebenchuk committed Aug 17, 2016
2 parents 9955b86 + 2f8237d commit d085a6f
Show file tree
Hide file tree
Showing 30 changed files with 857 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
}
.contact-element-label {
padding-right: 5px;
line-height: 24px;
+ .inline-actions-element {
top: 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function searchEntities($search, $firstResult, $maxResults)
->setMaxResults($maxResults);

$dataChannel = $this->getDataChannelById($channelId);
if ($dataChannel) {
if ($dataChannel && $this->securityFacade->isGranted('oro_integration_assign')) {
$queryBuilder->andWhere('e.channel = :channel')
->setParameter('channel', $dataChannel->getDataSource());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
namespace OroCRM\Bundle\MagentoBundle\Autocomplete;

use Oro\Bundle\FormBundle\Autocomplete\SearchHandler;
use Oro\Bundle\SecurityBundle\SecurityFacade;

use OroCRM\Bundle\ChannelBundle\Entity\Channel;

abstract class IntegrationAwareSearchHandler extends SearchHandler
{
/** @var string */
protected $dataChannelClass;

/** @var SecurityFacade */
protected $securityFacade;

/**
* @param string $dataChannelClass
* @return IntegrationAwareSearchHandler
Expand All @@ -21,6 +26,14 @@ public function setDataChannelClass($dataChannelClass)
return $this;
}

/**
* @param SecurityFacade $securityFacade
*/
public function setSecurityFacade(SecurityFacade $securityFacade)
{
$this->securityFacade = $securityFacade;
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected function searchEntities($search, $firstResult, $maxResults)
->addOrderBy('e.name', 'ASC');

$dataChannel = $this->getDataChannelById($channelId);
if ($dataChannel) {
if ($dataChannel && $this->securityFacade->isGranted('oro_integration_assign')) {
$queryBuilder->andWhere('e.channel = :channel')
->setParameter('channel', $dataChannel->getDataSource());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;

use Oro\Bundle\SecurityBundle\Annotation\Acl;
use Oro\Bundle\SecurityBundle\Annotation\AclAncestor;
use Oro\Bundle\SecurityBundle\SecurityFacade;

use OroCRM\Bundle\MagentoBundle\Entity\Customer;
use OroCRM\Bundle\AccountBundle\Entity\Account;
Expand Down Expand Up @@ -81,6 +83,10 @@ public function updateAction(Customer $customer)
*/
public function createAction()
{
if (!$this->getSecurityFacade()->isGranted('oro_integration_assign')) {
throw new AccessDeniedHttpException();
}

return $this->update(new Customer());
}

Expand Down Expand Up @@ -159,7 +165,7 @@ public function accountCustomersInfoAction(Account $account, Channel $channel)
$customers = array_filter(
$customers,
function ($item) {
return $this->get('oro_security.security_facade')->isGranted('VIEW', $item);
return $this->getSecurityFacade()->isGranted('VIEW', $item);
}
);

Expand Down Expand Up @@ -215,4 +221,12 @@ public function addressBookAction(Customer $customer)
{
return ['entity' => $customer];
}

/**
* @return SecurityFacade
*/
protected function getSecurityFacade()
{
return $this->get('oro_security.security_facade');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Oro\Bundle\SecurityBundle\Annotation\Acl;
use Oro\Bundle\SecurityBundle\Annotation\AclAncestor;
use Oro\Bundle\ImportExportBundle\Processor\ProcessorRegistry;
use Oro\Bundle\IntegrationBundle\Entity\Channel;

use OroCRM\Bundle\MagentoBundle\Entity\Customer;
Expand Down Expand Up @@ -123,7 +124,13 @@ public function actualizeAction(Order $order)
try {
$result = $this->loadOrderInformation(
$order->getChannel(),
['filters' => ['increment_id' => $order->getIncrementId()]]
[
ProcessorRegistry::TYPE_IMPORT => [
'filters' => [
'increment_id' => $order->getIncrementId()
]
]
]
);
} catch (\LogicException $e) {
$this->get('logger')->addCritical($e->getMessage(), ['exception' => $e]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ abstract class AbstractTwoWaySyncActionPermissionProvider
{
const CHANNEL_KEY = 'channelId';
const CUSTOMER_ID = 'customerId';
const CUSTOMER = 'customerData';
const CUSTOMER_ORIGIN_ID = 'customerOriginId';
/**
* @var ChannelSettingsProvider
*/
private $channelSettingsProvider;
protected $channelSettingsProvider;

/**
* @param ChannelSettingsProvider $channelSettingsProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Oro\Bundle\SecurityBundle\SecurityFacade;
use OroCRM\Bundle\MagentoBundle\Entity\NewsletterSubscriber;
use OroCRM\Bundle\MagentoBundle\Entity\Customer;

class NewsletterSubscriberPermissionProvider extends AbstractTwoWaySyncActionPermissionProvider
{
Expand Down Expand Up @@ -69,6 +70,47 @@ public function setSecurityFacade(SecurityFacade $securityFacade)
return $this;
}

/**
* Check if channel integration is applicable for magento customer.
* Get channel integration id from customer channel if it's does not exist in grid record
*
* @param ResultRecordInterface $record
* @param bool $checkExtension
*
* @return bool
*/
protected function isChannelApplicable(ResultRecordInterface $record, $checkExtension = true)
{
$channelId = $this->getChannelId($record);

if (!$channelId) {
return false;
}

return $this->channelSettingsProvider->isChannelApplicable($channelId, $checkExtension);
}

/**
* @param ResultRecordInterface $record
*
* @return int|null
*/
protected function getChannelId(ResultRecordInterface $record)
{
$channelId = $record->getValue(self::CHANNEL_KEY);
if (!$channelId) {
$customer = $record->getValue(self::CUSTOMER);
if ($customer instanceof Customer || $customer instanceof NewsletterSubscriber) {
$channel = $customer->getChannel();
if ($channel) {
$channelId = $customer->getChannel()->getId();
}
}
}

return $channelId;
}

/**
* @return bool
*/
Expand Down
6 changes: 2 additions & 4 deletions src/OroCRM/Bundle/MagentoBundle/Entity/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
*
* @package OroCRM\Bundle\OroCRMMagentoBundle\Entity
* @ORM\Entity
* @ORM\Table(name="orocrm_magento_product",
* uniqueConstraints={@ORM\UniqueConstraint(name="unq_sku_channel_id", columns={"sku", "channel_id"})}
* )
* @ORM\Table(name="orocrm_magento_product")
* @Config(
* defaultValues={
* "security"={
Expand Down Expand Up @@ -56,7 +54,7 @@ class Product extends ExtendProduct implements IntegrationAwareInterface
/**
* @var string
*
* @ORM\Column(name="sku", type="string", length=255, nullable=false)
* @ORM\Column(name="sku", type="string", length=255, nullable=true)
* @Oro\Versioned
*/
protected $sku;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace OroCRM\Bundle\MagentoBundle\EventListener;

use Oro\Bundle\DataGridBundle\Datasource\Orm\OrmDatasource;
use Oro\Bundle\DataGridBundle\Event\BuildAfter;
use Oro\Bundle\SecurityBundle\SecurityFacade;

/**
* Listener for grid "magento-customers-group-by-channel-grid".
*
* @see \OroCRM\Bundle\MagentoBundle\Autocomplete\CustomerGroupSearchHandler
*/
class CustomerGroupGridListener
{
/** @var SecurityFacade */
protected $securityFacade;

/**
* @param SecurityFacade $securityFacade
*/
public function __construct(SecurityFacade $securityFacade)
{
$this->securityFacade = $securityFacade;
}

/**
* @param BuildAfter $event
*/
public function onBuildAfter(BuildAfter $event)
{
$datagrid = $event->getDatagrid();
$datasource = $datagrid->getDatasource();
if ($datasource instanceof OrmDatasource) {
$queryBuilder = $datasource->getQueryBuilder();
$isGranted = $this->securityFacade->isGranted('oro_integration_assign');
// if permission for integration channel assign is not granted
if (!$isGranted) {
$queryBuilder->andWhere('1 = 0');
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace OroCRM\Bundle\MagentoBundle\EventListener;

use Doctrine\ORM\EntityManager;

use Oro\Bundle\DataGridBundle\Datasource\Orm\OrmDatasource;
use Oro\Bundle\DataGridBundle\Event\BuildAfter;
use Oro\Bundle\SecurityBundle\SecurityFacade;

use OroCRM\Bundle\MagentoBundle\Entity\MagentoSoapTransport;
use OroCRM\Bundle\MagentoBundle\Provider\Iterator\StoresSoapIterator;
use OroCRM\Bundle\ChannelBundle\Entity\Channel;

/**
* Listener for grid "magento-store-by-channel-grid".
*
* @see \OroCRM\Bundle\MagentoBundle\Autocomplete\StoreSearchHandler
*/
class StoreGridListener
{
/** @var SecurityFacade */
protected $securityFacade;

/** @var string */
protected $dataChannelClass;

/** @var EntityManager */
protected $entityManager;

/**
* @param SecurityFacade $securityFacade
* @param string $dataChannelClass
* @param EntityManager $entityManager
*/
public function __construct(SecurityFacade $securityFacade, $dataChannelClass, EntityManager $entityManager)
{
$this->securityFacade = $securityFacade;
$this->dataChannelClass = $dataChannelClass;
$this->entityManager = $entityManager;
}

/**
* Limit stores to website selected in integration settings
* if ASSIGN permission for integration channel is granted
*
* @param BuildAfter $event
*/
public function onBuildAfter(BuildAfter $event)
{
$datagrid = $event->getDatagrid();
$datasource = $datagrid->getDatasource();
if ($datasource instanceof OrmDatasource) {
if ($this->securityFacade->isGranted('oro_integration_assign')) {
$parameters = $datagrid->getParameters();
$channelIds = $parameters->get('channelIds');
$dataChannel = $this->getDataChannelById($channelIds);
if ($dataChannel) {
$transport = $dataChannel->getDataSource()->getTransport();
if ($transport instanceof MagentoSoapTransport) {
$websiteId = $transport->getSettingsBag()->get('website_id');
if ($websiteId !== StoresSoapIterator::ALL_WEBSITES) {
$datasource
->getQueryBuilder()
->andWhere('w.originId = :id')
->setParameter('id', $websiteId);
}
}
}
} else {
// if permission for integration channel assign is not granted
$datasource->getQueryBuilder()
->andWhere('1 = 0');
}
}
}

/**
* @param int $dataChannelId
* @return Channel
*/
protected function getDataChannelById($dataChannelId)
{
return $this->entityManager->find($this->dataChannelClass, $dataChannelId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CartItemsApiType extends AbstractType
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('sku', 'text', ['required' => true]);
$builder->add('sku', 'text', ['required' => false]);
$builder->add('name', 'text', ['required' => true]);
$builder->add('qty', 'number', ['required' => true]);
$builder->add('price', 'oro_money', ['required' => true]);
Expand Down
Loading

0 comments on commit d085a6f

Please sign in to comment.