Pārlūkot izejas kodu

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

Laurent Destailleur 8 gadi atpakaļ
vecāks
revīzija
20ad359c9b

+ 17 - 12
htdocs/admin/modules.php

@@ -75,14 +75,27 @@ if ($search_version) $param.='&search_version='.urlencode($search_version);
  * Actions
  */
 
+
+if (GETPOST('buttonreset'))
+{
+    $search_keyword='';
+    $search_status='';
+    $search_nature='';
+    $search_version='';
+}
+
 if ($action == 'set' && $user->admin)
 {
-    $result=activateModule($value);
-    if ($result) setEventMessages($result, null, 'errors');
+    $resarray = activateModule($value);
+    if (! empty($resarray['errors'])) setEventMessages('', $resarray['errors'], 'errors');
 	else
 	{
-		$msg = $langs->trans('ModuleEnabledAdminMustCheckRights');
-		setEventMessages($msg, null, 'warnings');
+	    //var_dump($resarray);exit;
+	    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:''));
 	exit;
@@ -96,14 +109,6 @@ if ($action == 'reset' && $user->admin)
 	exit;
 }
 
-if (GETPOST('buttonreset'))
-{
-    $search_keyword='';
-    $search_status='';
-    $search_nature='';
-    $search_version='';
-}
-
 
 
 /*

+ 54 - 37
htdocs/core/lib/admin.lib.php

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

+ 1 - 1
htdocs/install/step5.php

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

+ 1 - 1
htdocs/langs/en_US/admin.lang

@@ -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.
 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
-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