Skip to content

Commit 757c11a

Browse files
[Magento Community Engineering] Community Contributions - 2.4-develop
- merged latest code from mainline branch
2 parents 91a5013 + 3b19d14 commit 757c11a

File tree

16 files changed

+940
-125
lines changed

16 files changed

+940
-125
lines changed

app/code/Magento/AdminAnalytics/Test/Mftf/Test/TrackingScriptTest.xml

Lines changed: 0 additions & 26 deletions
This file was deleted.

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

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
namespace Magento\Customer\Model\Plugin;
88

99
use Magento\Authorization\Model\UserContextInterface;
10+
use Magento\Customer\Model\CustomerFactory;
11+
use Magento\Customer\Model\ResourceModel\Customer as CustomerResource;
1012
use Magento\Integration\Api\AuthorizationServiceInterface as AuthorizationService;
13+
use Magento\Store\Model\StoreManagerInterface;
1114

1215
/**
1316
* Plugin around \Magento\Framework\Authorization::isAllowed
@@ -19,16 +22,41 @@ class CustomerAuthorization
1922
/**
2023
* @var UserContextInterface
2124
*/
22-
protected $userContext;
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;
2341

2442
/**
2543
* Inject dependencies.
2644
*
2745
* @param UserContextInterface $userContext
46+
* @param CustomerFactory $customerFactory
47+
* @param CustomerResource $customerResource
48+
* @param StoreManagerInterface $storeManager
2849
*/
29-
public function __construct(UserContextInterface $userContext)
30-
{
50+
public function __construct(
51+
UserContextInterface $userContext,
52+
CustomerFactory $customerFactory,
53+
CustomerResource $customerResource,
54+
StoreManagerInterface $storeManager
55+
) {
3156
$this->userContext = $userContext;
57+
$this->customerFactory = $customerFactory;
58+
$this->customerResource = $customerResource;
59+
$this->storeManager = $storeManager;
3260
}
3361

3462
/**
@@ -53,9 +81,15 @@ public function aroundIsAllowed(
5381
&& $this->userContext->getUserId()
5482
&& $this->userContext->getUserType() === UserContextInterface::USER_TYPE_CUSTOMER
5583
) {
56-
return true;
57-
} else {
58-
return $proceed($resource, $privilege);
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+
}
5991
}
92+
93+
return $proceed($resource, $privilege);
6094
}
6195
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MediaContentCatalog\Observer;
9+
10+
use Magento\Catalog\Model\Category as CatalogCategory;
11+
use Magento\Framework\Event\Observer;
12+
use Magento\Framework\Event\ObserverInterface;
13+
use Magento\MediaContentApi\Api\Data\ContentIdentityInterfaceFactory;
14+
use Magento\MediaContentApi\Api\Data\ContentAssetLinkInterfaceFactory;
15+
use Magento\MediaContentApi\Api\DeleteContentAssetLinksInterface;
16+
use Magento\MediaContentApi\Model\GetEntityContentsInterface;
17+
use Magento\MediaContentApi\Api\ExtractAssetsFromContentInterface;
18+
19+
/**
20+
* Observe the catalog_category_delete_after event and deletes relation between category content and media asset.
21+
*/
22+
class CategoryDelete implements ObserverInterface
23+
{
24+
private const CONTENT_TYPE = 'catalog_category';
25+
private const TYPE = 'entityType';
26+
private const ENTITY_ID = 'entityId';
27+
private const FIELD = 'field';
28+
29+
/**
30+
* @var ContentIdentityInterfaceFactory
31+
*/
32+
private $contentIdentityFactory;
33+
34+
/**
35+
* @var ContentAssetLinkInterfaceFactory
36+
*/
37+
private $contentAssetLinkFactory;
38+
39+
/**
40+
* @var DeleteContentAssetLinksInterface
41+
*/
42+
private $deleteContentAssetLinks;
43+
44+
/**
45+
* @var array
46+
*/
47+
private $fields;
48+
49+
/**
50+
* @var GetEntityContentsInterface
51+
*/
52+
private $getContent;
53+
54+
/**
55+
* @var ExtractAssetsFromContentInterface
56+
*/
57+
private $extractAssetsFromContent;
58+
59+
/**
60+
* @param ExtractAssetsFromContentInterface $extractAssetsFromContent
61+
* @param GetEntityContentsInterface $getContent
62+
* @param DeleteContentAssetLinksInterface $deleteContentAssetLinks
63+
* @param ContentIdentityInterfaceFactory $contentIdentityFactory
64+
* @param ContentAssetLinkInterfaceFactory $contentAssetLinkFactory
65+
* @param array $fields
66+
*/
67+
public function __construct(
68+
ExtractAssetsFromContentInterface $extractAssetsFromContent,
69+
GetEntityContentsInterface $getContent,
70+
DeleteContentAssetLinksInterface $deleteContentAssetLinks,
71+
ContentIdentityInterfaceFactory $contentIdentityFactory,
72+
ContentAssetLinkInterfaceFactory $contentAssetLinkFactory,
73+
array $fields
74+
) {
75+
$this->extractAssetsFromContent = $extractAssetsFromContent;
76+
$this->getContent = $getContent;
77+
$this->deleteContentAssetLinks = $deleteContentAssetLinks;
78+
$this->contentAssetLinkFactory = $contentAssetLinkFactory;
79+
$this->contentIdentityFactory = $contentIdentityFactory;
80+
$this->fields = $fields;
81+
}
82+
83+
/**
84+
* Retrieve the deleted category and remove relation betwen category and asset
85+
*
86+
* @param Observer $observer
87+
* @throws \Exception
88+
*/
89+
public function execute(Observer $observer): void
90+
{
91+
$category = $observer->getEvent()->getData('category');
92+
$contentAssetLinks = [];
93+
94+
if ($category instanceof CatalogCategory) {
95+
foreach ($this->fields as $field) {
96+
$contentIdentity = $this->contentIdentityFactory->create(
97+
[
98+
self::TYPE => self::CONTENT_TYPE,
99+
self::FIELD => $field,
100+
self::ENTITY_ID => (string) $category->getEntityId(),
101+
]
102+
);
103+
$content = implode(PHP_EOL, $this->getContent->execute($contentIdentity));
104+
$assets = $this->extractAssetsFromContent->execute($content);
105+
106+
foreach ($assets as $asset) {
107+
$contentAssetLinks[] = $this->contentAssetLinkFactory->create(
108+
[
109+
'assetId' => $asset->getId(),
110+
'contentIdentity' => $contentIdentity
111+
]
112+
);
113+
}
114+
}
115+
if (!empty($contentAssetLinks)) {
116+
$this->deleteContentAssetLinks->execute($contentAssetLinks);
117+
}
118+
}
119+
}
120+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MediaContentCatalog\Observer;
9+
10+
use Magento\Catalog\Model\Product as CatalogProduct;
11+
use Magento\Framework\Event\Observer;
12+
use Magento\Framework\Event\ObserverInterface;
13+
use Magento\MediaContentApi\Api\Data\ContentIdentityInterfaceFactory;
14+
use Magento\MediaContentApi\Api\Data\ContentAssetLinkInterfaceFactory;
15+
use Magento\MediaContentApi\Api\DeleteContentAssetLinksInterface;
16+
use Magento\MediaContentApi\Model\GetEntityContentsInterface;
17+
use Magento\MediaContentApi\Api\ExtractAssetsFromContentInterface;
18+
19+
/**
20+
* Observe the catalog_product_delete_before event and deletes relation between category content and media asset.
21+
*/
22+
class ProductDelete implements ObserverInterface
23+
{
24+
private const CONTENT_TYPE = 'catalog_product';
25+
private const TYPE = 'entityType';
26+
private const ENTITY_ID = 'entityId';
27+
private const FIELD = 'field';
28+
29+
/**
30+
* @var ContentIdentityInterfaceFactory
31+
*/
32+
private $contentIdentityFactory;
33+
34+
/**
35+
* @var ContentAssetLinkInterfaceFactory
36+
*/
37+
private $contentAssetLinkFactory;
38+
39+
/**
40+
* @var DeleteContentAssetLinksInterface
41+
*/
42+
private $deleteContentAssetLinks;
43+
44+
/**
45+
* @var array
46+
*/
47+
private $fields;
48+
49+
/**
50+
* @var GetEntityContentsInterface
51+
*/
52+
private $getContent;
53+
54+
/**
55+
* @var ExtractAssetsFromContentInterface
56+
*/
57+
private $extractAssetsFromContent;
58+
59+
/**
60+
* @param ExtractAssetsFromContentInterface $extractAssetsFromContent
61+
* @param GetEntityContentsInterface $getContent
62+
* @param DeleteContentAssetLinksInterface $deleteContentAssetLinks
63+
* @param ContentIdentityInterfaceFactory $contentIdentityFactory
64+
* @param ContentAssetLinkInterfaceFactory $contentAssetLinkFactory
65+
* @param array $fields
66+
*/
67+
public function __construct(
68+
ExtractAssetsFromContentInterface $extractAssetsFromContent,
69+
GetEntityContentsInterface $getContent,
70+
DeleteContentAssetLinksInterface $deleteContentAssetLinks,
71+
ContentIdentityInterfaceFactory $contentIdentityFactory,
72+
ContentAssetLinkInterfaceFactory $contentAssetLinkFactory,
73+
array $fields
74+
) {
75+
$this->extractAssetsFromContent = $extractAssetsFromContent;
76+
$this->getContent = $getContent;
77+
$this->deleteContentAssetLinks = $deleteContentAssetLinks;
78+
$this->contentAssetLinkFactory = $contentAssetLinkFactory;
79+
$this->contentIdentityFactory = $contentIdentityFactory;
80+
$this->fields = $fields;
81+
}
82+
83+
/**
84+
* Retrieve the deleted product and remove relation betwen product and asset
85+
*
86+
* @param Observer $observer
87+
* @throws \Exception
88+
*/
89+
public function execute(Observer $observer): void
90+
{
91+
$product = $observer->getEvent()->getData('product');
92+
$contentAssetLinks = [];
93+
94+
if ($product instanceof CatalogProduct) {
95+
foreach ($this->fields as $field) {
96+
$contentIdentity = $this->contentIdentityFactory->create(
97+
[
98+
self::TYPE => self::CONTENT_TYPE,
99+
self::FIELD => $field,
100+
self::ENTITY_ID => (string) $product->getEntityId(),
101+
]
102+
);
103+
$productContent = implode(PHP_EOL, $this->getContent->execute($contentIdentity));
104+
$assets = $this->extractAssetsFromContent->execute($productContent);
105+
106+
foreach ($assets as $asset) {
107+
$contentAssetLinks[] = $this->contentAssetLinkFactory->create(
108+
[
109+
'assetId' => $asset->getId(),
110+
'contentIdentity' => $contentIdentity
111+
]
112+
);
113+
}
114+
}
115+
if (!empty($contentAssetLinks)) {
116+
$this->deleteContentAssetLinks->execute($contentAssetLinks);
117+
}
118+
}
119+
}
120+
}

app/code/Magento/MediaContentCatalog/etc/di.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@
1414
</argument>
1515
</arguments>
1616
</type>
17+
<type name="Magento\MediaContentCatalog\Observer\ProductDelete">
18+
<arguments>
19+
<argument name="fields" xsi:type="array">
20+
<item name="description" xsi:type="string">description</item>
21+
<item name="short_description" xsi:type="string">short_description</item>
22+
</argument>
23+
</arguments>
24+
</type>
25+
<type name="Magento\MediaContentCatalog\Observer\CategoryDelete">
26+
<arguments>
27+
<argument name="fields" xsi:type="array">
28+
<item name="image" xsi:type="string">image</item>
29+
<item name="description" xsi:type="string">description</item>
30+
</argument>
31+
</arguments>
32+
</type>
1733
<type name="Magento\MediaContentCatalog\Observer\Category">
1834
<arguments>
1935
<argument name="fields" xsi:type="array">

app/code/Magento/MediaContentCatalog/etc/events.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
<event name="catalog_category_save_after">
1010
<observer name="media_content_catalog_category_save_after" instance="Magento\MediaContentCatalog\Observer\Category" />
1111
</event>
12+
<event name="catalog_product_delete_before">
13+
<observer name="media_content_catalog_product_delete_before" instance="Magento\MediaContentCatalog\Observer\ProductDelete" />
14+
</event>
15+
<event name="catalog_category_delete_before">
16+
<observer name="media_content_catalog_category_delete_before" instance="Magento\MediaContentCatalog\Observer\CategoryDelete" />
17+
</event>
1218
<event name="catalog_product_save_after">
1319
<observer name="media_content_catalog_product_save_after" instance="Magento\MediaContentCatalog\Observer\Product" />
1420
</event>

0 commit comments

Comments
 (0)