Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/dev/1.10' into 1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrebenchuk committed Sep 9, 2016
2 parents f6f5b33 + 210441c commit 40447e9
Show file tree
Hide file tree
Showing 41 changed files with 368 additions and 179 deletions.
6 changes: 6 additions & 0 deletions UPGRADE-1.10.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
UPGRADE FROM 1.10 to 1.10.2
========================

####EmailBundle
- Constructor of `Oro\Bundle\EmailBundle\Form\Type\EmailTemplateRichTextType` changed. Removed the arguments.
- Constructor of `Oro\Bundle\EmailBundle\Form\Type\EmailType` changed. Added `ConfigManager $configManager` as last argument.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Oro\Component\Routing\Resolver\RouteOptionsResolverInterface;

use Oro\Bundle\ActivityBundle\EntityConfig\ActivityScope;
use Oro\Bundle\EntityBundle\Exception\EntityAliasNotFoundException;
use Oro\Bundle\EntityBundle\ORM\EntityAliasResolver;
use Oro\Bundle\EntityConfigBundle\Config\ConfigInterface;
use Oro\Bundle\EntityConfigBundle\Provider\ConfigProvider;
Expand Down Expand Up @@ -71,12 +72,16 @@ public function resolve(Route $route, RouteCollectionAccessor $routes)
protected function getSupportedActivities()
{
if (null === $this->supportedActivities) {
$this->supportedActivities = array_map(
$this->supportedActivities = array_filter(array_map(
function (ConfigInterface $config) {
// convert to entity alias
return $this->entityAliasResolver->getPluralAlias(
$config->getId()->getClassName()
);
try {
// convert to entity alias
return $this->entityAliasResolver->getPluralAlias(
$config->getId()->getClassName()
);
} catch (EntityAliasNotFoundException $e) {
return false;
}
},
$this->groupingConfigProvider->filter(
function (ConfigInterface $config) {
Expand All @@ -88,7 +93,7 @@ function (ConfigInterface $config) {
&& in_array(ActivityScope::GROUP_ACTIVITY, $groups, true);
}
)
);
));
}

return $this->supportedActivities;
Expand Down
2 changes: 2 additions & 0 deletions src/Oro/Bundle/ApiBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ services:
- '@oro_api.entity_alias_loader'
- '@oro_api.entity_alias_cache'
- %kernel.debug%
calls:
- [ setLogger, [ '@logger' ] ]
lazy: true

oro_api.entity_alias_cache:
Expand Down
3 changes: 3 additions & 0 deletions src/Oro/Bundle/EmailBundle/Cache/EntityCacheClearer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use Symfony\Component\Filesystem\Filesystem;

/**
* @deprecated since 1.9. Removing classes breaks doctrine metadata functionality
*/
class EntityCacheClearer implements CacheClearerInterface
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public function getConfigTreeBuilder()
'show_recent_emails_in_user_bar' => ['value' => true],
'attachment_sync_enable' => ['value' => true],
'attachment_sync_max_size' => ['value' => 0],
'attachment_preview_limit' => ['value' => 8]
'attachment_preview_limit' => ['value' => 8],
'sanitize_html' => ['value' => false]
]
);

Expand Down
3 changes: 1 addition & 2 deletions src/Oro/Bundle/EmailBundle/Entity/MailboxProcessSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Doctrine\ORM\Mapping as ORM;

use Oro\Bundle\EmailBundle\Entity\Mailbox;
use Oro\Bundle\EmailBundle\Form\Model\ExtendMailboxProcessSettings;

/**
* @ORM\Table(
Expand All @@ -15,7 +14,7 @@
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="type", type="string", length=30)
*/
abstract class MailboxProcessSettings extends ExtendMailboxProcessSettings
abstract class MailboxProcessSettings
{
/**
* @ORM\Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,27 @@ class EmailTemplateTransformer implements DataTransformerInterface
/** @var SanitizeHTMLTransformer */
protected $transformer;

/** @var bool Run sanitization transformer or not */
/** @deprecated since 1.10 */
private $sanitize;

/**
* @param SanitizeHTMLTransformer $transformer
*/
public function __construct(SanitizeHTMLTransformer $transformer)
{
$this->transformer = $transformer;
$this->sanitize = true;
}

/**
* {@inheritdoc}
*/
public function transform($value)
{
$value = $this->transformer->transform($value);
if ($this->sanitize) {
$value = $this->transformer->transform($value);
}

return $this->decodeTemplateVariables($value);
}
Expand All @@ -34,11 +41,23 @@ public function transform($value)
*/
public function reverseTransform($value)
{
$value = $this->transformer->reverseTransform($value);
if ($this->sanitize) {
$value = $this->transformer->reverseTransform($value);
}

return $this->decodeTemplateVariables($value);
}

/**
* Toggle sanitization transformer
* @param bool $sanitize
* @deprecated since 1.10
*/
public function setSanitize($sanitize)
{
$this->sanitize = (bool) $sanitize;
}

/**
* Decodes encoded brackets '{{' and '}}' and data inside them for further replacing with system/entity variables.
*
Expand Down

This file was deleted.

27 changes: 5 additions & 22 deletions src/Oro/Bundle/EmailBundle/Form/Type/EmailTemplateRichTextType.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,22 @@
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;

use Oro\Bundle\FormBundle\Form\DataTransformer\SanitizeHTMLTransformer;

use Oro\Bundle\EmailBundle\Form\DataTransformer\EmailTemplateTransformer;

class EmailTemplateRichTextType extends AbstractType
{
const NAME = 'oro_email_template_rich_text';

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

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

/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->resetModelTransformers();

$allowableTags = null;
if (!empty($options['wysiwyg_options']['valid_elements'])) {
$allowableTags = $options['wysiwyg_options']['valid_elements'];
}

$transformer = new SanitizeHTMLTransformer($allowableTags, $this->cacheDir);
$builder->addModelTransformer(new EmailTemplateTransformer($transformer));
$templateTransformer = new EmailTemplateTransformer();
// sanitize transformer is already added in the parent type
$templateTransformer->setSanitize(false);
// append template transformer to run after parent type transformers
$builder->addModelTransformer($templateTransformer, true);
}

/**
Expand Down
19 changes: 18 additions & 1 deletion src/Oro/Bundle/EmailBundle/Form/Type/EmailTemplateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

use Oro\Bundle\LocaleBundle\Model\LocaleSettings;
use Oro\Bundle\ConfigBundle\Config\ConfigManager;
use Oro\Bundle\FormBundle\Form\Type\OroRichTextType;
use Oro\Bundle\LocaleBundle\Model\LocaleSettings;

class EmailTemplateType extends AbstractType
{
Expand Down Expand Up @@ -79,6 +80,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'required' => false,
'locales' => $this->getLanguages(),
'labels' => $this->getLocaleLabels(),
'content_options' => ['wysiwyg_options' => $this->getWysiwygOptions()],
)
);
$builder->add(
Expand Down Expand Up @@ -180,4 +182,19 @@ protected function getLocaleLabels()
{
return $this->localeSettings->getLocalesByCodes($this->getLanguages(), $this->localeSettings->getLanguage());
}

/**
* @return array
*/
protected function getWysiwygOptions()
{
if ($this->userConfig->get('oro_email.sanitize_html')) {
return [];
}

return [
'valid_elements' => null, //all elements are valid
'plugins' => array_merge(OroRichTextType::$defaultPlugins, ['fullpage']),
];
}
}
39 changes: 36 additions & 3 deletions src/Oro/Bundle/EmailBundle/Form/Type/EmailType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Security\Core\SecurityContextInterface;

use Oro\Bundle\FormBundle\Utils\FormUtils;
use Oro\Bundle\ConfigBundle\Config\ConfigManager;
use Oro\Bundle\EmailBundle\Builder\Helper\EmailModelBuilderHelper;
use Oro\Bundle\EmailBundle\Entity\Repository\EmailTemplateRepository;
use Oro\Bundle\EmailBundle\Form\Model\Email;
use Oro\Bundle\EmailBundle\Provider\EmailRenderer;
use Oro\Bundle\FormBundle\Form\Type\OroRichTextType;
use Oro\Bundle\FormBundle\Utils\FormUtils;
use Oro\Bundle\SecurityBundle\Authentication\Token\UsernamePasswordOrganizationToken;

class EmailType extends AbstractType
Expand All @@ -31,23 +33,31 @@ class EmailType extends AbstractType
/** @var EmailModelBuilderHelper */
protected $emailModelBuilderHelper;

/** @var ConfigManager */
protected $configManager;

/**
* @param SecurityContextInterface $securityContext
* @param EmailRenderer $emailRenderer
* @param EmailModelBuilderHelper $emailModelBuilderHelper
* @param ConfigManager $configManager
*/
public function __construct(
SecurityContextInterface $securityContext,
EmailRenderer $emailRenderer,
EmailModelBuilderHelper $emailModelBuilderHelper
EmailModelBuilderHelper $emailModelBuilderHelper,
ConfigManager $configManager
) {
$this->securityContext = $securityContext;
$this->emailRenderer = $emailRenderer;
$this->emailModelBuilderHelper = $emailModelBuilderHelper;
$this->configManager = $configManager;
}

/**
* {@inheritdoc}
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
Expand Down Expand Up @@ -83,7 +93,15 @@ public function buildForm(FormBuilderInterface $builder, array $options)
['required' => false, 'attr' => ['class' => 'taggable-field']]
)
->add('subject', 'text', ['required' => true, 'label' => 'oro.email.subject.label'])
->add('body', 'oro_resizeable_rich_text', ['required' => false, 'label' => 'oro.email.email_body.label'])
->add(
'body',
'oro_resizeable_rich_text',
[
'required' => false,
'label' => 'oro.email.email_body.label',
'wysiwyg_options' => $this->getWysiwygOptions(),
]
)
->add(
'template',
'oro_email_template_list',
Expand Down Expand Up @@ -244,4 +262,19 @@ public function getBlockPrefix()
{
return 'oro_email_email';
}

/**
* @return array
*/
protected function getWysiwygOptions()
{
if ($this->configManager->get('oro_email.sanitize_html')) {
return [];
}

return [
'valid_elements' => null, //all elements are valid
'plugins' => array_merge(OroRichTextType::$defaultPlugins, ['fullpage']),
];
}
}
3 changes: 1 addition & 2 deletions src/Oro/Bundle/EmailBundle/Resources/config/form.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ services:

oro_email.form.type.emailtemplate_rich_text:
class: Oro\Bundle\EmailBundle\Form\Type\EmailTemplateRichTextType
arguments:
- %kernel.cache_dir%
tags:
- { name: form.type, alias: oro_email_template_rich_text }

Expand Down Expand Up @@ -151,6 +149,7 @@ services:
- '@security.context'
- '@oro_email.email_renderer'
- '@oro_email.email.model.builder.helper'
- '@oro_config.user'
tags:
- { name: form.type, alias: oro_email_email }

Expand Down
8 changes: 3 additions & 5 deletions src/Oro/Bundle/EmailBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ services:
- '@kernel'
tags:
- { name: kernel.cache_warmer, priority: 30 }
- { name: oro_entity_extend.warmer }

oro_email.entity.cache.clearer:
class: %oro_email.entity.cache.clearer.class%
deprecated: ~
arguments:
- %oro_email.entity.cache_dir%
- %oro_email.entity.proxy_name_template%
tags:
- { name: kernel.cache_clearer }

oro_email.email.cache.manager:
class: %oro_email.email.cache.manager.class%
Expand All @@ -184,9 +184,7 @@ services:
class: %oro_email.email_flag_manager_loader_selector.class%

oro_email.email_address.entity_manager:
public: false
class: Doctrine\ORM\EntityManager
factory: ['@doctrine', getManagerForClass]
parent: oro_entity.abstract_entity_manager
arguments:
- 'OroEmailBundle:EmailAddress'

Expand Down
Loading

0 comments on commit 40447e9

Please sign in to comment.