Elfinder - Add isAllow() function

1.10.x
Julio Montoya 10 years ago
parent f70c7cc617
commit f5f3b6c85d
  1. 10
      composer.lock
  2. 1
      src/Chamilo/CoreBundle/Component/Editor/Connector.php
  3. 130
      src/Chamilo/CoreBundle/Component/Editor/Driver/CourseDriver.php
  4. 10
      src/Chamilo/CoreBundle/Component/Editor/Driver/Driver.php
  5. 7
      src/Chamilo/CoreBundle/Component/Editor/Driver/DriverInterface.php
  6. 24
      src/Chamilo/CoreBundle/Component/Editor/Driver/HomeDriver.php
  7. 44
      src/Chamilo/CoreBundle/Component/Editor/Driver/PersonalDriver.php

10
composer.lock generated

@ -767,16 +767,16 @@
},
{
"name": "sabre/vobject",
"version": "3.3.5",
"version": "3.4.0",
"source": {
"type": "git",
"url": "https://github.com/fruux/sabre-vobject.git",
"reference": "77cb636a5bde4c19d7522c2c548b258859ddd1ef"
"reference": "20c72ddf7ae3e037ad348bbc83b477af56b9484e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fruux/sabre-vobject/zipball/77cb636a5bde4c19d7522c2c548b258859ddd1ef",
"reference": "77cb636a5bde4c19d7522c2c548b258859ddd1ef",
"url": "https://api.github.com/repos/fruux/sabre-vobject/zipball/20c72ddf7ae3e037ad348bbc83b477af56b9484e",
"reference": "20c72ddf7ae3e037ad348bbc83b477af56b9484e",
"shasum": ""
},
"require": {
@ -829,7 +829,7 @@
"jCard",
"vCard"
],
"time": "2015-01-10 00:54:52"
"time": "2015-02-23 21:12:17"
},
{
"name": "symfony/console",

@ -388,6 +388,7 @@ class Connector
/**
* @param string $driver
*
* @return string
*/
private function getDriverClass($driver)

@ -17,7 +17,7 @@ class CourseDriver extends Driver
*/
public function getConfiguration()
{
if (!empty($this->connector->course)) {
if ($this->allow()) {
//$translator = $this->connector->translator;
//$code = $this->connector->course->getCode();
$courseCode = $this->connector->course['code'];
@ -41,6 +41,8 @@ class CourseDriver extends Driver
)
);
}
return array();
}
/**
@ -51,7 +53,7 @@ class CourseDriver extends Driver
public function getCourseDocumentSysPath()
{
$url = null;
if (isset($this->connector->course)) {
if ($this->allow()) {
//$directory = $this->connector->course->getDirectory();
$directory = $this->connector->course['directory'];
$dataPath = $this->connector->paths['sys_data_path'];
@ -67,7 +69,7 @@ class CourseDriver extends Driver
public function getCourseDocumentRelativeWebPath()
{
$url = null;
if (isset($this->connector->course)) {
if ($this->allow()) {
$directory = $this->connector->course['directory'];
$url = api_get_path(REL_COURSE_PATH).$directory.'/document/';
}
@ -82,7 +84,7 @@ class CourseDriver extends Driver
public function getCourseDocumentWebPath()
{
$url = null;
if (isset($this->connector->course)) {
if ($this->allow()) {
$directory = $this->connector->course->getDirectory();
$url = api_get_path(WEB_COURSE_PATH).$directory.'/document/';
}
@ -95,43 +97,47 @@ class CourseDriver extends Driver
*/
public function upload($fp, $dst, $name, $tmpname)
{
$this->setConnectorFromPlugin();
// upload file by elfinder.
$result = parent::upload($fp, $dst, $name, $tmpname);
$name = $result['name'];
$filtered = \URLify::filter($result['name'], 80);
if (strcmp($name, $filtered) != 0) {
/*$arg = array('target' => $file['hash'], 'name' => $filtered);
$elFinder->exec('rename', $arg);*/
$this->rename($result['hash'], $filtered);
}
$realPath = $this->realpath($result['hash']);
if (!empty($realPath)) {
// Getting file info
//$info = $elFinder->exec('file', array('target' => $file['hash']));
/** @var elFinderVolumeLocalFileSystem $volume */
//$volume = $info['volume'];
//$root = $volume->root();
//var/www/chamilogits/data/courses/NEWONE/document
$realPathRoot = $this->getCourseDocumentSysPath();
// Removing course path
$realPath = str_replace($realPathRoot, '/', $realPath);
add_document(
$this->connector->course,
$realPath,
'file',
intval($result['size']),
$result['name']
);
if ($this->allow()) {
$this->setConnectorFromPlugin();
// upload file by elfinder.
$result = parent::upload($fp, $dst, $name, $tmpname);
$name = $result['name'];
$filtered = \URLify::filter($result['name'], 80);
if (strcmp($name, $filtered) != 0) {
/*$arg = array('target' => $file['hash'], 'name' => $filtered);
$elFinder->exec('rename', $arg);*/
$this->rename($result['hash'], $filtered);
}
$realPath = $this->realpath($result['hash']);
if (!empty($realPath)) {
// Getting file info
//$info = $elFinder->exec('file', array('target' => $file['hash']));
/** @var elFinderVolumeLocalFileSystem $volume */
//$volume = $info['volume'];
//$root = $volume->root();
//var/www/chamilogits/data/courses/NEWONE/document
$realPathRoot = $this->getCourseDocumentSysPath();
// Removing course path
$realPath = str_replace($realPathRoot, '/', $realPath);
add_document(
$this->connector->course,
$realPath,
'file',
intval($result['size']),
$result['name']
);
}
return $result;
}
return $result;
return false;
}
/**
@ -141,23 +147,41 @@ class CourseDriver extends Driver
{
// elfinder does not delete the file
//parent::rm($hash);
$this->setConnectorFromPlugin();
if ($this->allow()) {
$this->setConnectorFromPlugin();
$path = $this->decode($hash);
$stat = $this->stat($path);
$stat['realpath'] = $path;
$this->removed[] = $stat;
$path = $this->decode($hash);
$stat = $this->stat($path);
$stat['realpath'] = $path;
$this->removed[] = $stat;
$realFilePath = $path;
$coursePath = $this->getCourseDocumentSysPath();
$filePath = str_replace($coursePath, '/', $realFilePath);
$realFilePath = $path;
$coursePath = $this->getCourseDocumentSysPath();
$filePath = str_replace($coursePath, '/', $realFilePath);
\DocumentManager::delete_document(
$this->connector->course,
$filePath,
$coursePath
);
\DocumentManager::delete_document(
$this->connector->course,
$filePath,
$coursePath
);
return true;
return true;
}
return false;
}
/**
* @return bool
*/
public function allow()
{
//if ($this->connector->security->isGranted('ROLE_ADMIN')) {
$userId = api_get_user_id();
return
isset($this->connector->course) &&
!empty($this->connector->course) &&
!api_is_anonymous($userId, true)
;
}
}

@ -28,7 +28,7 @@ class Driver extends \elFinderVolumeLocalFileSystem implements DriverInterface
/**
* Gets driver name.
* @param string
* @param string $name
*/
public function setName($name)
{
@ -60,4 +60,12 @@ class Driver extends \elFinderVolumeLocalFileSystem implements DriverInterface
$options = $this->getAppPluginOptions();
$this->setConnector($options['connector']);
}
/**
* @return bool
*/
public function allow()
{
return false;
}
}

@ -19,7 +19,7 @@ interface DriverInterface
/**
* Gets driver name.
* @param string
* @param string $name
*/
public function setName($name);
@ -38,4 +38,9 @@ interface DriverInterface
* @return Connector
*/
public function setConnectorFromPlugin();
/**
* @return bool
*/
public function allow();
}

@ -16,8 +16,7 @@ class HomeDriver extends Driver
*/
public function getConfiguration()
{
//if ($this->connector->security->isGranted('ROLE_ADMIN')) {
if (api_is_platform_admin()) {
if ($this->allow()) {
$home = api_get_path(SYS_PATH).'home';
return array(
@ -28,6 +27,8 @@ class HomeDriver extends Driver
'accessControl' => array($this, 'access'),
);
}
return array();
}
/**
@ -35,8 +36,9 @@ class HomeDriver extends Driver
*/
public function upload($fp, $dst, $name, $tmpname)
{
$this->setConnectorFromPlugin();
if ($this->connector->security->isGranted('ROLE_ADMIN')) {
if ($this->allow()) {
$this->setConnectorFromPlugin();
return parent::upload($fp, $dst, $name, $tmpname);
}
}
@ -46,9 +48,19 @@ class HomeDriver extends Driver
*/
public function rm($hash)
{
$this->setConnectorFromPlugin();
if ($this->connector->security->isGranted('ROLE_ADMIN')) {
if ($this->allow()) {
$this->setConnectorFromPlugin();
return parent::rm($hash);
}
}
/**
* @return bool
*/
public function allow()
{
//if ($this->connector->security->isGranted('ROLE_ADMIN')) {
return api_is_platform_admin();
}
}

@ -17,25 +17,34 @@ class PersonalDriver extends Driver
*/
public function getConfiguration()
{
//if ($this->connector->security->isGranted('IS_AUTHENTICATED_FULLY')) {
if ($this->allow()) {
$userId = api_get_user_id();
if (!empty($userId)) {
// Adding user personal files
$dir = \UserManager::get_user_picture_path_by_id($userId, 'system');
$dirWeb = \UserManager::get_user_picture_path_by_id($userId, 'web');
$dir = \UserManager::get_user_picture_path_by_id(
$userId,
'system'
);
$dirWeb = \UserManager::get_user_picture_path_by_id(
$userId,
'web'
);
$driver = array(
'driver' => 'PersonalDriver',
'alias' => get_lang('MyFiles'),
'path' => $dir['dir'].'my_files',
'URL' => $dirWeb['dir'].'my_files',
'path' => $dir['dir'] . 'my_files',
'URL' => $dirWeb['dir'] . 'my_files',
'accessControl' => array($this, 'access')
);
return $driver;
}
//}
}
return array();
}
/**
@ -43,10 +52,11 @@ class PersonalDriver extends Driver
*/
public function upload($fp, $dst, $name, $tmpname)
{
$this->setConnectorFromPlugin();
//if ($this->connector->security->isGranted('IS_AUTHENTICATED_FULLY')) {
if ($this->allow()) {
$this->setConnectorFromPlugin();
return parent::upload($fp, $dst, $name, $tmpname);
//}
}
}
/**
@ -54,9 +64,19 @@ class PersonalDriver extends Driver
*/
public function rm($hash)
{
$this->setConnectorFromPlugin();
//if ($this->connector->security->isGranted('IS_AUTHENTICATED_FULLY')) {
if ($this->allow()) {
$this->setConnectorFromPlugin();
return parent::rm($hash);
//}
}
}
/**
* @return bool
*/
public function allow()
{
//if ($this->connector->security->isGranted('IS_AUTHENTICATED_FULLY')) {
return !api_is_anonymous();
}
}

Loading…
Cancel
Save