Skip to content

Commit

Permalink
Merge pull request #6440 from laboro/bug/BAP-9639_1.9
Browse files Browse the repository at this point in the history
BAP-9639: 500 error is occurred on Business Units
  • Loading branch information
vsoroka committed Jan 11, 2016
2 parents 5d2ff56 + d4bc447 commit 5fdc394
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 87 deletions.
15 changes: 7 additions & 8 deletions src/Oro/Bundle/ActivityBundle/Manager/ActivityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,15 +413,14 @@ public function getActivityAssociations($entityClass)
$config = $this->activityConfigProvider->getConfig($entityClass);
$activityClassNames = $config->get('activities', false, []);
foreach ($activityClassNames as $activityClassName) {
if (!$this->isActivityAssociationEnabled($entityClass, $activityClassName)) {
$associationName = ExtendHelper::buildAssociationName($entityClass, ActivityScope::ASSOCIATION_KIND);
if (!$this->isActivityAssociationEnabled($entityClass, $activityClassName, $associationName)) {
continue;
}

$entityConfig = $this->entityConfigProvider->getConfig($activityClassName);
$activityConfig = $this->activityConfigProvider->getConfig($activityClassName);

$associationName = ExtendHelper::buildAssociationName($entityClass, ActivityScope::ASSOCIATION_KIND);

$item = [
'className' => $activityClassName,
'associationName' => $associationName,
Expand Down Expand Up @@ -457,15 +456,14 @@ public function getActivityActions($entityClass)

$activityClassNames = $this->activityConfigProvider->getConfig($entityClass)->get('activities');
foreach ($activityClassNames as $activityClassName) {
if (!$this->isActivityAssociationEnabled($entityClass, $activityClassName)) {
$associationName = ExtendHelper::buildAssociationName($entityClass, ActivityScope::ASSOCIATION_KIND);
if (!$this->isActivityAssociationEnabled($entityClass, $activityClassName, $associationName)) {
continue;
}

$activityConfig = $this->activityConfigProvider->getConfig($activityClassName);
$buttonWidget = $activityConfig->get('action_button_widget');
if (!empty($buttonWidget)) {
$associationName = ExtendHelper::buildAssociationName($entityClass, ActivityScope::ASSOCIATION_KIND);

$item = [
'className' => $activityClassName,
'associationName' => $associationName,
Expand Down Expand Up @@ -566,16 +564,17 @@ public function addFilterByTargetEntity(
/**
* @param string $entityClass
* @param string $activityClassName
* @param string $activityAssociationName
*
* @return bool
*/
protected function isActivityAssociationEnabled($entityClass, $activityClassName)
protected function isActivityAssociationEnabled($entityClass, $activityClassName, $activityAssociationName)
{
$extendConfig = $this->extendConfigProvider->getConfig($activityClassName);
$relations = $extendConfig->get('relation', false, []);
$relationKey = ExtendHelper::buildRelationKey(
$activityClassName,
ExtendHelper::buildAssociationName($entityClass, ActivityScope::ASSOCIATION_KIND),
$activityAssociationName,
RelationType::MANY_TO_MANY,
$entityClass
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
use Doctrine\Common\Persistence\ManagerRegistry;

use Oro\Bundle\ActivityBundle\EntityConfig\ActivityScope;
use Oro\Bundle\ActivityBundle\Manager\ActivityManager;
use Oro\Bundle\ActivityListBundle\Provider\ActivityListChainProvider;
use Oro\Bundle\EntityBundle\ORM\DoctrineHelper;
use Oro\Bundle\EntityConfigBundle\Provider\ConfigProvider;
use Oro\Bundle\EntityExtendBundle\Tools\ExtendHelper;
use Oro\Bundle\UIBundle\Event\BeforeGroupingChainWidgetEvent;

class PlaceholderFilter
Expand All @@ -24,22 +26,28 @@ class PlaceholderFilter
/** @var ConfigProvider */
protected $configProvider;

/** @var ActivityManager */
protected $activityManager;

/**
* @param ActivityListChainProvider $activityListChainProvider
* @param ManagerRegistry $doctrine
* @param DoctrineHelper $doctrineHelper
* @param ConfigProvider $configProvider
* @param ActivityManager $activityManager
*/
public function __construct(
ActivityListChainProvider $activityListChainProvider,
ManagerRegistry $doctrine,
DoctrineHelper $doctrineHelper,
ConfigProvider $configProvider
ConfigProvider $configProvider,
ActivityManager $activityManager
) {
$this->activityListProvider = $activityListChainProvider;
$this->doctrine = $doctrine;
$this->doctrineHelper = $doctrineHelper;
$this->configProvider = $configProvider;
$this->activityManager = $activityManager;
}

/**
Expand All @@ -52,33 +60,60 @@ public function __construct(
public function isApplicable($entity = null, $pageType = null)
{
if ($pageType === null || !is_object($entity) || !$this->doctrineHelper->isManageableEntity($entity) ||
$this->doctrineHelper->isNewEntity($entity)) {
$this->doctrineHelper->isNewEntity($entity)
) {
return false;
}

$entityClass = $this->doctrineHelper->getEntityClass($entity);
if (!$this->configProvider->hasConfig($entityClass)) {
return false;
}

$hasAppliedActivityAssociation = false;
$activityAssociations = $this->activityManager->getActivityAssociations($entityClass);
foreach ($activityAssociations as $activityAssociation) {
$isAssociationAccessible = ExtendHelper::isFieldAccessible(
$this->configProvider->getConfig(
$activityAssociation['className'],
$activityAssociation['associationName']
)
);
if ($isAssociationAccessible) {
$hasAppliedActivityAssociation = true;
break;
}
}

/**
* If at least one activity is accessible we can continue otherwise no.
*/
if (!$hasAppliedActivityAssociation) {
return false;
}

$pageType = (int) $pageType;
$id = $this->doctrineHelper->getSingleEntityIdentifier($entity);
$entityClass = $this->doctrineHelper->getEntityClass($entity);
$activityListRepo = $this->doctrine->getRepository('OroActivityListBundle:ActivityList');

return $this->isAllowedOnPage($entity, $pageType) && (
return $this->isAllowedOnPage($entityClass, $pageType) && (
in_array($entityClass, $this->activityListProvider->getTargetEntityClasses())
|| (bool)$activityListRepo->getRecordsCountForTargetClassAndId($entityClass, $id)
);
}

/**
* @param object $entity
* @param string $entityClass
* @param int $pageType
* @return bool
*/
protected function isAllowedOnPage($entity, $pageType)
protected function isAllowedOnPage($entityClass, $pageType)
{
if (!$this->configProvider->hasConfig($entity)) {
if (!$this->configProvider->hasConfig($entityClass)) {
return false;
}

$config = $this->configProvider->getConfig($entity);
$config = $this->configProvider->getConfig($entityClass);
if (!$config->has(ActivityScope::SHOW_ON_PAGE)) {
return false;
}
Expand All @@ -101,7 +136,10 @@ public function isAllowedButton(BeforeGroupingChainWidgetEvent $event)
$entity = $event->getEntity();
$pageType = $event->getPageType();

if ($pageType === null || !is_object($entity) || !$this->isAllowedOnPage($entity, $pageType)) {
if ($pageType === null
|| !is_object($entity)
|| !$this->isAllowedOnPage($this->doctrineHelper->getEntityClass($entity), $pageType)
) {
// Clear allowed widgets
$event->setWidgets([]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ services:
- @doctrine
- @oro_entity.doctrine_helper
- @oro_entity_config.provider.activity
- @oro_activity.manager
tags:
- { name: kernel.event_listener, event: oro.ui.grouping_chain_widget.before, method: isAllowedButton }

Expand Down
Loading

0 comments on commit 5fdc394

Please sign in to comment.