forked from Wavyzz/dolibarr
Debug v16 - Fix for postgresql - Fix for sql loading per module - php8
This commit is contained in:
@@ -297,7 +297,7 @@ class User extends CommonObject
|
||||
public $all_permissions_are_loaded;
|
||||
|
||||
/**
|
||||
* @var int Number of rights granted to the user
|
||||
* @var int Number of rights granted to the user. Value loaded after a getrights().
|
||||
*/
|
||||
public $nb_rights;
|
||||
|
||||
@@ -883,15 +883,18 @@ class User extends CommonObject
|
||||
$i = 0;
|
||||
while ($i < $num) {
|
||||
$obj = $this->db->fetch_object($result);
|
||||
$nid = $obj->id;
|
||||
|
||||
$sql = "DELETE FROM ".$this->db->prefix()."user_rights WHERE fk_user = ".((int) $this->id)." AND fk_id = ".((int) $nid)." AND entity = ".((int) $entity);
|
||||
if (!$this->db->query($sql)) {
|
||||
$error++;
|
||||
}
|
||||
$sql = "INSERT INTO ".$this->db->prefix()."user_rights (entity, fk_user, fk_id) VALUES (".((int) $entity).", ".((int) $this->id).", ".((int) $nid).")";
|
||||
if (!$this->db->query($sql)) {
|
||||
$error++;
|
||||
if ($obj) {
|
||||
$nid = $obj->id;
|
||||
|
||||
$sql = "DELETE FROM ".$this->db->prefix()."user_rights WHERE fk_user = ".((int) $this->id)." AND fk_id = ".((int) $nid)." AND entity = ".((int) $entity);
|
||||
if (!$this->db->query($sql)) {
|
||||
$error++;
|
||||
}
|
||||
$sql = "INSERT INTO ".$this->db->prefix()."user_rights (entity, fk_user, fk_id) VALUES (".((int) $entity).", ".((int) $this->id).", ".((int) $nid).")";
|
||||
if (!$this->db->query($sql)) {
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
$i++;
|
||||
@@ -1096,6 +1099,14 @@ class User extends CommonObject
|
||||
}
|
||||
}
|
||||
|
||||
// For avoid error
|
||||
if (!isset($this->rights) || !is_object($this->rights)) {
|
||||
$this->rights = new stdClass(); // For avoid error
|
||||
}
|
||||
if (!isset($this->rights->user) || !is_object($this->rights->user)) {
|
||||
$this->rights->user = new stdClass(); // For avoid error
|
||||
}
|
||||
|
||||
// Get permission of users + Get permissions of groups
|
||||
|
||||
// First user permissions
|
||||
@@ -1121,7 +1132,6 @@ class User extends CommonObject
|
||||
if ($resql) {
|
||||
$num = $this->db->num_rows($resql);
|
||||
$i = 0;
|
||||
|
||||
while ($i < $num) {
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
@@ -1131,9 +1141,6 @@ class User extends CommonObject
|
||||
$subperms = $obj->subperms;
|
||||
|
||||
if (!empty($perms)) {
|
||||
if (!isset($this->rights) || !is_object($this->rights)) {
|
||||
$this->rights = new stdClass(); // For avoid error
|
||||
}
|
||||
if (!empty($module)) {
|
||||
if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
|
||||
$this->rights->$module = new stdClass();
|
||||
@@ -1200,9 +1207,6 @@ class User extends CommonObject
|
||||
$subperms = $obj->subperms;
|
||||
|
||||
if (!empty($perms)) {
|
||||
if (!isset($this->rights) || !is_object($this->rights)) {
|
||||
$this->rights = new stdClass(); // For avoid error
|
||||
}
|
||||
if (!empty($module)) {
|
||||
if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
|
||||
$this->rights->$module = new stdClass();
|
||||
@@ -1232,6 +1236,63 @@ class User extends CommonObject
|
||||
$this->db->free($resql);
|
||||
}
|
||||
|
||||
// Force permission on user for admin
|
||||
if (!empty($this->admin)) {
|
||||
if (empty($this->rights->user->user)) {
|
||||
$this->rights->user->user = new stdClass();
|
||||
}
|
||||
$listofpermtotest = array('lire', 'creer', 'password', 'supprimer', 'export');
|
||||
foreach ($listofpermtotest as $permtotest) {
|
||||
if (empty($this->rights->user->user->$permtotest)) {
|
||||
$this->rights->user->user->$permtotest = 1;
|
||||
$this->nb_rights++;
|
||||
}
|
||||
}
|
||||
if (empty($this->rights->user->self)) {
|
||||
$this->rights->user->self = new stdClass();
|
||||
}
|
||||
$listofpermtotest = array('creer', 'password');
|
||||
foreach ($listofpermtotest as $permtotest) {
|
||||
if (empty($this->rights->user->self->$permtotest)) {
|
||||
$this->rights->user->self->$permtotest = 1;
|
||||
$this->nb_rights++;
|
||||
}
|
||||
}
|
||||
// Add test on advanced permissions
|
||||
if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
|
||||
if (empty($this->rights->user->user_advance)) {
|
||||
$this->rights->user->user_advance = new stdClass();
|
||||
}
|
||||
$listofpermtotest = array('readperms', 'write');
|
||||
foreach ($listofpermtotest as $permtotest) {
|
||||
if (empty($this->rights->user->user_advance->$permtotest)) {
|
||||
$this->rights->user->user_advance->$permtotest = 1;
|
||||
$this->nb_rights++;
|
||||
}
|
||||
}
|
||||
if (empty($this->rights->user->self_advance)) {
|
||||
$this->rights->user->self_advance = new stdClass();
|
||||
}
|
||||
$listofpermtotest = array('readperms', 'writeperms');
|
||||
foreach ($listofpermtotest as $permtotest) {
|
||||
if (empty($this->rights->user->self_advance->$permtotest)) {
|
||||
$this->rights->user->self_advance->$permtotest = 1;
|
||||
$this->nb_rights++;
|
||||
}
|
||||
}
|
||||
if (empty($this->rights->user->group_advance)) {
|
||||
$this->rights->user->group_advance = new stdClass();
|
||||
}
|
||||
$listofpermtotest = array('read', 'readperms', 'write', 'delete');
|
||||
foreach ($listofpermtotest as $permtotest) {
|
||||
if (empty($this->rights->user) || empty($this->rights->user->group_advance->$permtotest)) {
|
||||
$this->rights->user->group_advance->$permtotest = 1;
|
||||
$this->nb_rights++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// For backward compatibility
|
||||
if (isset($this->rights->propale) && !isset($this->rights->propal)) {
|
||||
$this->rights->propal = $this->rights->propale;
|
||||
|
||||
Reference in New Issue
Block a user