Skip to content

Commit 4f294eb

Browse files
author
Ievgen Shakhsuvarov
committed
Merge branch 'develop' of https://github.corp.ebay.com/magento2/magento2ce into MAGETWO-26655-TD
2 parents a6825fa + 7581dd6 commit 4f294eb

File tree

30 files changed

+200
-77
lines changed

30 files changed

+200
-77
lines changed

app/code/Magento/Checkout/Model/Type/Onepage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ protected function _validateCustomerData(array $data)
530530
$quote = $this->getQuote();
531531
$isCustomerNew = !$quote->getCustomerId();
532532
$customer = $quote->getCustomer();
533-
$customerData = $this->extensibleDataObjectConverter->toFlatArray($customer);
533+
$customerData = $this->extensibleDataObjectConverter->toFlatArray($customer, [], '\Magento\Customer\Api\Data\CustomerInterface');
534534

535535
/** @var Form $customerForm */
536536
$customerForm = $this->_formFactory->create(
@@ -594,7 +594,7 @@ protected function _validateCustomerData(array $data)
594594
$this->_objectCopyService->copyFieldsetToTarget(
595595
'customer_account',
596596
'to_quote',
597-
$this->extensibleDataObjectConverter->toFlatArray($customer),
597+
$this->extensibleDataObjectConverter->toFlatArray($customer, [], '\Magento\Customer\Api\Data\CustomerInterface'),
598598
$quote
599599
);
600600

app/code/Magento/Customer/Block/Adminhtml/Edit/Form.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ protected function _prepareForm()
7272
$form->addField('id', 'hidden', ['name' => 'customer_id']);
7373
$customer = $this->_customerRepository->getById($customerId);
7474
$form->setValues(
75-
$this->_extensibleDataObjectConverter->toFlatArray($customer)
75+
$this->_extensibleDataObjectConverter->toFlatArray(
76+
$customer,
77+
[],
78+
'\Magento\Customer\Api\Data\CustomerInterface'
79+
)
7680
)->addValues(
7781
['customer_id' => $customerId]
7882
);

app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/Account.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,11 @@ protected function _customizeFieldset($fieldset)
172172
);
173173
$form->getElement('website_id')->setRenderer($renderer);
174174

175-
$accountData = $this->_extensibleDataObjectConverter->toFlatArray($this->_getCustomerDataObject());
175+
$accountData = $this->_extensibleDataObjectConverter->toFlatArray(
176+
$this->_getCustomerDataObject(),
177+
[],
178+
'\Magento\Customer\Api\Data\CustomerInterface'
179+
);
176180

177181
if ($this->_getCustomerDataObject()->getId()) {
178182
$customerFormFields = $this->_addEditCustomerFormFields($fieldset);

app/code/Magento/Customer/Controller/Adminhtml/Index/Validate.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ protected function _validateCustomer($response)
2929
$customerForm = $this->_formFactory->create(
3030
'customer',
3131
'adminhtml_customer',
32-
$this->_extensibleDataObjectConverter->toFlatArray($customer),
32+
$this->_extensibleDataObjectConverter->toFlatArray(
33+
$customer,
34+
[],
35+
'\Magento\Customer\Api\Data\CustomerInterface'
36+
),
3337
true
3438
);
3539
$customerForm->setInvisibleIgnored(true);

app/code/Magento/Customer/Model/AccountManagement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ protected function createPasswordHash($password)
683683
public function validate(\Magento\Customer\Api\Data\CustomerInterface $customer)
684684
{
685685
$customerErrors = $this->validator->validateData(
686-
$this->extensibleDataObjectConverter->toFlatArray($customer),
686+
$this->extensibleDataObjectConverter->toFlatArray($customer, [], '\Magento\Customer\Api\Data\CustomerInterface'),
687687
[],
688688
'customer'
689689
);

app/code/Magento/Customer/Model/Address/Mapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(ExtensibleDataObjectConverter $extensibleDataObjectC
3737
*/
3838
public function toFlatArray($addressDataObject)
3939
{
40-
$flatAddressArray = $this->extensibleDataObjectConverter->toFlatArray($addressDataObject);
40+
$flatAddressArray = $this->extensibleDataObjectConverter->toFlatArray($addressDataObject, [], '\Magento\Customer\Api\Data\AddressInterface');
4141
//preserve street
4242
$street = $addressDataObject->getStreet();
4343
if (!empty($street) && is_array($street)) {

app/code/Magento/Customer/Model/Customer/Mapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(ExtensibleDataObjectConverter $extensibleDataObjectC
3636
*/
3737
public function toFlatArray(CustomerInterface $customer)
3838
{
39-
$flatArray = $this->extensibleDataObjectConverter->toNestedArray($customer);
39+
$flatArray = $this->extensibleDataObjectConverter->toNestedArray($customer, [], '\Magento\Customer\Api\Data\CustomerInterface');
4040
unset($flatArray["addresses"]);
4141
return ConvertArray::toFlatArray($flatArray);
4242
}

app/code/Magento/Customer/Model/Resource/CustomerRepository.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ public function save(\Magento\Customer\Api\Data\CustomerInterface $customer, $pa
125125
{
126126
$this->validate($customer);
127127
$customerData = $this->extensibleDataObjectConverter->toFlatArray(
128-
$this->customerBuilder->populate($customer)->setAddresses([])->create()
128+
$this->customerBuilder->populate($customer)->setAddresses([])->create(),
129+
[],
130+
'\Magento\Customer\Api\Data\CustomerInterface'
129131
);
130132
$customerModel = $this->customerFactory->create(['data' => $customerData]);
131133
$storeId = $customerModel->getStoreId();

app/code/Magento/Customer/Model/Resource/Group/Grid/ServiceCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function loadData($printQuery = false, $logQuery = false)
6767
$groups = $searchResults->getItems();
6868
foreach ($groups as $group) {
6969
$groupItem = new \Magento\Framework\Object();
70-
$groupItem->addData($this->simpleDataObjectConverter->toFlatArray($group));
70+
$groupItem->addData($this->simpleDataObjectConverter->toFlatArray($group, '\Magento\Customer\Api\Data\GroupInterface'));
7171
$this->_addItem($groupItem);
7272
}
7373
$this->_setIsLoaded();

app/code/Magento/Integration/Model/Oauth/Consumer.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,17 @@ class Consumer extends \Magento\Framework\Model\AbstractModel implements Consume
3838
*/
3939
protected $_keyLengthFactory;
4040

41+
/**
42+
* @var \Magento\Integration\Helper\Oauth\Data
43+
*/
44+
protected $dataHelper;
45+
4146
/**
4247
* @param \Magento\Framework\Model\Context $context
4348
* @param \Magento\Framework\Registry $registry
4449
* @param \Magento\Integration\Model\Oauth\Consumer\Validator\KeyLengthFactory $keyLengthFactory
4550
* @param \Magento\Framework\Url\Validator $urlValidator
51+
* @param \Magento\Integration\Helper\Oauth\Data $dataHelper
4652
* @param \Magento\Framework\Model\Resource\AbstractResource $resource
4753
* @param \Magento\Framework\Data\Collection\Db $resourceCollection
4854
* @param array $data
@@ -52,12 +58,14 @@ public function __construct(
5258
\Magento\Framework\Registry $registry,
5359
\Magento\Integration\Model\Oauth\Consumer\Validator\KeyLengthFactory $keyLengthFactory,
5460
\Magento\Framework\Url\Validator $urlValidator,
61+
\Magento\Integration\Helper\Oauth\Data $dataHelper,
5562
\Magento\Framework\Model\Resource\AbstractResource $resource = null,
5663
\Magento\Framework\Data\Collection\Db $resourceCollection = null,
5764
array $data = []
5865
) {
5966
$this->_keyLengthFactory = $keyLengthFactory;
6067
$this->_urlValidator = $urlValidator;
68+
$this->dataHelper = $dataHelper;
6169
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
6270
}
6371

@@ -166,4 +174,13 @@ public function getCreatedAt()
166174
{
167175
return $this->getData('created_at');
168176
}
177+
178+
/**
179+
* {@inheritdoc}
180+
*/
181+
public function isValidForTokenExchange()
182+
{
183+
$expiry = $this->dataHelper->getConsumerExpirationPeriod();
184+
return $expiry > $this->getResource()->getTimeInSecondsSinceCreation($this->getId());
185+
}
169186
}

app/code/Magento/Integration/Model/Oauth/Token/Provider.php

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,16 @@ class Provider implements TokenProviderInterface
2222
*/
2323
protected $_tokenFactory;
2424

25-
/**
26-
* @var \Magento\Integration\Helper\Oauth\Data
27-
*/
28-
protected $_dataHelper;
29-
30-
/**
31-
* @var \Magento\Framework\Stdlib\DateTime\DateTime
32-
*/
33-
protected $_date;
34-
3525
/**
3626
* @param \Magento\Integration\Model\Oauth\Consumer\Factory $consumerFactory
3727
* @param \Magento\Integration\Model\Oauth\TokenFactory $tokenFactory
38-
* @param \Magento\Integration\Helper\Oauth\Data $dataHelper
39-
* @param \Magento\Framework\Stdlib\DateTime\DateTime $date
4028
*/
4129
public function __construct(
4230
\Magento\Integration\Model\Oauth\Consumer\Factory $consumerFactory,
43-
\Magento\Integration\Model\Oauth\TokenFactory $tokenFactory,
44-
\Magento\Integration\Helper\Oauth\Data $dataHelper,
45-
\Magento\Framework\Stdlib\DateTime\DateTime $date
31+
\Magento\Integration\Model\Oauth\TokenFactory $tokenFactory
4632
) {
4733
$this->_consumerFactory = $consumerFactory;
4834
$this->_tokenFactory = $tokenFactory;
49-
$this->_dataHelper = $dataHelper;
50-
$this->_date = $date;
5135
}
5236

5337
/**
@@ -56,9 +40,7 @@ public function __construct(
5640
public function validateConsumer($consumer)
5741
{
5842
// Must use consumer within expiration period.
59-
$consumerTS = strtotime($consumer->getCreatedAt());
60-
$expiry = $this->_dataHelper->getConsumerExpirationPeriod();
61-
if ($this->_date->timestamp() - $consumerTS > $expiry) {
43+
if (!$consumer->isValidForTokenExchange()) {
6244
throw new \Magento\Framework\Oauth\Exception(
6345
'Consumer key has expired'
6446
);

app/code/Magento/Integration/Model/Resource/Oauth/Consumer.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,22 @@ public function _afterDelete(\Magento\Framework\Model\AbstractModel $object)
5757
$adapter->delete($this->getTable('oauth_token'), ['consumer_id' => $object->getId()]);
5858
return parent::_afterDelete($object);
5959
}
60+
61+
/**
62+
* Compute time in seconds since consumer was created.
63+
*
64+
* @param int $consumerId - The consumer id
65+
* @return int - time lapsed in seconds
66+
*/
67+
public function getTimeInSecondsSinceCreation($consumerId)
68+
{
69+
$adapter = $this->_getReadAdapter();
70+
$select = $adapter->select()
71+
->from($this->getMainTable())
72+
->reset(\Zend_Db_Select::COLUMNS)
73+
->columns('CURRENT_TIMESTAMP() - created_at')
74+
->where('entity_id = ?', $consumerId);
75+
76+
return $adapter->fetchOne($select);
77+
}
6078
}

app/code/Magento/Integration/etc/adminhtml/system.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<label>Consumer Settings</label>
2727
<field id="expiration_period" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="0" showInStore="0">
2828
<label>Expiration Period</label>
29-
<comment>Disable consumer key/secret credentials if not used within X seconds.</comment>
29+
<comment>Consumer key/secret will expire if not used within X seconds after Oauth token exchange starts.</comment>
3030
</field>
3131
<field id="post_maxredirects" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="0" showInStore="0">
3232
<label>OAuth consumer credentials HTTP Post maxredirects</label>

app/code/Magento/Sales/Block/Adminhtml/Order/Create/Form/Account.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public function getFormValues()
161161
} catch (\Exception $e) {
162162
/** If customer does not exist do nothing. */
163163
}
164-
$data = isset($customer) ? $this->_extensibleDataObjectConverter->toFlatArray($customer) : [];
164+
$data = isset($customer) ? $this->_extensibleDataObjectConverter->toFlatArray($customer, [], '\Magento\Customer\Api\Data\CustomerInterface') : [];
165165
foreach ($this->getQuote()->getData() as $key => $value) {
166166
if (strpos($key, 'customer_') === 0) {
167167
$data[substr($key, 9)] = $value;

app/code/Magento/Sales/Model/Quote.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,9 @@ public function setCustomer(\Magento\Customer\Api\Data\CustomerInterface $custom
684684
$this->setCustomerId($customer->getId());
685685
$customerData = $this->objectFactory->create(
686686
$this->extensibleDataObjectConverter->toFlatArray(
687-
$this->customerBuilder->populate($customer)->setAddresses([])->create()
687+
$this->customerBuilder->populate($customer)->setAddresses([])->create(),
688+
[],
689+
'\Magento\Customer\Api\Data\CustomerInterface'
688690
)
689691
);
690692
$this->_objectCopyService->copyFieldsetToTarget('customer_account', 'to_quote', $customerData, $this);

dev/tests/api-functional/testsuite/Magento/Webapi/Authentication/RestTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public function testGetAccessTokenConsumerMismatch()
176176

177177
/**
178178
* @expectedException \Exception
179-
* @expectedExceptionMessage HTTP/1.1 401
179+
* @expectedExceptionMessage HTTP/1.1 400
180180
*/
181181
public function testAccessApiInvalidAccessToken()
182182
{

dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/GroupTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ public function testSaveActionExistingGroup()
146146
$simpleDataObjectConverter = Bootstrap::getObjectManager()
147147
->get('Magento\Framework\Api\SimpleDataObjectConverter');
148148
$customerGroupData = $simpleDataObjectConverter->toFlatArray(
149-
$this->groupRepository->getById($groupId)
149+
$this->groupRepository->getById($groupId),
150+
'Magento\Customer\Api\Data\GroupInterface'
150151
);
151152
ksort($customerGroupData);
152153

dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagementTest.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,8 +599,16 @@ public function testCreateNonexistingCustomer()
599599
'aPassword',
600600
true
601601
);
602-
$attributesBefore = $this->extensibleDataObjectConverter->toFlatArray($existingCustomer);
603-
$attributesAfter = $this->extensibleDataObjectConverter->toFlatArray($customerAfter);
602+
$attributesBefore = $this->extensibleDataObjectConverter->toFlatArray(
603+
$existingCustomer,
604+
[],
605+
'\Magento\Customer\Api\Data\CustomerInterface'
606+
);
607+
$attributesAfter = $this->extensibleDataObjectConverter->toFlatArray(
608+
$customerAfter,
609+
[],
610+
'\Magento\Customer\Api\Data\CustomerInterface'
611+
);
604612
// ignore 'updated_at'
605613
unset($attributesBefore['updated_at']);
606614
unset($attributesAfter['updated_at']);
@@ -670,7 +678,10 @@ public function testCreateCustomerInServiceVsInModel()
670678
$simpleDataObjectConverter = Bootstrap::getObjectManager()
671679
->get('Magento\Framework\Api\SimpleDataObjectConverter');
672680

673-
$dataInService = $simpleDataObjectConverter->toFlatArray($savedCustomer);
681+
$dataInService = $simpleDataObjectConverter->toFlatArray(
682+
$savedCustomer,
683+
'Magento\Customer\Api\Data\CustomerInterface'
684+
);
674685
$expectedDifferences = [
675686
'created_at',
676687
'updated_at',

dev/tests/integration/testsuite/Magento/Customer/Model/CustomerMetadataTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function testGetCustomerAttributeMetadata()
120120
'id' => 1,
121121
'website_id' => 1,
122122
'store_id' => 1,
123-
'group_id' => '1',
123+
'group_id' => 1,
124124
'firstname' => 'John',
125125
'lastname' => 'Smith',
126126
'email' => '[email protected]',
@@ -132,7 +132,11 @@ public function testGetCustomerAttributeMetadata()
132132
$customer = $this->customerRepository->getById(1);
133133
$this->assertNotNull($customer);
134134

135-
$attributes = $this->_extensibleDataObjectConverter->toFlatArray($customer);
135+
$attributes = $this->_extensibleDataObjectConverter->toFlatArray(
136+
$customer,
137+
[],
138+
'\Magento\Customer\Api\Data\CustomerInterface'
139+
);
136140
$this->assertNotEmpty($attributes);
137141

138142
foreach ($attributes as $attributeCode => $attributeValue) {

dev/tests/integration/testsuite/Magento/Customer/Model/Resource/CustomerRepositoryTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,16 @@ public function testUpdateCustomer()
141141
$this->assertEquals('Admin', $customerAfter->getCreatedIn());
142142
$passwordFromFixture = 'password';
143143
$this->accountManagement->authenticate($customerAfter->getEmail(), $passwordFromFixture);
144-
$attributesBefore = $this->converter->toFlatArray($customerBefore);
145-
$attributesAfter = $this->converter->toFlatArray($customerAfter);
144+
$attributesBefore = $this->converter->toFlatArray(
145+
$customerBefore,
146+
[],
147+
'\Magento\Customer\Api\Data\CustomerInterface'
148+
);
149+
$attributesAfter = $this->converter->toFlatArray(
150+
$customerAfter,
151+
[],
152+
'\Magento\Customer\Api\Data\CustomerInterface'
153+
);
146154
// ignore 'updated_at'
147155
unset($attributesBefore['updated_at']);
148156
unset($attributesAfter['updated_at']);

dev/tests/integration/testsuite/Magento/Weee/Model/TaxTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function testGetProductWeeeAttributes()
5858
['metadataService' => $customerMetadataService]
5959
);
6060
$expected = $this->_extensibleDataObjectConverter->toFlatArray(
61-
$customerRepository->getById(1)
61+
$customerRepository->getById(1), [], '\Magento\Customer\Api\Data\CustomerInterface'
6262
);
6363
$customerBuilder->populateWithArray($expected);
6464
$customerDataSet = $customerBuilder->create();

dev/tests/unit/testsuite/Magento/Customer/Block/Adminhtml/Edit/Tab/AccountTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ private function _setupStoreMode($customerData, $isSingleStoreMode, $canModifyCu
187187
'adminhtml_customer',
188188
$this->extensibleDataObjectConverterMock->toFlatArray(
189189
$customerObject,
190+
[],
190191
'\Magento\Customer\Api\Data\CustomerInterface'
191192
)
192193
)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\Oauth;
7+
8+
class OauthInputExceptionTest extends \PHPUnit_Framework_TestCase
9+
{
10+
public function testGetAggregatedErrorMessage()
11+
{
12+
$exception = new OauthInputException();
13+
foreach (['field1', 'field2'] as $param) {
14+
$exception->addError(OauthInputException::REQUIRED_FIELD, ['fieldName' => $param]);
15+
}
16+
$exception->addError('Message with period.');
17+
18+
$this->assertEquals(
19+
'field1 is a required field, field2 is a required field, Message with period',
20+
$exception->getAggregatedErrorMessage()
21+
);
22+
}
23+
24+
public function testGetAggregatedErrorMessageNoError()
25+
{
26+
$exception = new OauthInputException();
27+
$this->assertEquals('', $exception->getAggregatedErrorMessage());
28+
}
29+
}

0 commit comments

Comments
 (0)