Commit 37965235 authored by efalcy's avatar efalcy
Browse files

hotline #70402 fix file manager rename file or folder

parent 61bb90ca
- ticket #70402 : Administration : correction du renommage des fichiers et dossiers dans l'explorateur de fichier.
\ No newline at end of file
......@@ -403,8 +403,8 @@ class Class_AdminVarLoader extends Storm_Model_Loader {
'RESIZABLE_EXTENSIONS' => Class_AdminVar_Meta::newMultiInput($this->_('Liste des extensions de fichiers susceptibles d\'être redimensionnés.'),
['value' => 'jpg;jpeg;png;']),
'SELECTABLE_IMAGE_EXTENSIONS' => Class_AdminVar_Meta::newMultiInput($this->_('Liste des extensions d\'images susceptibles d\'être sélectionnées pour enrichir un contenu.'),
['value' => 'svg;gif;jpg;jpeg;png;geojson']),
'SELECTABLE_EXTENSIONS' => Class_AdminVar_Meta::newMultiInput($this->_('Liste des extensions susceptibles d\'être sélectionnées pour enrichir un contenu.'),
['value' => 'svg;gif;jpg;jpeg;png;geojson;pdf']),
'IMAGICK_IMAGE_COMPRESSION_QUALITY' => Class_AdminVar_Meta::newDefault($this->_('Compression d\'image utilisée dans le redimensionnement et la compression des images.'),
['value' => '90'])->bePrivate(),
......
......@@ -23,7 +23,7 @@ class Class_FileManager extends Class_Entity {
use Trait_Translator;
protected static $_file_system;
const REGEX_NAME = '/^[a-z0-9][a-z0-9_\-\. ]+$/i';
protected $_attribs = ['Id' => '',
'Realpath' => '',
'Path' => '',
......@@ -324,7 +324,7 @@ class Class_FileManager extends Class_Entity {
return false;
if ('all' == $extensions)
$extensions = Class_AdminVar::get('SELECTABLE_IMAGE_EXTENSIONS');
$extensions = Class_AdminVar::get('SELECTABLE_EXTENSIONS');
$selectable = array_map('strtolower', explode(';', $extensions));
return in_array(strtolower($this->getExtension()), $selectable);
......
......@@ -32,6 +32,8 @@ class Class_FileManager_Model {
if($instance->isDir())
$path .= '/';
$path = str_replace('"', '\"', $path);
return array_merge($this->_findProfilesContaining($instance, $path),
$this->_findArticlesContaining($path),
$this->_findDomainsContaining($path));
......
......@@ -44,7 +44,7 @@ class ZendAfi_Controller_Plugin_Manager_FileManager extends ZendAfi_Controller_P
},
'label' => $this->_('Sélectionner "%s"', $model->getName()),
'anchorOptions' => array_filter(['title' => $this->_('Sélectionner "%s"', $model->getName()),
'onclick' => "$(this).selectItemForCKEditor('" . Class_Url::relative($model->getId()) . "');"])],
'onclick' => "$(this).selectItemForCKEditor('" . Class_Url::relative(str_replace(["'", '"'], ["\'", '"'], $model->getId())) . "');"])],
['url' => ['action' => 'create',
'into' => $model->getId()],
......@@ -222,7 +222,12 @@ class ZendAfi_Controller_Plugin_Manager_FileManager extends ZendAfi_Controller_P
if (!$form->isValid($this->_getPost()))
return;
$folder = $this->_getParam('folder');
$post = $this->_getPost();
$folder = isset($post['folder'])
? $post['folder']
: $this->_getParam('folder');
$message = Class_FileManager::create($folder, $into)
? $this->_('Dossier "%s" créé.', $folder)
: $this->_('Impossible de créer le dossier "%s".', $folder);
......@@ -333,17 +338,21 @@ class ZendAfi_Controller_Plugin_Manager_FileManager extends ZendAfi_Controller_P
if (!$this->_request->isPost())
return;
if (!$form->isValid($this->_getPost()))
if (!$form->isValid($post = $this->_getPost()))
return;
$new_name = $item->isFile()
? $this->_getParam('name') . '.' . $item->getExtension()
$new_name= isset($post['name'])
? $post['name']
: $this->_getParam('name');
$new_name = $item->isFile()
? $new_name . '.' . $item->getExtension()
: $new_name;
$expected_destination = $item->getParentPath() . '/' . $new_name;
$message = ($success = Class_FileManager::rename($item, $expected_destination))
? $this->_('"%s" renommé en "%s".', $item->getBasename(), $this->_getParam('name'))
? $this->_('"%s" renommé en "%s".', $item->getBasename(), $new_name)
: $this->_('Erreur. Impossible de renommer "%s".', $item->getPath());
if($success)
......
......@@ -30,9 +30,8 @@ class ZendAfi_Form_Admin_FileManager_Folder extends ZendAfi_Form {
['label' => $this->_('Nom'),
'allowEmpty' => false,
'required' => true,
'validators' => [(new Zend_Validate_Regex('/^[a-z0-9](?:[a-z0-9_ -.]*[a-z0-9])?$/i'))
'validators' => [(new Zend_Validate_Regex(Class_FileManager::REGEX_NAME))
->setMessage($this->_('Le nom du dossier peut contenir uniquement des lettres, des chiffres et les caratères "_", "-", " ", ".". Exemple : "mon_dossier"'))]])
->addUniqDisplayGroup('new_folder');
}
}
\ No newline at end of file
......@@ -30,9 +30,8 @@ class ZendAfi_Form_Admin_FileManager_Rename extends ZendAfi_Form {
['label' => $this->_('Nom'),
'allowEmpty' => false,
'required' => true,
'validators' => [(new Zend_Validate_Regex('/^[a-z0-9](?:[a-z0-9_ -.]*[a-z0-9])?$/i'))
'validators' => [(new Zend_Validate_Regex(Class_FileManager::REGEX_NAME))
->setMessage($this->_('Le nom peut contenir uniquement des lettres, des chiffres et les caratères "_", "-", " ", ".". Exemple : "mon_fichier.2"'))]])
->addUniqDisplayGroup('rename_file');
}
}
\ No newline at end of file
......@@ -41,7 +41,7 @@ class ZendAfi_View_Helper_CkEditor extends ZendAfi_View_Helper_BaseHelper
'?' .
http_build_query(['full_screen' => 1,
'browser' => 'userfiles/image',
'selectable_extensions' => Class_AdminVar::get('SELECTABLE_IMAGE_EXTENSIONS')]);
'selectable_extensions' => Class_AdminVar::get('SELECTABLE_EXTENSIONS')]);
$config['filebrowserFlashBrowseUrl'] = $this->view->url(['module' => 'admin',
'controller' => 'file-manager'], null, true) .
......
......@@ -28,7 +28,7 @@ class ZendAfi_View_Helper_CoreFiveFileInput extends ZendAfi_View_Helper_BaseHelp
mkdir($banniere_dir);
$extensions = ($type == 'Images')
? Class_AdminVar::get('SELECTABLE_IMAGE_EXTENSIONS')
? Class_AdminVar::get('SELECTABLE_EXTENSIONS')
: Class_AdminVar::get('ALLOWED_FILES_EXTENSIONS_FOR_IMPORT');
$c5_url = $this->view->url(['module' => 'admin',
......
......@@ -1343,6 +1343,14 @@ class FileManagerControllerMoveActionWithLinkedDataIbDBTest extends FileManagerC
$this->postDispatch('/admin/file-manager/rename?item=userfiles%2Fimage%2Fwhite.png', ['name' => 'yellow.2']);
$this->assertContains('userfiles/image/yellow.2.png', $this->_top_profile->getCfgSiteParam('header_img'));
}
/** @test */
public function renameProfileImageWithDoubleQuotesShouldNotBeenUpdated() {
$this->postDispatch('/admin/file-manager/rename?item=userfiles%2Fimage%2Fwhite.png&name=wrong',
['name' => 'yell"ow.2']);
$this->assertContains('userfiles/image/white.png', $this->_top_profile->getCfgSiteParam('header_img'));
}
}
......@@ -1473,4 +1481,46 @@ class FileManagerControllerIndexRenderPopupTest extends FileManagerControllerTes
public function createButtonShouldNotContainsDataPopup() {
$this->assertNotContains('data-popup=', $this->_response->getBody());
}
}
class FileManagerControllerWithSpecialCharTest extends FileManagerControllerTestCase {
public function setUp() {
parent::setUp();
$image = (new Class_FileManager)
->setId('userfiles/my\'directory/new_image.jpg')
->setPath('userfiles/my\'directory/new_image.jpg')
->setParentPath('userfiles/my\'directory')
->setName('new_image.jpg')
->setDir(false)
->setExtension('jpg')
->setDimensions('1920x1080');
Class_FileManager::getFileSystem()
->whenCalled('directoryAt')
->with('userfiles/my\'directory/new_image.jpg')
->answers(null)
->whenCalled('fileAt')
->with('userfiles/my\'directory/new_image.jpg')
->answers($image)
->whenCalled('directoryAt')
->with('userfiles/my\'directory')
->answers(null)
->whenCalled('fileAt')
->with('userfiles/my\'directory')
->answers(null) ;
$this->dispatch('/admin/file-manager/index?browser=userfiles%2Fmy%27directory%2Fnew_image.jpg&selectable_extensions=jpg;png', true);
}
/** @test */
public function selectButtonShouldBePresent() {
$this->assertXPathContentContains('//div//a[contains(@onclick, "$(this).selectItemForCKEditor(\'/stl/userfiles/my%27directory/coffee-mug.png\');")]', 'Sélectionner', $this->_response->getBody());
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment