Skip to content

Commit 8e2d385

Browse files
authored
Merge pull request #6088 from magento-tango/TANGO-PR-09-01-2020_24
TANGO PR 09-01-2020 v2.4
2 parents b87f1df + 0a3cd60 commit 8e2d385

File tree

21 files changed

+723
-102
lines changed

21 files changed

+723
-102
lines changed

app/code/Magento/Catalog/etc/db_schema.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@
154154
default="0" comment="Store ID"/>
155155
<column xsi:type="int" name="entity_id" unsigned="true" nullable="false" identity="false"
156156
default="0" comment="Entity ID"/>
157-
<column xsi:type="text" name="value" nullable="true" comment="Value"/>
157+
<column xsi:type="mediumtext" name="value" nullable="true" comment="Value"/>
158158
<constraint xsi:type="primary" referenceId="PRIMARY">
159159
<column name="value_id"/>
160160
</constraint>
@@ -408,7 +408,7 @@
408408
default="0" comment="Store ID"/>
409409
<column xsi:type="int" name="entity_id" unsigned="true" nullable="false" identity="false"
410410
default="0" comment="Entity ID"/>
411-
<column xsi:type="text" name="value" nullable="true" comment="Value"/>
411+
<column xsi:type="mediumtext" name="value" nullable="true" comment="Value"/>
412412
<constraint xsi:type="primary" referenceId="PRIMARY">
413413
<column name="value_id"/>
414414
</constraint>

app/code/Magento/Checkout/Test/Mftf/Section/CheckoutPaymentSection.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
<element name="billingNewAddressForm" type="text" selector="[data-form='billing-new-address']"/>
1616
<element name="billingAddressNotSameCheckbox" type="checkbox" selector="#billing-address-same-as-shipping-checkmo"/>
1717
<element name="editAddress" type="button" selector="button.action.action-edit-address"/>
18+
<element name="addressDropdown" type="select" selector="[name=billing_address_id]"/>
19+
<element name="addressDropdownSelected" type="select" selector="[name=billing_address_id] option:checked"/>
1820
<element name="placeOrderDisabled" type="button" selector="#checkout-payment-method-load button.disabled"/>
1921
<element name="update" type="button" selector=".payment-method._active .payment-method-billing-address .action.action-update"/>
2022
<element name="guestFirstName" type="input" selector=".payment-method._active .billing-address-form input[name='firstname']"/>

app/code/Magento/Checkout/Test/Mftf/Test/OnePageCheckoutAsCustomerUsingNonDefaultAddressTest.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
</createData>
2727

2828
<!-- Create customer -->
29-
<createData entity="Customer_US_UK_DE" stepKey="createCustomer"/>
29+
<createData entity="Customer_DE_UK_US" stepKey="createCustomer"/>
3030
</before>
3131
<after>
3232
<!-- Admin log out -->
@@ -70,7 +70,8 @@
7070

7171
<!-- Change the address -->
7272
<click selector="{{CheckoutPaymentSection.editAddress}}" stepKey="editAddress"/>
73-
<waitForElementVisible selector="{{CheckoutShippingSection.addressDropdown}}" stepKey="waitForDropDownToBeVisible"/>
73+
<waitForElementVisible selector="{{CheckoutPaymentSection.addressDropdown}}" stepKey="waitForDropDownToBeVisible"/>
74+
<see selector="{{CheckoutPaymentSection.addressDropdownSelected}}" userInput="{{US_Address_NY.street[0]}}" stepKey="seeDefaultBillingAddressStreet"/>
7475
<selectOption selector="{{CheckoutShippingSection.addressDropdown}}" userInput="{{UK_Not_Default_Address.street[0]}}" stepKey="addAddress"/>
7576

7677
<!-- Check order summary in checkout -->

app/code/Magento/Checkout/view/frontend/web/js/view/billing-address/list.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ define([
2323
},
2424
addressOptions = addressList().filter(function (address) {
2525
return address.getType() === 'customer-address';
26+
}),
27+
addressDefaultIndex = addressOptions.findIndex(function (address) {
28+
return address.isDefaultBilling();
2629
});
2730

2831
return Component.extend({
@@ -53,7 +56,8 @@ define([
5356
this._super()
5457
.observe('selectedAddress isNewAddressSelected')
5558
.observe({
56-
isNewAddressSelected: !customer.isLoggedIn() || !addressOptions.length
59+
isNewAddressSelected: !customer.isLoggedIn() || !addressOptions.length,
60+
selectedAddress: this.addressOptions[addressDefaultIndex]
5761
});
5862

5963
return this;
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
/**
3+
*
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Magento\Customer\Model\Customer;
10+
11+
use Magento\Authorization\Model\UserContextInterface;
12+
use Magento\Customer\Model\CustomerFactory;
13+
use Magento\Customer\Model\ResourceModel\Customer as CustomerResource;
14+
use Magento\Framework\AuthorizationInterface;
15+
use Magento\Integration\Api\AuthorizationServiceInterface as AuthorizationService;
16+
use Magento\Store\Model\StoreManagerInterface;
17+
18+
/**
19+
* Checks if customer is logged in and authorized in the current store
20+
*/
21+
class Authorization implements AuthorizationInterface
22+
{
23+
/**
24+
* @var UserContextInterface
25+
*/
26+
private $userContext;
27+
28+
/**
29+
* @var CustomerFactory
30+
*/
31+
private $customerFactory;
32+
33+
/**
34+
* @var CustomerResource
35+
*/
36+
private $customerResource;
37+
38+
/**
39+
* @var StoreManagerInterface
40+
*/
41+
private $storeManager;
42+
43+
/**
44+
* Authorization constructor.
45+
*
46+
* @param UserContextInterface $userContext
47+
* @param CustomerFactory $customerFactory
48+
* @param CustomerResource $customerResource
49+
* @param StoreManagerInterface $storeManager
50+
*/
51+
public function __construct(
52+
UserContextInterface $userContext,
53+
CustomerFactory $customerFactory,
54+
CustomerResource $customerResource,
55+
StoreManagerInterface $storeManager
56+
) {
57+
$this->userContext = $userContext;
58+
$this->customerFactory = $customerFactory;
59+
$this->customerResource = $customerResource;
60+
$this->storeManager = $storeManager;
61+
}
62+
63+
/**
64+
* @inheritdoc
65+
*/
66+
public function isAllowed($resource, $privilege = null)
67+
{
68+
if ($resource === AuthorizationService::PERMISSION_SELF
69+
&& $this->userContext->getUserId()
70+
&& $this->userContext->getUserType() === UserContextInterface::USER_TYPE_CUSTOMER
71+
) {
72+
$customer = $this->customerFactory->create();
73+
$this->customerResource->load($customer, $this->userContext->getUserId());
74+
$currentStoreId = $this->storeManager->getStore()->getId();
75+
$sharedStoreIds = $customer->getSharedStoreIds();
76+
77+
return in_array($currentStoreId, $sharedStoreIds);
78+
}
79+
80+
return false;
81+
}
82+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
*
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Magento\Customer\Model\Customer;
10+
11+
use Magento\Framework\AuthorizationInterface;
12+
13+
/**
14+
* Class to invalidate user credentials
15+
*/
16+
class AuthorizationComposite implements AuthorizationInterface
17+
{
18+
/**
19+
* @var AuthorizationInterface[]
20+
*/
21+
private $authorizationChecks;
22+
23+
/**
24+
* AuthorizationComposite constructor.
25+
*
26+
* @param AuthorizationInterface[] $authorizationChecks
27+
*/
28+
public function __construct(
29+
array $authorizationChecks
30+
) {
31+
$this->authorizationChecks = $authorizationChecks;
32+
}
33+
34+
/**
35+
* @inheritdoc
36+
*/
37+
public function isAllowed($resource, $privilege = null)
38+
{
39+
$result = false;
40+
41+
foreach ($this->authorizationChecks as $authorizationCheck) {
42+
$result = $authorizationCheck->isAllowed($resource, $privilege);
43+
if (!$result) {
44+
break;
45+
}
46+
}
47+
48+
return $result;
49+
}
50+
}

app/code/Magento/Customer/Model/Plugin/CustomerAuthorization.php

Lines changed: 19 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66

77
namespace Magento\Customer\Model\Plugin;
88

9-
use Magento\Authorization\Model\UserContextInterface;
10-
use Magento\Customer\Model\CustomerFactory;
11-
use Magento\Customer\Model\ResourceModel\Customer as CustomerResource;
12-
use Magento\Integration\Api\AuthorizationServiceInterface as AuthorizationService;
13-
use Magento\Store\Model\StoreManagerInterface;
9+
use Closure;
10+
use Magento\Customer\Model\Customer\AuthorizationComposite;
11+
use Magento\Framework\Authorization;
1412

1513
/**
1614
* Plugin around \Magento\Framework\Authorization::isAllowed
@@ -20,74 +18,38 @@
2018
class CustomerAuthorization
2119
{
2220
/**
23-
* @var UserContextInterface
21+
* @var AuthorizationComposite
2422
*/
25-
private $userContext;
26-
27-
/**
28-
* @var CustomerFactory
29-
*/
30-
private $customerFactory;
31-
32-
/**
33-
* @var CustomerResource
34-
*/
35-
private $customerResource;
36-
37-
/**
38-
* @var StoreManagerInterface
39-
*/
40-
private $storeManager;
23+
private $authorizationComposite;
4124

4225
/**
4326
* Inject dependencies.
44-
*
45-
* @param UserContextInterface $userContext
46-
* @param CustomerFactory $customerFactory
47-
* @param CustomerResource $customerResource
48-
* @param StoreManagerInterface $storeManager
27+
* @param AuthorizationComposite $composite
4928
*/
5029
public function __construct(
51-
UserContextInterface $userContext,
52-
CustomerFactory $customerFactory,
53-
CustomerResource $customerResource,
54-
StoreManagerInterface $storeManager
30+
AuthorizationComposite $composite
5531
) {
56-
$this->userContext = $userContext;
57-
$this->customerFactory = $customerFactory;
58-
$this->customerResource = $customerResource;
59-
$this->storeManager = $storeManager;
32+
$this->authorizationComposite = $composite;
6033
}
6134

6235
/**
63-
* Check if resource for which access is needed has self permissions defined in webapi config.
36+
* Verify if to allow customer users to access resources with self permission
6437
*
65-
* @param \Magento\Framework\Authorization $subject
66-
* @param callable $proceed
67-
* @param string $resource
68-
* @param string $privilege
69-
*
70-
* @return bool true If resource permission is self, to allow
71-
* customer access without further checks in parent method
7238
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
39+
* @param Authorization $subject
40+
* @param Closure $proceed
41+
* @param string $resource
42+
* @param mixed $privilege
43+
* @return bool
7344
*/
7445
public function aroundIsAllowed(
75-
\Magento\Framework\Authorization $subject,
76-
\Closure $proceed,
77-
$resource,
46+
Authorization $subject,
47+
Closure $proceed,
48+
string $resource,
7849
$privilege = null
7950
) {
80-
if ($resource == AuthorizationService::PERMISSION_SELF
81-
&& $this->userContext->getUserId()
82-
&& $this->userContext->getUserType() === UserContextInterface::USER_TYPE_CUSTOMER
83-
) {
84-
$customer = $this->customerFactory->create();
85-
$this->customerResource->load($customer, $this->userContext->getUserId());
86-
$currentStoreId = $this->storeManager->getStore()->getId();
87-
$sharedStoreIds = $customer->getSharedStoreIds();
88-
if (in_array($currentStoreId, $sharedStoreIds)) {
89-
return true;
90-
}
51+
if ($this->authorizationComposite->isAllowed($resource, $privilege)) {
52+
return true;
9153
}
9254

9355
return $proceed($resource, $privilege);

app/code/Magento/Customer/Test/Mftf/Data/CustomerData.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,21 @@
285285
<requiredEntity type="address">DE_Address_Berlin_Not_Default_Address</requiredEntity>
286286
<requiredEntity type="address">UK_Not_Default_Address</requiredEntity>
287287
</entity>
288+
<entity name="Customer_DE_UK_US" type="customer">
289+
<data key="group_id">1</data>
290+
<data key="default_billing">true</data>
291+
<data key="default_shipping">true</data>
292+
<data key="email" unique="prefix">[email protected]</data>
293+
<data key="firstname">John</data>
294+
<data key="lastname">Doe</data>
295+
<data key="fullname">John Doe</data>
296+
<data key="password">pwdTest123!</data>
297+
<data key="store_id">0</data>
298+
<data key="website_id">0</data>
299+
<requiredEntity type="address">DE_Address_Berlin_Not_Default_Address</requiredEntity>
300+
<requiredEntity type="address">UK_Not_Default_Address</requiredEntity>
301+
<requiredEntity type="address">US_Address_NY</requiredEntity>
302+
</entity>
288303
<entity name="Retailer_Customer" type="customer">
289304
<data key="group_id">3</data>
290305
<data key="default_billing">true</data>

app/code/Magento/Customer/etc/webapi_rest/di.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,13 @@
2222
<type name="Magento\Customer\Api\CustomerRepositoryInterface">
2323
<plugin name="updateCustomerByIdFromRequest" type="Magento\Customer\Model\Plugin\UpdateCustomer" />
2424
</type>
25+
<type name="Magento\Customer\Model\Customer\AuthorizationComposite">
26+
<arguments>
27+
<argument name="authorizationChecks" xsi:type="array">
28+
<item name="rest_customer_authorization" xsi:type="object">
29+
Magento\Customer\Model\Customer\Authorization
30+
</item>
31+
</argument>
32+
</arguments>
33+
</type>
2534
</config>

app/code/Magento/Customer/etc/webapi_soap/di.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,13 @@
99
<type name="Magento\Framework\Authorization">
1010
<plugin name="customerAuthorization" type="Magento\Customer\Model\Plugin\CustomerAuthorization" />
1111
</type>
12+
<type name="Magento\Customer\Model\Customer\AuthorizationComposite">
13+
<arguments>
14+
<argument name="authorizationChecks" xsi:type="array">
15+
<item name="soap_customer_authorization" xsi:type="object">
16+
Magento\Customer\Model\Customer\Authorization
17+
</item>
18+
</argument>
19+
</arguments>
20+
</type>
1221
</config>

app/code/Magento/Customer/view/frontend/web/js/customer-data.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ define([
261261
}
262262
});
263263

264+
//remove expired section names of previously installed/enable modules
265+
expiredSectionNames = _.intersection(expiredSectionNames, sectionConfig.getSectionNames());
266+
264267
return _.uniq(expiredSectionNames);
265268
},
266269

0 commit comments

Comments
 (0)