From 68855ce6726e3a0984727e0f3f7559555c8666c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20France?= Date: Mon, 19 Jun 2023 20:08:27 +0200 Subject: [PATCH 1/4] use user hasRight --- htdocs/adherents/subscription.php | 2 +- htdocs/categories/viewcat.php | 2 +- .../box_accountancy_last_manual_entries.php | 2 +- .../box_accountancy_suspense_account.php | 2 +- htdocs/core/lib/security.lib.php | 2 +- htdocs/expensereport/list.php | 2 +- .../recruitmentcandidature_card.php | 2 +- htdocs/societe/class/api_contacts.class.php | 4 ++-- htdocs/user/bank.php | 22 +++++++++---------- htdocs/user/class/api_users.class.php | 4 ++-- 10 files changed, 22 insertions(+), 22 deletions(-) diff --git a/htdocs/adherents/subscription.php b/htdocs/adherents/subscription.php index 03923f903a7..c2a5e9dc2d0 100644 --- a/htdocs/adherents/subscription.php +++ b/htdocs/adherents/subscription.php @@ -152,7 +152,7 @@ if (empty($reshook) && $action == 'confirm_create_thirdparty' && $confirm == 'ye } } -if (empty($reshook) && $action == 'setuserid' && ($user->rights->user->self->creer || $user->hasRight('user', 'user', 'creer'))) { +if (empty($reshook) && $action == 'setuserid' && ($user->hasRight('user', 'self', 'creer') || $user->hasRight('user', 'user', 'creer'))) { $error = 0; if (!$user->hasRight('user', 'user', 'creer')) { // If can edit only itself user, we can link to itself only if (GETPOST("userid", 'int') != $user->id && GETPOST("userid", 'int') != $object->user_id) { diff --git a/htdocs/categories/viewcat.php b/htdocs/categories/viewcat.php index 3a01c3b9c2d..06fe0954d41 100644 --- a/htdocs/categories/viewcat.php +++ b/htdocs/categories/viewcat.php @@ -1127,7 +1127,7 @@ if ($type == Categorie::TYPE_USER) { // Link to delete from category print ''; - if ($user->rights->user->user->creer) { + if ($user->hasRight('user', 'user', 'creer')) { print "id."'>"; print $langs->trans("DeleteFromCat"); print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft'); diff --git a/htdocs/core/boxes/box_accountancy_last_manual_entries.php b/htdocs/core/boxes/box_accountancy_last_manual_entries.php index 7cdb220653a..54a1dd0cb63 100644 --- a/htdocs/core/boxes/box_accountancy_last_manual_entries.php +++ b/htdocs/core/boxes/box_accountancy_last_manual_entries.php @@ -60,7 +60,7 @@ class box_accountancy_last_manual_entries extends ModeleBoxes $this->db = $db; - $this->hidden = empty($user->rights->accounting->mouvements->lire); + $this->hidden = !$user->hasRight('accounting', 'mouvements', 'lire'); } /** diff --git a/htdocs/core/boxes/box_accountancy_suspense_account.php b/htdocs/core/boxes/box_accountancy_suspense_account.php index 74a46e3f241..0a6fa06033f 100644 --- a/htdocs/core/boxes/box_accountancy_suspense_account.php +++ b/htdocs/core/boxes/box_accountancy_suspense_account.php @@ -60,7 +60,7 @@ class box_accountancy_suspense_account extends ModeleBoxes $this->db = $db; - $this->hidden = empty($user->rights->accounting->mouvements->lire); + $this->hidden = !$user->hasRight('accounting', 'mouvements', 'lire'); } /** diff --git a/htdocs/core/lib/security.lib.php b/htdocs/core/lib/security.lib.php index fe1343e5b9e..cf6112b1488 100644 --- a/htdocs/core/lib/security.lib.php +++ b/htdocs/core/lib/security.lib.php @@ -666,7 +666,7 @@ function restrictedArea(User $user, $features, $object = 0, $tableandshare = '', // Check create user permission $createuserok = 1; if (GETPOST('action', 'aZ09') == 'confirm_create_user' && GETPOST("confirm", 'aZ09') == 'yes') { - if (!$user->rights->user->user->creer) { + if (!$user->hasRight('user', 'user', 'creer')) { $createuserok = 0; } diff --git a/htdocs/expensereport/list.php b/htdocs/expensereport/list.php index bb188c3fafc..da22037e771 100644 --- a/htdocs/expensereport/list.php +++ b/htdocs/expensereport/list.php @@ -176,7 +176,7 @@ $arrayfields = array( // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php'; -$canedituser = (!empty($user->admin) || $user->rights->user->user->creer); +$canedituser = (!empty($user->admin) || $user->hasRight('user', 'user', 'creer')); $objectuser = new User($db); diff --git a/htdocs/recruitment/recruitmentcandidature_card.php b/htdocs/recruitment/recruitmentcandidature_card.php index 5a6f8a58443..f433a12d466 100644 --- a/htdocs/recruitment/recruitmentcandidature_card.php +++ b/htdocs/recruitment/recruitmentcandidature_card.php @@ -579,7 +579,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // Button to convert into a user if ($object->status == $object::STATUS_CONTRACT_SIGNED) { - if ($user->rights->user->user->creer) { + if ($user->hasRight('user', 'user', 'creer')) { $useralreadyexists = $object->fk_user; if (empty($useralreadyexists)) { print '
'.$langs->trans("CreateDolibarrLogin").'
'; diff --git a/htdocs/societe/class/api_contacts.class.php b/htdocs/societe/class/api_contacts.class.php index 9d6ed42ddb1..9aff444a242 100644 --- a/htdocs/societe/class/api_contacts.class.php +++ b/htdocs/societe/class/api_contacts.class.php @@ -380,7 +380,7 @@ class Contacts extends DolibarrApi */ public function createUser($id, $request_data = null) { - //if (!DolibarrApiAccess::$user->rights->user->user->creer) { + //if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'creer')) { //throw new RestException(401); //} @@ -394,7 +394,7 @@ class Contacts extends DolibarrApi if (!DolibarrApiAccess::$user->rights->societe->contact->lire) { throw new RestException(401, 'No permission to read contacts'); } - if (!DolibarrApiAccess::$user->rights->user->user->creer) { + if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'creer')) { throw new RestException(401, 'No permission to create user'); } diff --git a/htdocs/user/bank.php b/htdocs/user/bank.php index 346e693bd56..03c96c45bcf 100644 --- a/htdocs/user/bank.php +++ b/htdocs/user/bank.php @@ -80,7 +80,7 @@ if (empty($account->userid)) { } // Define value to know what current user can do on users -$canadduser = (!empty($user->admin) || $user->rights->user->user->creer || $user->rights->hrm->write_personal_information->write); +$canadduser = (!empty($user->admin) || $user->hasRight('user', 'user', 'creer') || $user->rights->hrm->write_personal_information->write); $canreaduser = (!empty($user->admin) || $user->rights->user->user->lire || $user->rights->hrm->read_personal_information->read); $permissiontoaddbankaccount = (!empty($user->rights->salaries->write) || !empty($user->rights->hrm->employee->write) || $user->hasRight('user', 'creer')); $permissiontoreadhr = $user->hasRight('hrm', 'read_personal_information', 'read') || $user->hasRight('hrm', 'write_personal_information', 'write'); @@ -266,7 +266,7 @@ llxHeader('', $title, $help_url); $head = user_prepare_head($object); -if ($id && $bankid && $action == 'edit' && ($user->rights->user->user->creer || $user->rights->hrm->write_personal_information->write)) { +if ($id && $bankid && $action == 'edit' && ($user->hasRight('user', 'user', 'creer') || $user->rights->hrm->write_personal_information->write)) { if ($conf->use_javascript_ajax) { print "\n