Skip to content

Commit

Permalink
Fix: 🛟Fix getrights usage & Update the documentation to suggest to us…
Browse files Browse the repository at this point in the history
…e loadRights (Dolibarr#30543)

* Qual: Update the documentation to suggest to use loadRights

# Qual: Update the documentation to suggest to use loadRights

Given the pending issues, update the documention regarding getrights to
point to loadRights.

* Fix: call loadRights on User (not getRights)
  • Loading branch information
mdeweerd authored Aug 4, 2024
1 parent 37a46a9 commit e3d3bad
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion htdocs/core/customreports.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
// $search_measures, $search_xaxis or $search_yaxis may have been defined by the parent.

if (empty($user) || empty($user->id)) {
print 'Page is called as an include but $user and its permission loaded with getrights() are not defined. We stop here.';
print 'Page is called as an include but $user and its permission loaded with loadRights() are not defined. We stop here.';
exit(-1);
}
if (empty($object)) {
Expand Down
8 changes: 4 additions & 4 deletions htdocs/user/class/api_users.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public function get($id, $includepermissions = 0)
}

if ($includepermissions) {
$this->useraccount->getRights();
$this->useraccount->loadRights();
}

return $this->_cleanObjectDatas($this->useraccount);
Expand Down Expand Up @@ -207,7 +207,7 @@ public function getByLogin($login, $includepermissions = 0)
}

if ($includepermissions) {
$this->useraccount->getRights();
$this->useraccount->loadRights();
}

return $this->_cleanObjectDatas($this->useraccount);
Expand Down Expand Up @@ -246,7 +246,7 @@ public function getByEmail($email, $includepermissions = 0)
}

if ($includepermissions) {
$this->useraccount->getRights();
$this->useraccount->loadRights();
}

return $this->_cleanObjectDatas($this->useraccount);
Expand Down Expand Up @@ -281,7 +281,7 @@ public function getInfo($includepermissions = 0)
}

if ($includepermissions) {
$this->useraccount->getRights();
$this->useraccount->loadRights();
}

$usergroup = new UserGroup($this->db);
Expand Down
12 changes: 6 additions & 6 deletions htdocs/user/class/user.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ public function __construct($db)

/**
* Load a user from database with its id or ref (login).
* This function does not load permissions, only user properties. Use getrights() for this just after the fetch.
* This function does not load permissions, only user properties. Use loadRights() for this just after the fetch.
*
* @param int $id If defined, id to used for search
* @param string $login If defined, login to used for search
Expand Down Expand Up @@ -767,7 +767,7 @@ public function loadDefaultValues()
* @param string $permlevel1 Permission level1 (Example: 'read', 'write', 'delete')
* @param string $permlevel2 Permission level2
* @return int 1 if user has permission, 0 if not.
* @see clearrights(), delrights(), getrights(), hasRight()
* @see clearrights(), delrights(), loadRights(), hasRight()
*/
public function hasRight($module, $permlevel1, $permlevel2 = '')
{
Expand Down Expand Up @@ -922,7 +922,7 @@ public function hasRight($module, $permlevel1, $permlevel2 = '')
* @param int $entity Entity to use
* @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
* @return int > 0 if OK, < 0 if KO
* @see clearrights(), delrights(), getrights(), hasRight()
* @see clearrights(), delrights(), loadRights(), hasRight()
*/
public function addrights($rid, $allmodule = '', $allperms = '', $entity = 0, $notrigger = 0)
{
Expand Down Expand Up @@ -1065,7 +1065,7 @@ public function addrights($rid, $allmodule = '', $allperms = '', $entity = 0, $n
* @param int|string $entity Entity to use. Example: '1', or '0,1', or '2,3'
* @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
* @return int > 0 if OK, < 0 if OK
* @see clearrights(), addrights(), getrights(), hasRight()
* @see clearrights(), addrights(), loadRights(), hasRight()
*/
public function delrights($rid, $allmodule = '', $allperms = '', $entity = 0, $notrigger = 0)
{
Expand Down Expand Up @@ -1183,7 +1183,7 @@ public function delrights($rid, $allmodule = '', $allperms = '', $entity = 0, $n
* Clear all permissions array of user
*
* @return void
* @see getrights(), hasRight()
* @see loadRights(), hasRight()
*/
public function clearrights()
{
Expand Down Expand Up @@ -1456,7 +1456,7 @@ public function loadRights($moduletag = '', $forcereload = 0)
* @param string $moduletag Limit permission for a particular module ('' by default means load all permissions)
* @param int $forcereload Force reload of permissions even if they were already loaded (ignore cache)
* @return void
* @deprecated
* @deprecated Use getRights
*
* @see clearrights(), delrights(), addrights(), hasRight()
* @phpstan-ignore-next-line
Expand Down

0 comments on commit e3d3bad

Please sign in to comment.