Fix permission lost when enabled/disabled module.

This commit is contained in:
Laurent Destailleur 2015-04-08 17:33:38 +02:00
parent b3355df3bf
commit fc803e7000
3 changed files with 36 additions and 32 deletions

View File

@ -182,43 +182,27 @@ else if ($action == 'set_SUPPLIER_ORDER_OTHER')
$res3=1;
}*/
// TODO We add/delete permission until permission can have a condition on a global var
$r_id = 1190;
$entity = $conf->entity;
$r_desc=$langs->trans("Permission1190");
$r_modul='fournisseur';
$r_type='w';
$r_perms='commande';
$r_subperms='approve2';
$r_def=0;
// TODO We add/delete permission here until permission can have a condition on a global var
include_once DOL_DOCUMENT_ROOT.'/core/modules/modFournisseur.class.php';
$newmodule=new modFournisseur($db);
// clear default rights array
$newmodule->rights=array();
// add new right
$r=0;
$newmodule->rights[$r][0] = 1190;
$newmodule->rights[$r][1] = $langs->trans("Permission1190");
$newmodule->rights[$r][2] = 'w';
$newmodule->rights[$r][3] = 0;
$newmodule->rights[$r][4] = 'commande';
$newmodule->rights[$r][5] = 'approve2';
if ($conf->global->SUPPLIER_ORDER_DOUBLE_APPROVAL)
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."rights_def";
$sql.= " (id, entity, libelle, module, type, bydefault, perms, subperms)";
$sql.= " VALUES ";
$sql.= "(".$r_id.",".$entity.",'".$db->escape($r_desc)."','".$r_modul."','".$r_type."',".$r_def.",'".$r_perms."','".$r_subperms."')";
$resqlinsert=$db->query($sql,1);
if (! $resqlinsert)
{
if ($db->errno() != "DB_ERROR_RECORD_ALREADY_EXISTS")
{
setEventMessage($db->lasterror(),'errors');
$error++;
}
}
$newmodule->insert_permissions(1);
}
else
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."rights_def";
$sql.= " WHERE id = ".$r_id;
$resqldelete=$db->query($sql,1);
if (! $resqldelete)
{
setEventMessage($db->lasterror(),'errors');
$error++;
}
$newmodule->delete_permissions();
}
}

View File

@ -161,6 +161,14 @@ class modFournisseur extends DolibarrModules
$this->rights[$r][4] = 'commande';
$this->rights[$r][5] = 'approuver';
/*$r++;
$this->rights[$r][0] = 1191;
$this->rights[$r][1] = 'Approuver une commande fournisseur (si supérieur hiérarchique)';
$this->rights[$r][2] = 'w';
$this->rights[$r][3] = 0;
$this->rights[$r][4] = 'commande';
$this->rights[$r][5] = 'approve_ifsupervisor_advance';*/
$r++;
$this->rights[$r][0] = 1186;
$this->rights[$r][1] = 'Commander une commande fournisseur';
@ -250,6 +258,18 @@ class modFournisseur extends DolibarrModules
$this->rights[$r][4] = 'commande';
$this->rights[$r][5] = 'export';
if ($conf->global->SUPPLIER_ORDER_DOUBLE_APPROVAL)
{
$r++;
$this->rights[$r][0] = 1190;
$this->rights[$r][1] = 'Approve supplier order (second level)'; // $langs->trans("Permission1190");
$this->rights[$r][2] = 'w';
$this->rights[$r][3] = 0;
$this->rights[$r][4] = 'commande';
$this->rights[$r][5] = 'approve2';
}
// Exports
//--------
$r=0;

View File

@ -190,7 +190,7 @@ if (empty($reshook))
if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
}
if ($action == 'reopen' && $user->rights->fournisseur->commande->approuver)
if ($action == 'reopen') // no test on permission here, permission to use will depends on status
{
if (in_array($object->statut, array(1, 2, 5, 6, 7, 9)))
{