mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
Prepare code to allow ECM access to externale users
This commit is contained in:
parent
76014e5681
commit
b1a235b810
|
|
@ -299,6 +299,22 @@ if ($type == 'directory') {
|
|||
$filter = preg_quote((string) $search_doc_ref, '/');
|
||||
$filearray = dol_dir_list($upload_dir, "files", 1, $filter, $excludefiles, $sortfield, $sorting, 1);
|
||||
|
||||
// To allow external users,we must restrict $filearray to entries the user is a thirdparty.
|
||||
// This can be done by filtering on entries found into llx_ecm
|
||||
if ($user->socid > 0) {
|
||||
$filearrayallowedtoexternal = array(); // 'fullpath' => array(...)
|
||||
|
||||
// Search files in ECM with select filepath.filename where src_object_type = $module and src_object_type EXISTS in (select rowid from $objecttablename WERE fk_soc = '.$user->socid.' and entity in getEntity($objecttbalename)
|
||||
// TODO
|
||||
|
||||
// Now clean $filearray to keep only record also found into $filearrayallowedtoexternal.
|
||||
foreach ($filearray as $key => $val) {
|
||||
if (!in_array($upload_dir.'/'.$val['relativename'], $filearrayallowedtoexternal)) {
|
||||
unset($filearray[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$perm = $user->hasRight('ecm', 'upload');
|
||||
|
||||
$formfile->list_of_autoecmfiles($upload_dir, $filearray, $module, $param, 1, '', $perm, 1, $textifempty, $maxlengthname, $url, 1);
|
||||
|
|
|
|||
|
|
@ -115,6 +115,7 @@ if ($modulepart == 'ecm') {
|
|||
accessforbidden();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
|
|
@ -150,6 +151,7 @@ foreach ($sqltree as $keycursor => $val) {
|
|||
}
|
||||
|
||||
if (!empty($conf->use_javascript_ajax) && !getDolGlobalString('MAIN_ECM_DISABLE_JS')) {
|
||||
//
|
||||
treeOutputForAbsoluteDir($sqltree, $selecteddir, $fullpathselecteddir, $modulepart, $websitekey, $pageid, $preopened, $fullpathpreopened);
|
||||
|
||||
// TODO Find a solution to not output this code for each leaf we open
|
||||
|
|
@ -370,7 +372,7 @@ if ((!isset($mode) || $mode != 'noajax') && is_object($db)) {
|
|||
*/
|
||||
function treeOutputForAbsoluteDir($sqltree, $selecteddir, $fullpathselecteddir, $modulepart, $websitekey, $pageid, $preopened, $fullpathpreopened, $depth = 0)
|
||||
{
|
||||
global $conf, $db, $langs, $form;
|
||||
global $conf, $db, $langs, $form, $user;
|
||||
global $dolibarr_main_data_root;
|
||||
|
||||
$ecmdirstatic = new EcmDirectory($db);
|
||||
|
|
@ -379,17 +381,25 @@ function treeOutputForAbsoluteDir($sqltree, $selecteddir, $fullpathselecteddir,
|
|||
if (file_exists($fullpathselecteddir)) {
|
||||
$files = @scandir($fullpathselecteddir);
|
||||
|
||||
if (!empty($files)) {
|
||||
if (!empty($files)) { // array should have at least . and ..
|
||||
natcasesort($files);
|
||||
if (count($files) > 2) { /* The 2 accounts for . and .. */
|
||||
echo '<ul class="ecmjqft" style="display: none;">'."\n";
|
||||
|
||||
// All dirs
|
||||
foreach ($files as $file) { // $file can be '.', '..', or 'My dir' or 'My file'
|
||||
if ($file == 'temp') {
|
||||
$nboflinesshown = 0;
|
||||
foreach ($files as $file) {
|
||||
// $file can be '.', '..', 'temp', or 'My dir' or 'My file'
|
||||
if (in_array($file, array('temp', '.', '..'))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// External users are not allowed to see manual directories so we quit.
|
||||
// TODO Implement acl on directory for user groups.
|
||||
if ($user->socid > 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
$nbofsubdir = 0;
|
||||
$nboffilesinsubdir = 0;
|
||||
|
||||
|
|
@ -419,7 +429,7 @@ function treeOutputForAbsoluteDir($sqltree, $selecteddir, $fullpathselecteddir,
|
|||
}
|
||||
|
||||
//print 'modulepart='.$modulepart.' fullpathselecteddir='.$fullpathselecteddir.' - val[fullrelativename] (in database)='.$val['fullrelativename'].' - val[id]='.$val['id'].' - is_dir='.dol_is_dir($fullpathselecteddir . $file).' - file='.$file."\n";
|
||||
if ($file != '.' && $file != '..' && ((!empty($val['fullrelativename']) && $val['id'] >= 0) || dol_is_dir($fullpathselecteddir.(preg_match('/\/$/', $fullpathselecteddir) ? '' : '/').$file))) {
|
||||
if ((!empty($val['fullrelativename']) && $val['id'] >= 0) || dol_is_dir($fullpathselecteddir.(preg_match('/\/$/', $fullpathselecteddir) ? '' : '/').$file)) {
|
||||
if (empty($val['fullrelativename'])) { // If we did not find entry into database, but found a directory (dol_is_dir was ok at previous test)
|
||||
$val['fullrelativename'] = (($selecteddir && $selecteddir != '/') ? $selecteddir.'/' : '').$file;
|
||||
$val['id'] = 0;
|
||||
|
|
@ -432,6 +442,9 @@ function treeOutputForAbsoluteDir($sqltree, $selecteddir, $fullpathselecteddir,
|
|||
if (preg_match('/^'.preg_quote($val['fullrelativename'].'/', '/').'/', $preopened)) {
|
||||
$collapsedorexpanded = 'expanded';
|
||||
}
|
||||
|
||||
$nboflinesshown++;
|
||||
|
||||
print '<li class="directory '.$collapsedorexpanded.' lidirecm">'; // collapsed is opposite if expanded
|
||||
|
||||
//print '<div class="divfmdirlia inline-block">'; // Disabled, this break the javascrip component
|
||||
|
|
@ -521,6 +534,11 @@ function treeOutputForAbsoluteDir($sqltree, $selecteddir, $fullpathselecteddir,
|
|||
}
|
||||
}
|
||||
|
||||
if ($user->socid > 0 && empty($nboflinesshown)) {
|
||||
// External users are not allowed to see manual directories
|
||||
print '<li>Not directory allowed to external users.<br>ACL for external users not yet implemented.</li>';
|
||||
}
|
||||
|
||||
echo "</ul>\n";
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -956,6 +956,7 @@ class Conf extends stdClass
|
|||
$this->global->MAIN_MODULES_FOR_EXTERNAL .= ",".$key;
|
||||
}
|
||||
}
|
||||
//$this->global->MAIN_MODULES_FOR_EXTERNAL .= ",ecm";
|
||||
|
||||
// Enable select2
|
||||
if (empty($this->global->MAIN_USE_JQUERY_MULTISELECT) || $this->global->MAIN_USE_JQUERY_MULTISELECT == '1') {
|
||||
|
|
|
|||
|
|
@ -274,6 +274,7 @@ if ($action == 'convertimgwebp' && $permtoadd) {
|
|||
$action = 'file_manager';
|
||||
}
|
||||
|
||||
// List of directories
|
||||
if (empty($action) || $action == 'editfile' || $action == 'file_manager' || preg_match('/refresh/i', $action) || $action == 'delete') {
|
||||
$langs->load("ecm");
|
||||
|
||||
|
|
|
|||
|
|
@ -462,6 +462,7 @@ if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i', $act
|
|||
print '</th></tr>';
|
||||
|
||||
$showonrightsize = '';
|
||||
|
||||
// Auto section
|
||||
if (count($sectionauto)) {
|
||||
$htmltooltip = $langs->trans("ECMAreaDesc2");
|
||||
|
|
@ -473,6 +474,8 @@ if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i', $act
|
|||
print '<td colspan="6">';
|
||||
print '<div id="filetreeauto" class="ecmfiletree"><ul class="ecmjqft">';
|
||||
|
||||
$arrayofmodulesforexternalusers = explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL'));
|
||||
|
||||
$nbofentries = 0;
|
||||
$oldvallevel = 0;
|
||||
foreach ($sectionauto as $key => $val) {
|
||||
|
|
@ -480,9 +483,19 @@ if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i', $act
|
|||
continue; // If condition to show the ECM auto directory is ok
|
||||
}
|
||||
|
||||
// External users are not allowed to see manual directories so we quit.
|
||||
if ($user->socid > 0) {
|
||||
// Check if dir is allowed to external users
|
||||
//var_dump($conf->global->MAIN_MODULES_FOR_EXTERNAL);
|
||||
if (! in_array($val['module'], $arrayofmodulesforexternalusers)) {
|
||||
// Discard this entry
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
print '<li class="directory collapsed">';
|
||||
print '<a class="fmdirlia jqft ecmjqft" href="'.$_SERVER["PHP_SELF"].'?module='.urlencode($val['module']).'">';
|
||||
print $val['label'];
|
||||
print dolPrintLabel($val['label']);
|
||||
print '</a>';
|
||||
|
||||
print '<div class="ecmjqft">';
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user