Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/master' into 1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrebenchuk committed Feb 15, 2016
2 parents 6e45c54 + 6fb8643 commit 2133258
Show file tree
Hide file tree
Showing 87 changed files with 1,063 additions and 512 deletions.
2 changes: 1 addition & 1 deletion src/Oro/Bundle/ActivityListBundle/Entity/ActivityList.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public function getSubject()
*/
public function setSubject($subject)
{
$this->subject = $subject;
$this->subject = substr($subject, 0, 255);

return $this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,6 @@
}
.accordion-body {
padding: 0;
.control-group{
max-width: none;
}
> .message {
.user-fieldset {
margin-top: 5px;
Expand Down
3 changes: 3 additions & 0 deletions src/Oro/Bundle/AddressBundle/Form/Type/AddressType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Validator\Constraint;

use Oro\Bundle\AddressBundle\Form\EventListener\AddressCountryAndRegionSubscriber;

class AddressType extends AbstractType
{
const ABSTRACT_ADDRESS_GROUP = 'AbstractAddress';
/**
* @var AddressCountryAndRegionSubscriber
*/
Expand Down Expand Up @@ -65,6 +67,7 @@ public function configureOptions(OptionsResolver $resolver)
'extra_fields_message' => 'This form should not contain extra fields: "{{ extra_fields }}"',
'single_form' => true,
'region_route' => 'oro_api_country_get_regions',
'validation_groups' => [Constraint::DEFAULT_GROUP, self::ABSTRACT_ADDRESS_GROUP],
)
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Oro/Bundle/AddressBundle/Resources/config/validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Oro\Bundle\AddressBundle\Entity\AbstractAddress:
max: 255

country:
- NotBlank: ~
- NotBlank:
groups: [AbstractAddress]

regionText:
- Length:
Expand Down
1 change: 0 additions & 1 deletion src/Oro/Bundle/ApiBundle/Command/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Oro\Component\ChainProcessor\ChainApplicableChecker;
use Oro\Component\ChainProcessor\Context;
use Oro\Component\ChainProcessor\ProcessorBagInterface;
use Oro\Bundle\ApiBundle\Request\RequestType;

class DebugCommand extends ContainerAwareCommand
{
Expand Down
9 changes: 6 additions & 3 deletions src/Oro/Bundle/ApiBundle/Command/DumpConfigCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
use Symfony\Component\Yaml\Yaml;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;

use Oro\Component\ChainProcessor\ProcessorBag;
use Oro\Bundle\ApiBundle\Config\DescriptionsConfigExtra;
use Oro\Bundle\ApiBundle\Config\FiltersConfigExtra;
use Oro\Bundle\ApiBundle\Config\SortersConfigExtra;
use Oro\Bundle\ApiBundle\Provider\ConfigProvider;
use Oro\Bundle\ApiBundle\Provider\RelationConfigProvider;
use Oro\Bundle\ApiBundle\Request\RequestType;
use Oro\Bundle\ApiBundle\Request\Version;
use Oro\Bundle\EntityBundle\Tools\EntityClassNameHelper;

Expand Down Expand Up @@ -44,8 +44,7 @@ protected function configure()
'request-type',
null,
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
'API request type',
[RequestType::REST, RequestType::JSON_API]
'API request type'
)
->addOption(
'section',
Expand Down Expand Up @@ -81,6 +80,10 @@ public function execute(InputInterface $input, OutputInterface $output)
$extras[] = new DescriptionsConfigExtra();
}

/** @var ProcessorBag $processorBag */
$processorBag = $this->getContainer()->get('oro_api.processor_bag');
$processorBag->addApplicableChecker(new RequestTypeApplicableChecker());

switch ($input->getOption('section')) {
case 'entities':
$config = $this->getConfig($entityClass, $version, $requestType, $extras);
Expand Down
9 changes: 6 additions & 3 deletions src/Oro/Bundle/ApiBundle/Command/DumpMetadataCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
use Symfony\Component\Yaml\Yaml;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;

use Oro\Component\ChainProcessor\ProcessorBag;
use Oro\Bundle\ApiBundle\Provider\ConfigProvider;
use Oro\Bundle\ApiBundle\Provider\MetadataProvider;
use Oro\Bundle\ApiBundle\Request\RequestType;
use Oro\Bundle\ApiBundle\Request\Version;
use Oro\Bundle\ApiBundle\Util\ConfigUtil;
use Oro\Bundle\EntityBundle\Tools\EntityClassNameHelper;
Expand Down Expand Up @@ -42,8 +42,7 @@ protected function configure()
'request-type',
null,
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
'API request type',
[RequestType::REST, RequestType::JSON_API]
'API request type'
);
}

Expand All @@ -61,6 +60,10 @@ public function execute(InputInterface $input, OutputInterface $output)
//$version = $input->getArgument('version');
$version = Version::LATEST;

/** @var ProcessorBag $processorBag */
$processorBag = $this->getContainer()->get('oro_api.processor_bag');
$processorBag->addApplicableChecker(new RequestTypeApplicableChecker());

$metadata = $this->getMetadata($entityClass, $version, $requestType);
$output->write(Yaml::dump($metadata, 100, 4, true, true));
}
Expand Down
12 changes: 8 additions & 4 deletions src/Oro/Bundle/ApiBundle/Provider/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(ConfigProcessor $processor)
*
* @return array|null
*/
public function getConfig($className, $version, array $requestType, array $extras = [])
public function getConfig($className, $version, array $requestType = [], array $extras = [])
{
if (empty($className)) {
throw new \InvalidArgumentException('$className must not be empty.');
Expand All @@ -46,10 +46,14 @@ public function getConfig($className, $version, array $requestType, array $extra

/** @var ConfigContext $context */
$context = $this->processor->createContext();
$context->setVersion($version);
$context->setRequestType($requestType);
$context->setExtras($extras);
$context->setClassName($className);
$context->setVersion($version);
if (!empty($requestType)) {
$context->setRequestType($requestType);
}
if (!empty($extras)) {
$context->setExtras($extras);
}

$this->processor->process($context);

Expand Down
12 changes: 8 additions & 4 deletions src/Oro/Bundle/ApiBundle/Provider/FieldConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(FieldConfigProcessor $processor)
*
* @return array|null
*/
public function getFieldConfig($className, $fieldName, $version, array $requestType, array $extras = [])
public function getFieldConfig($className, $fieldName, $version, array $requestType = [], array $extras = [])
{
if (empty($className)) {
throw new \InvalidArgumentException('$className must not be empty.');
Expand All @@ -50,11 +50,15 @@ public function getFieldConfig($className, $fieldName, $version, array $requestT

/** @var FieldConfigContext $context */
$context = $this->processor->createContext();
$context->setVersion($version);
$context->setRequestType($requestType);
$context->setExtras($extras);
$context->setClassName($className);
$context->setFieldName($fieldName);
$context->setVersion($version);
if (!empty($requestType)) {
$context->setRequestType($requestType);
}
if (!empty($extras)) {
$context->setExtras($extras);
}

$this->processor->process($context);

Expand Down
12 changes: 8 additions & 4 deletions src/Oro/Bundle/ApiBundle/Provider/MetadataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,22 @@ public function __construct(MetadataProcessor $processor)
*
* @return EntityMetadata|null
*/
public function getMetadata($className, $version, array $requestType, array $extras = [], $config = null)
public function getMetadata($className, $version, array $requestType = [], array $extras = [], $config = null)
{
if (empty($className)) {
throw new \InvalidArgumentException('$className must not be empty.');
}

/** @var MetadataContext $context */
$context = $this->processor->createContext();
$context->setVersion($version);
$context->setRequestType($requestType);
$context->setClassName($className);
$context->setExtras($extras);
$context->setVersion($version);
if (!empty($requestType)) {
$context->setRequestType($requestType);
}
if (!empty($extras)) {
$context->setExtras($extras);
}
if (!empty($config)) {
$context->setConfig($config);
}
Expand Down
12 changes: 8 additions & 4 deletions src/Oro/Bundle/ApiBundle/Provider/RelationConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(RelationConfigProcessor $processor)
*
* @return array|null
*/
public function getRelationConfig($className, $version, array $requestType, array $extras = [])
public function getRelationConfig($className, $version, array $requestType = [], array $extras = [])
{
if (empty($className)) {
throw new \InvalidArgumentException('$className must not be empty.');
Expand All @@ -46,10 +46,14 @@ public function getRelationConfig($className, $version, array $requestType, arra

/** @var RelationConfigContext $context */
$context = $this->processor->createContext();
$context->setVersion($version);
$context->setRequestType($requestType);
$context->setExtras($extras);
$context->setClassName($className);
$context->setVersion($version);
if (!empty($requestType)) {
$context->setRequestType($requestType);
}
if (!empty($extras)) {
$context->setExtras($extras);
}

$this->processor->process($context);

Expand Down
17 changes: 16 additions & 1 deletion src/Oro/Bundle/ApiBundle/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
#OroApiBundle
OroApiBundle
============

The goal of this bundle is to make a creation of different kinds of APIs as easy as possible.

The main idea of this bundle is to provide some default implementation of API which can be reused and easily changed for any entity if required.

To achieve this, this bundle is implemented based on two ORO components: [ChainProcessor](../../Component/ChainProcessor/) and [EntitySerializer](../../Component/EntitySerializer/). The ChainProcessor component is responsible to organize data processing flow. The EntitySerializer component provides the fast access to entities data.

**Notes**:
- For now only GET requests for REST and JSON.API are implemented.
- This documentation is not full and it will be completed soon.

Table of Contents
-----------------
- [Configuration](./Resources/doc/configuration.md)
- [Debug commands](./Resources/doc/debug_commands.md)
10 changes: 10 additions & 0 deletions src/Oro/Bundle/ApiBundle/Resources/doc/configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Configuration
-------------

By default API for all entities, except custom entities, dictionaries and enumerations are disabled. To enable API for any entity you can use `Resources/config/oro/api.yml` file. For example, to make `Acme\Bundle\ProductBundle\Product` entity accessible through API you can write the following configuration:

```yaml
oro_api:
entities:
Acme\Bundle\ProductBundle\Product: ~
```
92 changes: 92 additions & 0 deletions src/Oro/Bundle/ApiBundle/Resources/doc/debug_commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
Debug commands
--------------

### oro:api:debug
This command shows details about registered API actions and processors.

If you want to know all actions run this command without parameters:

```bash
php app/console oro:api:debug
```

If you want to know which processors are registered for a particular action run this command with the action name as an argument:

```bash
php app/console oro:api:debug get_list
```

The `request-type` option can be used to see the processors which will be executed for a particular request type:

```bash
php app/console oro:api:debug get_list --request-type=rest --request-type=json_api
```

### oro:api:resources:dump
This command shows all API resources.

Run this command without parameters to see all available API resources:

```bash
php app/console oro:api:resources:dump
```

or specify the `request-type` option if you need to know API resources for a particular request type:

```bash
php app/console oro:api:resources:dump --request-type=rest --request-type=json_api
```

### oro:api:config:dump
This command shows API configuration for a particular entity.

Run this command and specify entity class or entity alias as an argument:

```bash
php app/console oro:api:config:dump "Oro\Bundle\UserBundle\Entity\User"
```

or

```bash
php app/console oro:api:config:dump users
```

To see API configuration for a particular request type you can use the `request-type` option:

```bash
php app/console oro:api:config:dump users --request-type=rest --request-type=json_api
```

If you want to see human-readable representation of an entity and its fields, you can use the `with-descriptions` option:

```bash
php app/console oro:api:config:dump users --with-descriptions
```

The `section` option can be used to see a configuration of an entity when it is referenced by another entity:

```bash
php app/console oro:api:config:dump addresses --section=relations
```

### oro:api:metadata:dump
This command shows metadata for a particular entity.

To see metadata run this command and specify entity class or entity alias as an argument:

```bash
php app/console oro:api:metadata:dump "Oro\Bundle\UserBundle\Entity\User"
```

or

```bash
php app/console oro:api:metadata:dump users
```

If you want to see entity metadata that is used for a particular request type you can use the `request-type` option:

```bash
php app/console oro:api:metadata:dump users --request-type=rest --request-type=json_api
```
2 changes: 1 addition & 1 deletion src/Oro/Bundle/ConfigBundle/Config/UserScopeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function setScopeId($scopeId)
*/
protected function ensureScopeIdInitialized()
{
if (!$this->scopeId) {
if (null === $this->scopeId) {
$scopeId = 0;

$token = $this->securityContext->getToken();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public function systemAction($activeGroup = null, $activeSubGroup = null)
$sender = $this->get('oro_navigation.content.topic_sender');

$sender->send($sender->getGenerator()->generate($taggableData));

// recreate form to drop values for fields with use_parent_scope_value
$form = $provider->getForm($activeSubGroup);
$form->setData($this->get('oro_config.manager')->getSettingsByForm($form));
}
}

Expand Down
Loading

0 comments on commit 2133258

Please sign in to comment.