Skip to content

Commit 06f41c9

Browse files
authored
Merge pull request #5337 from magento-engcom/2.3.5-asi
[Magento Community Engineering] 2.3.5 Adobe Stock Integration scope
2 parents a201f17 + c011ca3 commit 06f41c9

File tree

11 files changed

+147
-18
lines changed

11 files changed

+147
-18
lines changed

app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images/DeleteFiles.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
*/
66
namespace Magento\Cms\Controller\Adminhtml\Wysiwyg\Images;
77

8-
use Magento\Framework\App\Filesystem\DirectoryList;
98
use Magento\Framework\App\Action\HttpPostActionInterface;
9+
use Magento\Framework\App\Filesystem\DirectoryList;
1010

1111
/**
1212
* Delete image files.
@@ -60,10 +60,15 @@ public function __construct(
6060
*/
6161
public function execute()
6262
{
63+
$resultJson = $this->resultJsonFactory->create();
64+
65+
if (!$this->getRequest()->isPost()) {
66+
$result = ['error' => true, 'message' => __('Wrong request.')];
67+
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
68+
return $resultJson->setData($result);
69+
}
70+
6371
try {
64-
if (!$this->getRequest()->isPost()) {
65-
throw new \Exception('Wrong request.');
66-
}
6772
$files = $this->getRequest()->getParam('files');
6873

6974
/** @var $helper \Magento\Cms\Helper\Wysiwyg\Images */
@@ -79,17 +84,16 @@ public function execute()
7984
/** @var \Magento\Framework\Filesystem $filesystem */
8085
$filesystem = $this->_objectManager->get(\Magento\Framework\Filesystem::class);
8186
$dir = $filesystem->getDirectoryRead(DirectoryList::MEDIA);
82-
$filePath = $path . '/' . \Magento\Framework\File\Uploader::getCorrectFileName($file);
87+
$filePath = $path . '/' . $file;
8388
if ($dir->isFile($dir->getRelativePath($filePath)) && !preg_match('#.htaccess#', $file)) {
8489
$this->getStorage()->deleteFile($filePath);
8590
}
8691
}
87-
92+
8893
return $this->resultRawFactory->create();
94+
// phpcs:ignore Magento2.Exceptions.ThrowCatch
8995
} catch (\Exception $e) {
9096
$result = ['error' => true, 'message' => $e->getMessage()];
91-
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
92-
$resultJson = $this->resultJsonFactory->create();
9397

9498
return $resultJson->setData($result);
9599
}

app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ define([
239239
handleKeyDown: function (e) {
240240
var key = keyCodes[e.keyCode];
241241

242-
if (this.visibleRecord() !== null) {
242+
if (this.visibleRecord() !== null && document.activeElement.tagName !== 'INPUT') {
243243
if (key === 'pageLeftKey') {
244244
this.prev(this.displayedRecord());
245245
} else if (key === 'pageRightKey') {

app/code/Magento/Ui/view/base/web/js/grid/columns/image.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ define([
8080
return record.css || {};
8181
},
8282

83+
/**
84+
* Get is active record
85+
*
86+
* @param {Object} record - Data to be preprocessed.
87+
*
88+
* @returns {Boolean}
89+
*/
90+
getIsActive: function (record) {
91+
return this.previewComponent().visibleRecord() === record._rowIndex || false;
92+
},
93+
8394
/**
8495
* Expand image preview
8596
*/

app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/color-picker.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ define([
7171
update: function (element, valueAccessor, allBindings, viewModel) {
7272
var config = valueAccessor();
7373

74+
/** Initialise value as empty if it is undefined when color picker input is reset **/
75+
if (config.value() === undefined) {
76+
config.value('');
77+
}
78+
7479
if (tinycolor(config.value()).isValid() || config.value() === '') {
7580
$(element).spectrum('set', config.value());
7681

app/code/Magento/Ui/view/base/web/templates/grid/columns/image.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
* See COPYING.txt for license details.
55
*/
66
-->
7-
<div class="masonry-image-block" ko-style="$col.getStyles($row())" attr="'data-id': $col.getId($row())">
7+
<div class="masonry-image-block" ko-style="$col.getStyles($row())" css="{'active': $col.getIsActive($row())}" attr="'data-id': $col.getId($row())">
88
<img attr="src: $col.getUrl($row())" css="$col.getClasses($row())" click="function(){ expandPreview($row()) }" data-role="thumbnail"/>
99
</div>

app/code/Magento/Ui/view/base/web/templates/grid/masonry.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* See COPYING.txt for license details.
55
*/
66
-->
7-
<div data-role="grid-wrapper" class="masonry-image-grid" attr="'data-id': containerId">
7+
<div data-role="grid-wrapper" class="masonry-image-grid" attr="'data-id': containerId" tabindex="0">
88
<div class="masonry-image-column" repeat="foreach: rows, item: '$row'">
99
<div outerfasteach="data: getVisible(), as: '$col'" template="getBody()"/>
1010
</div>

app/design/adminhtml/Magento/backend/Magento_Cms/web/css/source/_module.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
.media-gallery-modal {
77
.page-main-actions {
88
margin-bottom: 3rem;
9+
10+
.page-action-buttons {
11+
text-align: right;
12+
}
913
}
1014

1115
.new_folder {

app/design/adminhtml/Magento/backend/Magento_Ui/web/css/source/module/_masonry-grid.less

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
@admin__masonry_grid_image__space: 20px;
66
@admin__masonry_grid_background_color: #fff;
77
@admin__masonry_overlay_background_color: #507dc8;
8+
@admin__masonry_grid_active_image_border_color: #558dd6;
89

910
& when (@media-common = true) {
1011
.masonry-image {
@@ -27,6 +28,15 @@
2728
margin: @admin__masonry_grid_image__space/2;
2829
overflow: hidden;
2930

31+
.masonry-image-block {
32+
&.active {
33+
img {
34+
border: 2px @admin__masonry_grid_active_image_border_color solid;
35+
padding: 1px;
36+
}
37+
}
38+
}
39+
3040
img {
3141
cursor: pointer;
3242
height: 100%;

dev/tests/integration/testsuite/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images/DeleteFilesTest.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,47 @@ protected function setUp()
7575
* Execute method with correct directory path and file name to check that files under WYSIWYG media directory
7676
* can be removed.
7777
*
78+
* @param string $filename
7879
* @return void
80+
* @dataProvider executeDataProvider
7981
*/
80-
public function testExecute()
82+
public function testExecute(string $filename)
8183
{
84+
$filePath = $this->fullDirectoryPath . DIRECTORY_SEPARATOR . $filename;
85+
$fixtureDir = realpath(__DIR__ . '/../../../../../Catalog/_files');
86+
copy($fixtureDir . '/' . $this->fileName, $filePath);
87+
8288
$this->model->getRequest()->setMethod('POST')
83-
->setPostValue('files', [$this->imagesHelper->idEncode($this->fileName)]);
89+
->setPostValue('files', [$this->imagesHelper->idEncode($filename)]);
8490
$this->model->getStorage()->getSession()->setCurrentPath($this->fullDirectoryPath);
8591
$this->model->execute();
8692

8793
$this->assertFalse(
8894
$this->mediaDirectory->isExist(
89-
$this->mediaDirectory->getRelativePath($this->fullDirectoryPath . '/' . $this->fileName)
95+
$this->mediaDirectory->getRelativePath($this->fullDirectoryPath . '/' . $filename)
9096
)
9197
);
9298
}
9399

100+
/**
101+
* DataProvider for testExecute
102+
*
103+
* @return array
104+
*/
105+
public function executeDataProvider(): array
106+
{
107+
return [
108+
['name with spaces.jpg'],
109+
['name with, comma.jpg'],
110+
['name with* asterisk.jpg'],
111+
['name with[ bracket.jpg'],
112+
['magento_small_image.jpg'],
113+
['_.jpg'],
114+
[' - .jpg'],
115+
['-.jpg'],
116+
];
117+
}
118+
94119
/**
95120
* Check that htaccess file couldn't be removed via
96121
* \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\DeleteFiles::execute method

dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/grid/columns/image-preview.test.js

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,26 @@ define([
1313

1414
describe('Ui/js/grid/columns/image-preview', function () {
1515
var record = {
16-
_rowIndex: 1,
17-
rowNumber: 1
18-
},
19-
imagePreview;
16+
_rowIndex: 1,
17+
rowNumber: 1
18+
},
19+
imagePreview,
20+
recordMock = {
21+
_rowIndex: 2
22+
},
23+
secondRecordMock = {
24+
_rowIndex: 1,
25+
rowNumber: 1
26+
},
27+
elementMock = {
28+
keyCode: 37
29+
},
30+
masonryMock = {
31+
shows: jasmine.createSpy().and.returnValue([]),
32+
rows: jasmine.createSpy().and.returnValue({
33+
1: secondRecordMock
34+
})
35+
};
2036

2137
beforeEach(function () {
2238
imagePreview = new Preview();
@@ -46,5 +62,36 @@ define([
4662
});
4763

4864
});
65+
66+
describe('handleKeyDown method', function () {
67+
68+
it('verify record changed on key down', function () {
69+
var imageMock = document.createElement('img'),
70+
originMock = $.fn.get;
71+
72+
spyOn($.fn, 'get').and.returnValue(imageMock);
73+
imagePreview.visibleRecord = jasmine.createSpy().and.returnValue(2);
74+
imagePreview.displayedRecord = ko.observable();
75+
imagePreview.displayedRecord(recordMock);
76+
imagePreview.masonry = jasmine.createSpy().and.returnValue(masonryMock);
77+
imagePreview.handleKeyDown(elementMock);
78+
expect(imagePreview.displayedRecord()._rowIndex).toBe(secondRecordMock._rowIndex);
79+
80+
$.fn.get = originMock;
81+
});
82+
83+
it('verify record not changed on key down when active element input', function () {
84+
var input = $('<input id=\'input-fixture\'/>');
85+
86+
$(document.body).append(input);
87+
input.focus();
88+
imagePreview.visibleRecord = jasmine.createSpy().and.returnValue(1);
89+
imagePreview.displayedRecord = ko.observable(1);
90+
imagePreview.handleKeyDown(elementMock);
91+
expect(imagePreview.displayedRecord()).toBe(1);
92+
93+
$('#input-fixture').remove();
94+
});
95+
});
4996
});
5097
});

0 commit comments

Comments
 (0)