Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1440: create an endpoint for saving asset attributes #1506

Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e371bd5
magento/adobe-stock-integration#1440: Create an endpoint for saving a…
Jun 17, 2020
550fed0
Merge branch '2.0-develop' into 1440-create-an-endpoint-for-saving-as…
Jun 18, 2020
18e1a50
magento/adobe-stock-integration#1440: create an endpoint for saving a…
Jun 18, 2020
cd3e6c5
magento/adobe-stock-integration#1440: Create an endpoint for saving a…
Jun 23, 2020
efb0e48
magento/adobe-stock-integration#1440: Create an endpoint for saving a…
Jun 25, 2020
f132393
magento/adobe-stock-integration#1440: Create an endpoint for saving a…
Jun 28, 2020
b7cdfe6
magento/adobe-stock-integration#1440: Create an endpoint for saving a…
Jun 28, 2020
169e699
magento/adobe-stock-integration#1440: Create an endpoint for saving a…
Jun 28, 2020
d738465
magento/adobe-stock-integration#1440: Create an endpoint for saving a…
Jun 28, 2020
534a343
magento/adobe-stock-integration#1440: Create an endpoint for saving a…
Jun 28, 2020
f3cfbfa
magento/adobe-stock-integration#1440: Create an endpoint for saving a…
Jun 29, 2020
e9b8af6
magento/adobe-stock-integration#1440: Create an endpoint for saving a…
Jun 29, 2020
2572722
magento/adobe-stock-integration#1440: Create an endpoint for saving a…
Jun 29, 2020
c809b59
Merge branch '2.0-develop' of github.com:magento/adobe-stock-integrat…
Jun 29, 2020
40660c1
magento/adobe-stock-integration#1440: Create an endpoint for saving a…
Jun 29, 2020
06a76de
magento/adobe-stock-integration#1440: Create an endpoint for saving a…
Jun 30, 2020
98d0c26
magento/adobe-stock-integration#1440: Create an endpoint for saving a…
Jun 30, 2020
8f43f2a
magento/adobe-stock-integration#1440: Create an endpoint for saving a…
Jul 1, 2020
ea60efd
magento/adobe-stock-integration#1440: Create an endpoint for saving a…
Jul 2, 2020
8533b39
magento/adobe-stock-integration#1440: Create an endpoint for saving a…
Jul 2, 2020
90ceec4
Merge branch '2.0-develop' into 1440-create-an-endpoint-for-saving-as…
sivaschenko Jul 3, 2020
3d96605
magento/adobe-stock-integration#1440: Create an endpoint for saving a…
Jul 3, 2020
14daa64
Merge branch '2.0-develop' into 1440-create-an-endpoint-for-saving-as…
sivaschenko Jul 6, 2020
ed34e2d
magento/adobe-stock-integration#1506: Added grid reload and adjusted …
sivaschenko Jul 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 146 additions & 0 deletions MediaGalleryUi/Controller/Adminhtml/Image/SaveDetails.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\MediaGalleryUi\Controller\Adminhtml\Image;

use Exception;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Controller\Result\Json;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Exception\LocalizedException;
use Magento\MediaGalleryApi\Api\Data\AssetKeywordsInterfaceFactory;
use Magento\MediaGalleryApi\Api\GetAssetsByIdsInterface;
use Magento\MediaGalleryApi\Api\SaveAssetsInterface;
use Magento\MediaGalleryApi\Api\SaveAssetsKeywordsInterface;
use Psr\Log\LoggerInterface;

class SaveDetails extends Action implements HttpPostActionInterface
{
private const HTTP_OK = 200;
private const HTTP_INTERNAL_ERROR = 500;
private const HTTP_BAD_REQUEST = 400;

/**
* @see _isAllowed()
*/
public const ADMIN_RESOURCE = 'Magento_Cms::media_gallery';

/**
* @var SaveAssetsInterface
*/
private $saveAssets;

/**
* @var SaveAssetsKeywordsInterface
*/
private $saveAssetKeywords;

/**
* @var AssetKeywordsInterfaceFactory
*/
private $assetKeywordsFactory;

/**
* @var GetAssetsByIdsInterface
*/
private $getAssetsByIds;

/**
* @var LoggerInterface
*/
private $logger;

/**
* SaveDetails constructor.
*
* @param Context $context
* @param SaveAssetsInterface $saveAssets
* @param SaveAssetsKeywordsInterface $saveAssetKeywords
* @param AssetKeywordsInterfaceFactory $assetKeywordsFactory
* @param GetAssetsByIdsInterface $getAssetsByIds
* @param LoggerInterface $logger
*/
public function __construct(
Context $context,
SaveAssetsInterface $saveAssets,
SaveAssetsKeywordsInterface $saveAssetKeywords,
AssetKeywordsInterfaceFactory $assetKeywordsFactory,
GetAssetsByIdsInterface $getAssetsByIds,
LoggerInterface $logger
) {
parent::__construct($context);

$this->saveAssets = $saveAssets;
$this->saveAssetKeywords = $saveAssetKeywords;
$this->assetKeywordsFactory = $assetKeywordsFactory;
$this->getAssetsByIds = $getAssetsByIds;
$this->logger = $logger;
}

/**
* @inheritDoc
*/
public function execute()
{
/** @var Json $resultJson */
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
$imageId = (int) $this->getRequest()->getParam('id');
$title = $this->getRequest()->getParam('title');
$description = $this->getRequest()->getParam('description');
$imageKeywords = (array) $this->getRequest()->getParam('keywords');

if ($imageId === 0) {
$this->logger->debug("IF");
joweecaquicla marked this conversation as resolved.
Show resolved Hide resolved
$responseContent = [
'success' => false,
'message' => __('Image ID is required.'),
];
$resultJson->setHttpResponseCode(self::HTTP_BAD_REQUEST);
$resultJson->setData($responseContent);

return $resultJson;
}

try {
$asset = current($this->getAssetsByIds->execute([$imageId]));
$asset->setTitle($title);
$asset->setDescription($description);
$this->saveAssets->execute([$asset]);
$assetKeywords = $this->assetKeywordsFactory->create([
'assetId' => $imageId,
'keywords' => $imageKeywords
]);
$this->saveAssetKeywords->execute([$assetKeywords]);

$responseCode = self::HTTP_OK;
$responseContent = [
'success' => true,
'message' => __('You have successfully saved the image "%image"', ['image' => $asset->getTitle()]),
];
} catch (LocalizedException $exception) {
$responseCode = self::HTTP_BAD_REQUEST;
$responseContent = [
'success' => false,
'message' => $exception->getMessage(),
];
} catch (Exception $exception) {
$this->logger->critical($exception);
$responseCode = self::HTTP_INTERNAL_ERROR;
$responseContent = [
'success' => false,
'message' => __('An error occurred on attempt to save image.'),
];
}

$resultJson->setHttpResponseCode($responseCode);
$resultJson->setData($responseContent);

return $resultJson;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminEnhancedMediaGalleryEditImageDetailsActionGroup">
<annotations>
<description>Opens Edit image details panel panel for the first image in the media gallery grid</description>
</annotations>

<click selector="{{AdminEnhancedMediaGalleryImageActionsSection.openContextMenu}}" stepKey="openContextMenu"/>
<click selector="{{AdminEnhancedMediaGalleryImageActionsSection.edit}}" stepKey="edit"/>
<waitForLoadingMaskToDisappear stepKey="waitForLoadingMaskToDisappear"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminEnhancedMediaGalleryImageDetailsSaveActionGroup">
<annotations>
<description>Save image details from the View Details panel</description>
</annotations>
<arguments>
<argument name="title" type="string" defaultValue="Test Title"/>
<argument name="description" type="string" defaultValue="Test Description"/>
</arguments>

<fillField selector="{{AdminEnhancedMediaGalleryEditDetailsSection.title}}" userInput="{{title}}" stepKey="setTitle" />
<fillField selector="{{AdminEnhancedMediaGalleryEditDetailsSection.description}}" userInput="{{description}}" stepKey="setDescription" />
<click selector="{{AdminEnhancedMediaGalleryEditDetailsSection.save}}" stepKey="saveDetails"/>
<waitForLoadingMaskToDisappear stepKey="waitForLoadingMaskToDisappear"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
<section name="AdminEnhancedMediaGalleryEditDetailsSection">
<element name="title" type="input" selector="#title"/>
joweecaquicla marked this conversation as resolved.
Show resolved Hide resolved
<element name="fileName" type="text" selector="#path"/>
<element name="description" type="textarea" selector="#description"/>
<element name="cancel" type="button" selector="#image-details-action-cancel"/>
<element name="save" type="button" selector="#image-details-action-save"/>
</section>
</sections>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<element name="openContextMenu" type="button" selector=".three-dots"/>
<element name="viewDetails" type="button" selector="[data-ui-id='action-image-details']"/>
<element name="delete" type="button" selector="[data-ui-id='action-delete']"/>
<element name="edit" type="button" selector="[data-ui-id='action-edit']"/>
<element name="imageInGrid" type="button" selector="//img[@class='media-gallery-image-column'][contains(@src, '{{imageName}}')]" parameterized="true"/>
</section>
</sections>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="AdminMediaGalleryEditSaveImageDetailsTest">
joweecaquicla marked this conversation as resolved.
Show resolved Hide resolved
<annotations>
<features value="MediaGallery"/>
<useCaseId value="https://github.com/magento/adobe-stock-integration/issues/724"/>
<title value="User edits image meta data in media gallery"/>
<stories value="[Story # 38] User views basic image attributes in Media Gallery"/>
<testCaseId value=""/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chalov-anton , please provide the test case id (link) that should be used for this MFTF test

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chalov-anton , please provide the test case id (link) that should be used for this MFTF test

https://studio.cucumber.io/projects/131313/test-plan/folders/1320712/scenarios/3961351
The scenario is In Progress state

<description value=""/>
<severity value="CRITICAL"/>
<group value="media_gallery_ui"/>
</annotations>
<before>
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
<actionGroup ref="AdminOpenMediaGalleryForPageNoEditorActionGroup" stepKey="openMediaGalleryForPage"/>
</before>

<actionGroup ref="AdminEnhancedMediaGalleryUploadImageActionGroup" stepKey="uploadImage">
<argument name="image" value="ImageUpload"/>
</actionGroup>
<actionGroup ref="AdminEnhancedMediaGalleryEditImageDetailsActionGroup" stepKey="editImageDetails"/>
<actionGroup ref="AdminEnhancedMediaGalleryImageDetailsSaveActionGroup" stepKey="saveImage"/>
</test>
</tests>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="AdminStandaloneMediaGalleryEditSaveImageDetailsTest">
joweecaquicla marked this conversation as resolved.
Show resolved Hide resolved
<annotations>
<features value="MediaGallery"/>
<useCaseId value="https://github.com/magento/adobe-stock-integration/issues/724"/>
<title value="User edits image meta data in standalone media gallery"/>
<stories value="[Story # 38] User views basic image attributes in Media Gallery"/>
<testCaseId value=""/>
<description value=""/>
<severity value="CRITICAL"/>
<group value="media_gallery_ui"/>
</annotations>
<before>
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
<actionGroup ref="AdminOpenStandaloneMediaGalleryActionGroup" stepKey="openStandaloneMediaGallery"/>
</before>
joweecaquicla marked this conversation as resolved.
Show resolved Hide resolved

<actionGroup ref="AdminEnhancedMediaGalleryUploadImageActionGroup" stepKey="uploadImage">
<argument name="image" value="ImageUpload"/>
</actionGroup>
<actionGroup ref="AdminEnhancedMediaGalleryEditImageDetailsActionGroup" stepKey="editImageDetails"/>
<actionGroup ref="AdminEnhancedMediaGalleryImageDetailsSaveActionGroup" stepKey="saveImage"/>
joweecaquicla marked this conversation as resolved.
Show resolved Hide resolved
</test>
</tests>
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
<argument name="imageDetailsUrl" xsi:type="url" path="media_gallery/image/details"/>
</arguments>
</block>
<block name="image.edit.details" class="Magento\Backend\Block\Template" template="Magento_MediaGalleryUi::image_edit_details.phtml">
<arguments>
<argument name="imageEditDetailsUrl" xsi:type="url" path="media_gallery/image/details"/>
<argument name="saveDetailsUrl" xsi:type="url" path="media_gallery/image/saveDetails"/>
</arguments>
</block>
</block>
</container>
</layout>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
<argument name="imageDetailsUrl" xsi:type="url" path="media_gallery/image/details"/>
</arguments>
</block>
<block name="image.edit.details" class="Magento\Backend\Block\Template" template="Magento_MediaGalleryUi::image_edit_details_standalone.phtml">
<arguments>
<argument name="imageEditDetailsUrl" xsi:type="url" path="media_gallery/image/details"/>
<argument name="saveDetailsUrl" xsi:type="url" path="media_gallery/image/saveDetails"/>
</arguments>
</block>
</referenceContainer>
</body>
</page>
Loading