From 577491b79933ef0ddb606bc6d3bad32ab7a1d282 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 2 May 2024 21:48:50 +0200 Subject: [PATCH] Fix permissions on external users --- htdocs/contact/list.php | 15 ++++++++------- htdocs/core/menus/standard/eldy.lib.php | 2 +- htdocs/societe/index.php | 7 ++++--- htdocs/user/class/user.class.php | 16 +++++++++++----- htdocs/user/group/perms.php | 24 +++++++++++++++--------- htdocs/user/perms.php | 8 ++++++-- 6 files changed, 45 insertions(+), 27 deletions(-) diff --git a/htdocs/contact/list.php b/htdocs/contact/list.php index 5a1e71d62ed..a891a27d050 100644 --- a/htdocs/contact/list.php +++ b/htdocs/contact/list.php @@ -65,7 +65,7 @@ if ($contextpage == 'poslist') { $id = GETPOSTINT('id'); $contactid = GETPOSTINT('id'); $ref = ''; // There is no ref for contacts -if ($user->socid) { +if ($user->socid > 0) { $socid = $user->socid; } $result = restrictedArea($user, 'contact', $contactid, ''); @@ -280,9 +280,9 @@ if (($id > 0 || !empty($ref)) && $action != 'add') { } } -$permissiontoread = $user->hasRight('societe', 'lire'); -$permissiontodelete = $user->hasRight('societe', 'supprimer'); -$permissiontoadd = $user->hasRight('societe', 'creer'); +$permissiontoread = $user->hasRight('societe', 'contact', 'lire'); +$permissiontodelete = $user->hasRight('societe', 'contact', 'supprimer'); +$permissiontoadd = $user->hasRight('societe', 'contact', 'creer'); if (!$permissiontoread) { accessforbidden(); @@ -424,9 +424,10 @@ if (empty($reshook)) { if ($search_priv < 0) { $search_priv = ''; } -// the user has not right to see other third-party than their own + +// The user has no rights to see other third-party than their own if (!$user->hasRight('societe', 'client', 'voir')) { - $search_sale = $user->id; + $socid = $user->socid; } @@ -534,7 +535,6 @@ if ($search_priv != '0' && $search_priv != '1') { $sql .= " AND (p.priv='1' AND p.fk_user_creat=".((int) $user->id).")"; } } - // Search on sale representative if (!empty($search_sale) && $search_sale != '-1') { if ($search_sale == -2) { @@ -766,6 +766,7 @@ $sql .= $hookmanager->resPrint; $parameters = array('fieldstosearchall' => $fieldstosearchall); $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object, $action); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; +//print $sql; // Count total nb of records $nbtotalofrecords = ''; diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index d6059d5706b..90065331e47 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -128,7 +128,7 @@ function print_eldy_menu($db, $atarget, $type_user, &$tabMenu, &$menu, $noout = ) || (isModEnabled('supplier_proposal') || isModEnabled('supplier_order') || isModEnabled('supplier_invoice')) ), - 'perms' => ($user->hasRight('societe', 'lire') || $user->hasRight('fournisseur', 'lire') || $user->hasRight('supplier_order', 'lire') || $user->hasRight('supplier_invoice', 'lire') || $user->hasRight('supplier_proposal', 'lire')), + 'perms' => ($user->hasRight('societe', 'lire') || $user->hasRight('societe', 'contact', 'lire') || $user->hasRight('fournisseur', 'lire') || $user->hasRight('supplier_order', 'lire') || $user->hasRight('supplier_invoice', 'lire') || $user->hasRight('supplier_proposal', 'lire')), 'module' => 'societe|fournisseur' ); diff --git a/htdocs/societe/index.php b/htdocs/societe/index.php index 9eebb605974..bbe3657ac21 100644 --- a/htdocs/societe/index.php +++ b/htdocs/societe/index.php @@ -49,7 +49,7 @@ if ($user->socid) { } // Security check -$result = restrictedArea($user, 'societe', 0, '', '', '', ''); +$result = restrictedArea($user, 'societe|contact', 0, '', '', '', ''); $thirdparty_static = new Societe($db); $contact_static = new Contact($db); @@ -178,8 +178,9 @@ if (!empty($conf->use_javascript_ajax) && ((round($third['prospect']) ? 1 : 0) + $thirdpartygraph .= $dolgraph->show(); $thirdpartygraph .= ''."\n"; } else { + $statstring = ''; if (isModEnabled('societe') && $user->hasRight('societe', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS') && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS_STATS')) { - $statstring = ""; + $statstring .= ""; $statstring .= ''.$langs->trans("Prospects").''.round($third['prospect']).''; $statstring .= ""; } @@ -190,7 +191,7 @@ if (!empty($conf->use_javascript_ajax) && ((round($third['prospect']) ? 1 : 0) + } $statstring2 = ''; if (((isModEnabled('fournisseur') && $user->hasRight('fournisseur', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled('supplier_order') && $user->hasRight('supplier_order', 'lire')) || (isModEnabled('supplier_invoice') && $user->hasRight('supplier_invoice', 'lire'))) && !getDolGlobalString('SOCIETE_DISABLE_SUPPLIERS_STATS')) { - $statstring2 = ""; + $statstring2 .= ""; $statstring2 .= ''.$langs->trans("Suppliers").''.round($third['supplier']).''; $statstring2 .= ""; } diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 2a8f225cd32..423d6ef12af 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -848,11 +848,17 @@ class User extends CommonObject // Special case for external user if (!empty($this->socid)) { + if ($module == 'societe' && ($permlevel1 == 'creer' || $permlevel1 == 'write')) { + return 0; // An external user never has the permission ->societe->write to see all thirdparties (always restricted to himself) + } if ($module == 'societe' && $permlevel1 == 'client' && $permlevel2 == 'voir') { return 0; // An external user never has the permission ->societe->client->voir to see all thirdparties (always restricted to himself) } - if ($module == 'societe' && ($permlevel1 == 'creer' || $permlevel1 == 'write')) { - return 0; // An external user never has the permission ->societe->write to see all thirdparties (always restricted to himself) + if ($module == 'societe' && $permlevel1 == 'export') { + return 0; // An external user never has the permission ->societe->export to see all thirdparties (always restricted to himself) + } + if ($module == 'societe' && ($permlevel1 == 'supprimer' || $permlevel1 == 'delete')) { + return 0; // An external user never has the permission ->societe->delete to see all thirdparties (always restricted to himself) } } @@ -1224,12 +1230,12 @@ class User extends CommonObject } } - // For avoid error + // More init to avoid warnings/errors if (!isset($this->rights) || !is_object($this->rights)) { - $this->rights = new stdClass(); // For avoid error + $this->rights = new stdClass(); } if (!isset($this->rights->user) || !is_object($this->rights->user)) { - $this->rights->user = new stdClass(); // For avoid error + $this->rights->user = new stdClass(); } // Get permission of users + Get permissions of groups diff --git a/htdocs/user/group/perms.php b/htdocs/user/group/perms.php index bd3dfd5e6af..1659b7d4624 100644 --- a/htdocs/user/group/perms.php +++ b/htdocs/user/group/perms.php @@ -63,6 +63,10 @@ if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) { } // Security check +$socid = 0; +if (isset($user->socid) && $user->socid > 0) { + $socid = $user->socid; +} //$result = restrictedArea($user, 'user', $id, 'usergroup', ''); if (!$canreadperms) { accessforbidden(); @@ -78,11 +82,11 @@ $entity = $conf->entity; $hookmanager->initHooks(array('groupperms', 'globalcard')); -/** +/* * Actions */ -$parameters = array(); +$parameters = array('socid' => $socid); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); @@ -210,10 +214,8 @@ if ($object->id > 0) { dol_banner_tab($object, 'id', $linkback, $user->hasRight("user", "user", "read") || $user->admin); print '
'; - print '
'; + print '
'; - - print ''; // Name (already in dol_banner, we keep it to have the GlobalGroup picto, but we should move it in dol_banner) @@ -244,7 +246,7 @@ if ($object->id > 0) { include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; print '
'; - print '
'; + print '
'; print '
'; @@ -345,7 +347,7 @@ if ($object->id > 0) { // Show break line print ''; // Picto and label of module - print ''; + print ''; print img_object('', $picto, 'class="pictoobjectwidth paddingright"').' '.$objMod->getName(); print ''; print ''; @@ -427,8 +429,12 @@ if ($object->id > 0) { $permlabel = (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && ($langs->trans("PermissionAdvanced".$obj->id) != "PermissionAdvanced".$obj->id) ? $langs->trans("PermissionAdvanced".$obj->id) : (($langs->trans("Permission".$obj->id) != "Permission".$obj->id) ? $langs->trans("Permission".$obj->id) : $langs->trans($obj->label))); print ''; print $permlabel; - if ($langs->trans("Permission".$obj->id.'b') != "Permission".$obj->id.'b') { - print '
'.$langs->trans("Permission".$obj->id.'b').''; + $idtouse = $obj->id; + if (in_array($idtouse, array(121, 122, 125, 126))) { // Force message for the 3 permission on third parties + $idtouse = 122; + } + if ($langs->trans("Permission".$idtouse.'b') != "Permission".$idtouse.'b') { + print '
'.$langs->trans("Permission".$idtouse.'b').''; } if ($langs->trans("Permission".$obj->id.'c') != "Permission".$obj->id.'c') { print '
'.$langs->trans("Permission".$obj->id.'c').''; diff --git a/htdocs/user/perms.php b/htdocs/user/perms.php index b354422fdc8..f515775090e 100644 --- a/htdocs/user/perms.php +++ b/htdocs/user/perms.php @@ -671,8 +671,12 @@ if ($result) { print ''; } print $permlabel; - if ($langs->trans("Permission".$obj->id.'b') != "Permission".$obj->id.'b') { - print '
'.$langs->trans("Permission".$obj->id.'b').''; + $idtouse = $obj->id; + if (in_array($idtouse, array(121, 122, 125, 126))) { // Force message for the 3 permission on third parties + $idtouse = 122; + } + if ($langs->trans("Permission".$idtouse.'b') != "Permission".$idtouse.'b') { + print '
'.$langs->trans("Permission".$idtouse.'b').''; } if ($langs->trans("Permission".$obj->id.'c') != "Permission".$obj->id.'c') { print '
'.$langs->trans("Permission".$obj->id.'c').'';