2
0
forked from Wavyzz/dolibarr

FIX Warning to grant permission must be visible only if one module add

some permissions
This commit is contained in:
Laurent Destailleur
2016-09-30 18:26:32 +02:00
parent 2f557fc09b
commit 20ad359c9b
4 changed files with 73 additions and 51 deletions

View File

@@ -75,14 +75,27 @@ if ($search_version) $param.='&search_version='.urlencode($search_version);
* Actions * Actions
*/ */
if (GETPOST('buttonreset'))
{
$search_keyword='';
$search_status='';
$search_nature='';
$search_version='';
}
if ($action == 'set' && $user->admin) if ($action == 'set' && $user->admin)
{ {
$result=activateModule($value); $resarray = activateModule($value);
if ($result) setEventMessages($result, null, 'errors'); if (! empty($resarray['errors'])) setEventMessages('', $resarray['errors'], 'errors');
else else
{ {
$msg = $langs->trans('ModuleEnabledAdminMustCheckRights'); //var_dump($resarray);exit;
setEventMessages($msg, null, 'warnings'); if ($resarray['nbperms'] > 0)
{
$msg = $langs->trans('ModuleEnabledAdminMustCheckRights');
setEventMessages($msg, null, 'warnings');
}
} }
header("Location: modules.php?mode=".$mode.$param.($page_y?'&page_y='.$page_y:'')); header("Location: modules.php?mode=".$mode.$param.($page_y?'&page_y='.$page_y:''));
exit; exit;
@@ -96,14 +109,6 @@ if ($action == 'reset' && $user->admin)
exit; exit;
} }
if (GETPOST('buttonreset'))
{
$search_keyword='';
$search_status='';
$search_nature='';
$search_version='';
}
/* /*

View File

@@ -708,7 +708,7 @@ function purgeSessions($mysessionid)
* *
* @param string $value Name of module to activate * @param string $value Name of module to activate
* @param int $withdeps Activate/Disable also all dependencies * @param int $withdeps Activate/Disable also all dependencies
* @return string Error message or ''; * @return array array('nbmodules'=>nb modules activated with success, 'errors=>array of error messages, 'nbperms'=>Nb permission added);
*/ */
function activateModule($value,$withdeps=1) function activateModule($value,$withdeps=1)
{ {
@@ -717,7 +717,7 @@ function activateModule($value,$withdeps=1)
// Check parameters // Check parameters
if (empty($value)) return 'ErrorBadParameter'; if (empty($value)) return 'ErrorBadParameter';
$ret=''; $ret=array('nbmodules'=>0, 'errors'=>array(), 'nbperms'=>0);
$modName = $value; $modName = $value;
$modFile = $modName . ".class.php"; $modFile = $modName . ".class.php";
@@ -761,50 +761,67 @@ function activateModule($value,$withdeps=1)
} }
$result=$objMod->init(); $result=$objMod->init();
if ($result <= 0) $ret=$objMod->error; if ($result <= 0)
if (! $ret && $withdeps)
{ {
if (isset($objMod->depends) && is_array($objMod->depends) && ! empty($objMod->depends)) $ret['errors'][]=$objMod->error;
}
else
{
if ($withdeps)
{ {
// Activation des modules dont le module depend if (isset($objMod->depends) && is_array($objMod->depends) && ! empty($objMod->depends))
$TError=array();
$num = count($objMod->depends);
for ($i = 0; $i < $num; $i++)
{ {
$activate = false; // Activation des modules dont le module depend
foreach ($modulesdir as $dir) $num = count($objMod->depends);
{ for ($i = 0; $i < $num; $i++)
if (file_exists($dir.$objMod->depends[$i].".class.php")) {
{ $activate = false;
activateModule($objMod->depends[$i]); foreach ($modulesdir as $dir)
$activate = true; {
} if (file_exists($dir.$objMod->depends[$i].".class.php"))
} {
$resarray = activateModule($objMod->depends[$i]);
if (!$activate) $TError[] = $langs->trans('activateModuleDependNotSatisfied', $objMod->name, $objMod->depends[$i]); if (empty($resarray['errors'])) $activate = true;
break;
}
}
if ($activate)
{
$ret['nbmodules']+=$resarray['nbmodules'];
$ret['nbperms']+=$resarray['nbperms'];
}
else
{
$ret['errors'][] = $langs->trans('activateModuleDependNotSatisfied', $objMod->name, $objMod->depends[$i]);
}
}
} }
setEventMessages('', $TError, 'errors'); if (isset($objMod->conflictwith) && is_array($objMod->conflictwith) && ! empty($objMod->conflictwith))
}
if (isset($objMod->conflictwith) && is_array($objMod->conflictwith) && ! empty($objMod->conflictwith))
{
// Desactivation des modules qui entrent en conflit
$num = count($objMod->conflictwith);
for ($i = 0; $i < $num; $i++)
{ {
foreach ($modulesdir as $dir) // Desactivation des modules qui entrent en conflit
{ $num = count($objMod->conflictwith);
if (file_exists($dir.$objMod->conflictwith[$i].".class.php")) for ($i = 0; $i < $num; $i++)
{ {
unActivateModule($objMod->conflictwith[$i],0); foreach ($modulesdir as $dir)
} {
} if (file_exists($dir.$objMod->conflictwith[$i].".class.php"))
{
unActivateModule($objMod->conflictwith[$i],0);
}
}
}
} }
} }
} }
if (! count($ret['errors']))
{
$ret['nbmodules']++;
$ret['nbperms']+=count($objMod->rights);
}
return $ret; return $ret;
} }

View File

@@ -249,7 +249,7 @@ if ($action == "set" || empty($action) || preg_match('/upgrade/i',$action))
$res=dol_include_once("/core/modules/".$file); $res=dol_include_once("/core/modules/".$file);
$res=activateModule($modtoactivatenew,1); $res=activateModule($modtoactivatenew,1);
if (! $result) print 'ERROR in activating module file='.$file; if (! empty($res['errors'])) print 'ERROR in activating module file='.$file;
} }
} }

View File

@@ -1625,5 +1625,5 @@ activateModuleDependNotSatisfied=Module "%s" depends on module "%s" that is miss
CommandIsNotInsideAllowedCommands=The command you try to run is not inside list of allowed commands defined into parameter <strong>$dolibarr_main_restrict_os_commands</strong> into <strong>conf.php</strong> file. CommandIsNotInsideAllowedCommands=The command you try to run is not inside list of allowed commands defined into parameter <strong>$dolibarr_main_restrict_os_commands</strong> into <strong>conf.php</strong> file.
LandingPage=Landing page LandingPage=Landing page
SamePriceAlsoForSharedCompanies=If you use the multicompany module, with the choice "Single price", price will be also the same for all companies if products are shared between environments SamePriceAlsoForSharedCompanies=If you use the multicompany module, with the choice "Single price", price will be also the same for all companies if products are shared between environments
ModuleEnabledAdminMustCheckRights=Module has been activated. All permissions were given to admin users only. ModuleEnabledAdminMustCheckRights=Module has been activated. Permissions for activated module(s) were given to admin users only. You may need to grant permissions to other users manually if necessary.
UserHasNoPermissions=This user has no permission defined UserHasNoPermissions=This user has no permission defined