2
0
forked from Wavyzz/dolibarr

Use the non deprecated function loadRights instead of getrights

This commit is contained in:
Laurent Destailleur
2024-08-02 10:36:43 +02:00
parent 56d4a30bdf
commit f002fb4ed1
48 changed files with 67 additions and 68 deletions

View File

@@ -200,7 +200,7 @@ class DolibarrApiAccess implements iAuthenticate
}
// User seems valid
$fuser->getrights();
$fuser->loadRights();
// Set the property $user to the $user of API
static::$user = $fuser;

View File

@@ -144,7 +144,7 @@ class Login
// Renew the hash
if (empty($tmpuser->api_key) || $reset) {
$tmpuser->getrights();
$tmpuser->loadRights();
if (!$tmpuser->hasRight('user', 'self', 'creer')) {
if (empty($tmpuser->api_key)) {
throw new RestException(403, 'No API token set for this user and user need write permission on itself to reset its API token');

View File

@@ -72,7 +72,7 @@ function check_authentication($authentication, &$error, &$errorcode, &$errorlabe
// Validation of login
if (!$error) {
$fuser->getrights(); // Load permission of user
$fuser->loadRights(); // Load permission of user
// Authentication mode
if (empty($dolibarr_main_authentication)) {

View File

@@ -2019,7 +2019,7 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it
if (!empty($reinitadminperms) && !empty($user->admin)) { // Reload permission for current user if defined
// We reload permissions
$user->clearrights();
$user->getrights();
$user->loadRights();
}
}
$this->db->free($resql);

View File

@@ -58,7 +58,7 @@ require_once DOL_DOCUMENT_ROOT.'/includes/sabre/autoload.php';
$user = new User($db);
if (isset($_SERVER['PHP_AUTH_USER']) && $_SERVER['PHP_AUTH_USER'] != '') {
$user->fetch(0, $_SERVER['PHP_AUTH_USER']);
$user->getrights();
$user->loadRights();
}
// Load translation files required by the page

View File

@@ -40,7 +40,7 @@ if ($user->socid) {
$result = restrictedArea($user, 'ecm', '');
// Load permissions
$user->getrights('ecm');
$user->loadRights('ecm');
// Get parameters
$socid = GETPOSTINT('socid');

View File

@@ -2743,7 +2743,7 @@ class ExpenseReport extends CommonObject
$currentUser = new User($db);
$currentUser->fetch($this->fk_user);
$currentUser->getrights('expensereport');
$currentUser->loadRights('expensereport');
//Clean
$qty = (float) price2num($qty);

View File

@@ -271,7 +271,7 @@ $user_id = $user->id;
if ($id > 0) {
// Charge utilisateur edite
$fuser->fetch($id, '', '', 1);
$fuser->getrights();
$fuser->loadRights();
$user_id = $fuser->id;
$search_user = $user_id;

View File

@@ -256,7 +256,7 @@ if ($resql) {
$userstatic = new User($db);
$userstatic->id = $obj->rowid;
$userstatic->getrights('fournisseur');
$userstatic->loadRights('fournisseur');
if ($userstatic->hasRight('fournisseur', 'commande', 'approuver')) {
print '<tr class="oddeven">';

View File

@@ -253,7 +253,7 @@ $user_id = $user->id;
if ($id > 0) {
// Charge utilisateur edite
$fuser->fetch($id, '', '', 1);
$fuser->getrights();
$fuser->loadRights();
$user_id = $fuser->id;
$search_employee = $user_id;

View File

@@ -79,7 +79,7 @@ $langs->load("exports");
// Check exportkey
if (empty($datatoimport)) {
$user->getrights();
$user->loadRights();
llxHeader();
print '<div class="error">Bad value for datatoimport.</div>';

View File

@@ -1471,7 +1471,7 @@ if (!defined('NOLOGIN')) {
}
// Load permissions
$user->getrights();
$user->loadRights();
}
dol_syslog("--- Access to ".(empty($_SERVER["REQUEST_METHOD"]) ? '' : $_SERVER["REQUEST_METHOD"].' ').$_SERVER["PHP_SELF"].' - action='.GETPOST('action', 'aZ09').', massaction='.GETPOST('massaction', 'aZ09').(defined('NOTOKENRENEWAL') ? ' NOTOKENRENEWAL='.constant('NOTOKENRENEWAL') : ''), LOG_NOTICE);

View File

@@ -81,7 +81,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
// Load user to have $user->conf loaded (not done by default here because of NOLOGIN constant defined) and load permission if we need to use them in CSS
/*if (empty($user->id) && !empty($_SESSION['dol_login'])) {
$user->fetch('',$_SESSION['dol_login']);
$user->getrights();
$user->loadRights();
}*/
@@ -107,5 +107,3 @@ div.mainmenu.mymodule {
.myclasscss {
/* ... */
}

View File

@@ -105,7 +105,7 @@ if (!($result > 0)) {
dol_print_error(null, $user->error);
exit;
}
$user->getrights();
$user->loadRights();
$hookmanager->initHooks(array('cli'));

View File

@@ -34,7 +34,7 @@ require_once dirname(__FILE__).'/../../htdocs/mymodule/class/myobject.class.php'
if (empty($user->id)) {
print "Load permissions for admin user nb 1\n";
$user->fetch(1);
$user->getrights();
$user->loadRights();
}
$conf->global->MAIN_DISABLE_ALL_MAILS = 1;

View File

@@ -162,7 +162,7 @@ if (!isModEnabled('agenda')) {
// Check config
if (!getDolGlobalString('MAIN_AGENDA_XCAL_EXPORTKEY')) {
$user->getrights();
$user->loadRights();
top_httphead();
@@ -189,7 +189,7 @@ if ($reshook < 0) {
} elseif (empty($reshook)) {
// Check exportkey
if (!GETPOST("exportkey") || getDolGlobalString('MAIN_AGENDA_XCAL_EXPORTKEY') != GETPOST("exportkey")) {
$user->getrights();
$user->loadRights();
top_httphead();

View File

@@ -118,7 +118,7 @@ if ($result < 0) {
exit;
}
}
$user->getrights();
$user->loadRights();
$id = GETPOST('id', 'alpha'); // We accept non numeric id. We will filter later.
@@ -180,7 +180,7 @@ if (is_array($object->lines) && (count($object->lines) > 0)) {
exit(-1);
}
}
$user->getrights();
$user->loadRights();
}
}

View File

@@ -93,7 +93,7 @@ if (getDolGlobalString('STRIPE_USER_ACCOUNT_FOR_ACTIONS')) {
// We set the user to use for all ipn actions in Dolibarr
$user = new User($db);
$user->fetch(getDolGlobalString('STRIPE_USER_ACCOUNT_FOR_ACTIONS'));
$user->getrights();
$user->loadRights();
} else {
httponly_accessforbidden('Error: Setup of module Stripe not complete for mode '.dol_escape_htmltag($service).'. The STRIPE_USER_ACCOUNT_FOR_ACTIONS is not defined.', 400, 1);
}

View File

@@ -69,7 +69,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
// and permission, so we can later calculate number of top menu ($nbtopmenuentries) according to user profile.
if (empty($user->id) && !empty($_SESSION['dol_login'])) {
$user->fetch('', $_SESSION['dol_login'], '', 1);
$user->getrights();
$user->loadRights();
// Reload menu now we have the good user (and we need the good menu to have ->showmenu('topnb') correct.
$menumanager = new MenuManager($db, empty($user->socid) ? 0 : 1);

View File

@@ -71,7 +71,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
// and permission, so we can later calculate number of top menu ($nbtopmenuentries) according to user profile.
if (empty($user->id) && !empty($_SESSION['dol_login'])) {
$user->fetch('', $_SESSION['dol_login'], '', 1);
$user->getrights();
$user->loadRights();
//$user->loadPersonalConf();
// Reload menu now we have the good user (and we need the good menu to have ->showmenu('topnb') correct.

View File

@@ -72,7 +72,7 @@ if (!$sortorder) {
$object = new User($db);
if ($id > 0 || !empty($ref)) {
$result = $object->fetch($id, $ref, '', 1);
$object->getrights();
$object->loadRights();
}
// Security check

View File

@@ -59,7 +59,7 @@ if (!isset($id) || empty($id)) {
$object = new User($db);
$object->fetch($id, '', '', 1);
$object->getrights();
$object->loadRights();
// Security check
$socid = 0;

View File

@@ -71,7 +71,7 @@ $feature2 = (($socid && $user->hasRight('user', 'self', 'creer')) ? '' : 'user')
$object = new User($db);
if ($id > 0 || !empty($ref)) {
$result = $object->fetch($id, $ref, '', 1);
$object->getrights();
$object->loadRights();
}
$account = new UserBankAccount($db);

View File

@@ -1437,7 +1437,7 @@ if ($action == 'create' || $action == 'adduserldap') {
// Check if user has rights
if (!getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
$object->getrights();
$object->loadRights();
if (empty($object->nb_rights) && $object->statut != 0 && empty($object->admin)) {
setEventMessages($langs->trans('UserHasNoPermissions'), null, 'warnings');
}

View File

@@ -1299,7 +1299,7 @@ class User extends CommonObject
$sql .= " ".$this->db->prefix()."usergroup_user as gu,";
$sql .= " ".$this->db->prefix()."rights_def as r";
$sql .= " WHERE r.id = gr.fk_id";
// @FIXME Very strange business rules. Must be alays the same than into user->getrights() user/perms.php and user/group/perms.php
// @FIXME Very strange business rules. Must be always the same than into user->loadRights() user/perms.php and user/group/perms.php
if (getDolGlobalString('MULTICOMPANY_BACKWARD_COMPATIBILITY')) {
if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
$sql .= " AND gu.entity IN (0,".$conf->entity.")";
@@ -1443,11 +1443,12 @@ class User extends CommonObject
/**
* Load permissions granted to a user->id into object user->rights
* TODO Remove this method. It has a name conflict with getRights() in CommonObject.
* TODO Remove this method. It has a name conflict with getRights() in CommonObject and was replaced in v20 with loadRights()
*
* @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
*
* @see clearrights(), delrights(), addrights(), hasRight()
* @phpstan-ignore-next-line

View File

@@ -81,7 +81,7 @@ $form = new Form($db);
if ($id > 0) {
$object = new User($db);
$object->fetch($id, '', '', 1);
$object->getrights();
$object->loadRights();
$object->fetch_clicktodial();
$person_name = !empty($object->firstname) ? $object->lastname.", ".$object->firstname : $object->lastname;

View File

@@ -102,7 +102,7 @@ if (!$sortfield) {
$object = new User($db);
if ($id > 0 || !empty($ref)) {
$result = $object->fetch($id, $ref, '', 1);
$object->getrights();
$object->loadRights();
//$upload_dir = $conf->user->multidir_output[$object->entity] . "/" . $object->id ;
// For users, the upload_dir is always $conf->user->entity for the moment
$upload_dir = $conf->user->dir_output."/".$object->id;

View File

@@ -68,7 +68,7 @@ $extrafields->fetch_name_optionals_label($object->table_element);
// Load object
include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'.
$object->getrights();
$object->loadRights();
// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
$hookmanager->initHooks(array('groupcard', 'globalcard'));

View File

@@ -44,7 +44,7 @@ if ($user->socid > 0) {
$object = new UserGroup($db);
$object->fetch($id, '', true);
$object->getrights();
$object->loadRights();
// Users/Groups management only in master entity if transverse mode
if (isModEnabled('multicompany') && $conf->entity > 1 && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {

View File

@@ -74,7 +74,7 @@ if (!$canreadperms) {
$object = new UserGroup($db);
$object->fetch($id);
$object->getrights();
$object->loadRights();
$entity = $conf->entity;
@@ -106,7 +106,7 @@ if (empty($reshook)) {
}
$user->clearrights();
$user->getrights();
$user->loadRights();
}
if ($action == 'delrights' && $caneditperms) {
@@ -122,7 +122,7 @@ if (empty($reshook)) {
}
$user->clearrights();
$user->getrights();
$user->loadRights();
}
}

View File

@@ -47,7 +47,7 @@ $result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
$object = new User($db);
$object->fetch($id, '', '', 1);
$object->getrights();
$object->loadRights();
// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
$hookmanager->initHooks(array('usercard', 'userldap', 'globalcard'));

View File

@@ -80,7 +80,7 @@ if ($id > 0 || !empty($ref)) {
if ($result <= 0) {
accessforbidden('User not found');
}
$object->getrights();
$object->loadRights();
}
// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context

View File

@@ -42,7 +42,7 @@ $langs->loadLangs(array('companies', 'members', 'bills', 'users'));
$object = new User($db);
$object->fetch($id, '', '', 1);
$object->getrights();
$object->loadRights();
// If user is not user read and no permission to read other users, we stop
if (($object->id != $user->id) && (!$user->hasRight("user", "user", "read"))) {

View File

@@ -69,7 +69,7 @@ $now = dol_now();
$object = new User($db);
if ($id > 0 || !empty($ref)) {
$result = $object->fetch($id, $ref, '', 1);
$object->getrights();
$object->loadRights();
}
$permissiontoadd = (($object->id == $user->id) || ($user->hasRight('user', 'user', 'lire')));
@@ -141,7 +141,7 @@ $form = new Form($db);
$object = new User($db);
$result = $object->fetch($id, '', '', 1);
$object->getrights();
$object->loadRights();
$title = $langs->trans("ThirdParty").' - '.$langs->trans("Notification");
if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/thirdpartynameonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->name) {

View File

@@ -69,7 +69,7 @@ $dirleft = "../core/menus/standard";
// Charge utilisateur edite
$object = new User($db);
$object->fetch($id, '', '', 1);
$object->getrights();
$object->loadRights();
// Liste des zone de recherche permanentes supportees
/* deprecated

View File

@@ -81,7 +81,7 @@ if ($user->id != $id && !$canreaduser) {
$object = new User($db);
$object->fetch($id, '', '', 1);
$object->getrights();
$object->loadRights();
$entity = $conf->entity;
@@ -111,12 +111,12 @@ if (empty($reshook)) {
// If we are changing our own permissions, we reload permissions and menu
if ($object->id == $user->id) {
$user->clearrights();
$user->getrights();
$user->loadRights();
$menumanager->loadMenu();
}
$object->clearrights();
$object->getrights();
$object->loadRights();
}
if ($action == 'delrights' && $caneditperms && $confirm == 'yes') {
@@ -130,12 +130,12 @@ if (empty($reshook)) {
// If we are changing our own permissions, we reload permissions and menu
if ($object->id == $user->id) {
$user->clearrights();
$user->getrights();
$user->loadRights();
$menumanager->loadMenu();
}
$object->clearrights();
$object->getrights();
$object->loadRights();
}
}

View File

@@ -44,7 +44,7 @@ if (empty($id) && empty($ref)) {
$object = new User($db);
if ($id > 0 || !empty($ref)) {
$result = $object->fetch($id, $ref, '', 1);
$object->getrights();
$object->loadRights();
}
// Security check

View File

@@ -297,7 +297,7 @@ function getActionComm($authentication, $id)
}
if (!$error) {
$fuser->getrights();
$fuser->loadRights();
if ($fuser->hasRight('agenda', 'allactions', 'read')) {
$actioncomm = new ActionComm($db);
@@ -393,7 +393,7 @@ function getListActionCommType($authentication)
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
if (!$error) {
$fuser->getrights();
$fuser->loadRights();
if ($fuser->hasRight('agenda', 'myactions', 'read')) {
$cactioncomm = new CActionComm($db);

View File

@@ -231,7 +231,7 @@ function getCategory($authentication, $id)
}
if (!$error) {
$fuser->getrights();
$fuser->loadRights();
$nbmax = 10;
if ($fuser->hasRight('categorie', 'lire')) {

View File

@@ -289,7 +289,7 @@ function getContact($authentication, $id, $ref_ext)
}
if (!$error) {
$fuser->getrights();
$fuser->loadRights();
$contact = new Contact($db);
$result = $contact->fetch($id, null, $ref_ext);

View File

@@ -330,7 +330,7 @@ function getInvoice($authentication, $id = 0, $ref = '', $ref_ext = '')
}
if (!$error) {
$fuser->getrights();
$fuser->loadRights();
if ($fuser->hasRight('facture', 'lire')) {
$invoice = new Facture($db);
@@ -698,7 +698,7 @@ function createInvoiceFromOrder($authentication, $id_order = '', $ref_order = ''
//////////////////////
if (!$error) {
$fuser->getrights();
$fuser->loadRights();
if ($fuser->hasRight('commande', 'lire')) {
$order = new Commande($db);

View File

@@ -407,7 +407,7 @@ function getOrder($authentication, $id = 0, $ref = '', $ref_ext = '')
}
if (!$error) {
$fuser->getrights();
$fuser->loadRights();
if ($fuser->hasRight('commande', 'lire')) {
$order = new Commande($db);
@@ -831,7 +831,7 @@ function validOrder($authentication, $id = 0, $id_warehouse = 0)
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
if (!$error) {
$fuser->getrights();
$fuser->loadRights();
if ($fuser->hasRight('commande', 'lire')) {
$order = new Commande($db);

View File

@@ -243,7 +243,7 @@ function getDocument($authentication, $modulepart, $file, $refname = '')
}
if (!$error) {
$fuser->getrights();
$fuser->loadRights();
// Suppression de la chaine de character ../ dans $original_file
$original_file = str_replace("../", "/", $original_file);

View File

@@ -392,7 +392,7 @@ function getProductOrService($authentication, $id = 0, $ref = '', $ref_ext = '',
$langcode = ($lang ? $lang : (!getDolGlobalString('MAIN_LANG_DEFAULT') ? 'auto' : $conf->global->MAIN_LANG_DEFAULT));
$langs->setDefaultLang($langcode);
$fuser->getrights();
$fuser->loadRights();
$nbmax = 10;
if ($fuser->hasRight('produit', 'lire') || $fuser->hasRight('service', 'lire')) {
@@ -1029,7 +1029,7 @@ function getProductsForCategory($authentication, $id, $lang = '')
$langcode = ($lang ? $lang : (!getDolGlobalString('MAIN_LANG_DEFAULT') ? 'auto' : $conf->global->MAIN_LANG_DEFAULT));
$langs->setDefaultLang($langcode);
$fuser->getrights();
$fuser->loadRights();
$nbmax = 10;
if ($fuser->hasRight('produit', 'lire')) {

View File

@@ -281,7 +281,7 @@ function createProject($authentication, $project)
if (!$error) {
$fuser->getrights();
$fuser->loadRights();
if ($fuser->hasRight('projet', 'creer')) {
$newobject = new Project($db);
@@ -376,7 +376,7 @@ function getProject($authentication, $id = '', $ref = '')
}
if (!$error) {
$fuser->getrights();
$fuser->loadRights();
if ($fuser->hasRight('projet', 'lire')) {
$project = new Project($db);

View File

@@ -267,7 +267,7 @@ function getSupplierInvoice($authentication, $id = 0, $ref = '', $ref_ext = '')
}
if (!$error) {
$fuser->getrights();
$fuser->loadRights();
if ($fuser->hasRight('fournisseur', 'facture', 'lire')) {
$invoice = new FactureFournisseur($db);

View File

@@ -339,7 +339,7 @@ function getThirdParty($authentication, $id = '', $ref = '', $ref_ext = '', $bar
}
if (!$error) {
$fuser->getrights();
$fuser->loadRights();
if ($fuser->hasRight('societe', 'lire')) {
$thirdparty = new Societe($db);
@@ -845,7 +845,7 @@ function deleteThirdParty($authentication, $id = '', $ref = '', $ref_ext = '')
dol_syslog("Function: deleteThirdParty 1");
if (!$error) {
$fuser->getrights();
$fuser->loadRights();
if ($fuser->hasRight('societe', 'lire') && $fuser->hasRight('societe', 'supprimer')) {
$thirdparty = new Societe($db);

View File

@@ -354,7 +354,7 @@ function getUser($authentication, $id, $ref = '', $ref_ext = '')
}
if (!$error) {
$fuser->getrights();
$fuser->loadRights();
if ($fuser->hasRight('user', 'user', 'lire')
|| ($fuser->hasRight('user', 'self', 'creer') && $id && $id == $fuser->id)
@@ -517,7 +517,7 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser)
}
if (!$error) {
$fuser->getrights();
$fuser->loadRights();
if ($fuser->hasRight('societe', 'creer')) {
$thirdparty = new Societe($db);
@@ -716,7 +716,7 @@ function setUserPassword($authentication, $shortuser)
}
if (!$error) {
$fuser->getrights();
$fuser->loadRights();
if ($fuser->hasRight('user', 'user', 'password') || $fuser->hasRight('user', 'self', 'password')) {
$userstat = new User($db);