Fix permissions on external users

This commit is contained in:
Laurent Destailleur 2024-05-02 21:48:50 +02:00
parent 50aa16c270
commit 577491b799
6 changed files with 45 additions and 27 deletions

View file

@ -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 = '';

View file

@ -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'
);

View file

@ -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 .= '</td></tr>'."\n";
} else {
$statstring = '';
if (isModEnabled('societe') && $user->hasRight('societe', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS') && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS_STATS')) {
$statstring = "<tr>";
$statstring .= "<tr>";
$statstring .= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=p">'.$langs->trans("Prospects").'</a></td><td class="right">'.round($third['prospect']).'</td>';
$statstring .= "</tr>";
}
@ -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 = "<tr>";
$statstring2 .= "<tr>";
$statstring2 .= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=f">'.$langs->trans("Suppliers").'</a></td><td class="right">'.round($third['supplier']).'</td>';
$statstring2 .= "</tr>";
}

View file

@ -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

View file

@ -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 '<div class="fichecenter">';
print '<div class="fichehalfleft">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent tableforfield">';
// 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 '</table>';
print '</div>';
print '</div>';
print '<div class="clearboth"></div>';
@ -345,7 +347,7 @@ if ($object->id > 0) {
// Show break line
print '<tr class="oddeven trforbreakperms" data-hide-perms="'.$obj->module.'" data-j="'.$j.'">';
// Picto and label of module
print '<td class="maxwidthonsmartphone tdoverflowmax200 tdforbreakperms" data-hide-perms="'.$obj->module.'" title="'.dol_escape_htmltag($objMod->getName).'">';
print '<td class="maxwidthonsmartphone tdoverflowmax200 tdforbreakperms" data-hide-perms="'.$obj->module.'" title="'.dol_escape_htmltag($objMod->getName()).'">';
print img_object('', $picto, 'class="pictoobjectwidth paddingright"').' '.$objMod->getName();
print '<a name="'.$objMod->getName().'"></a>';
print '</td>';
@ -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 '<td>';
print $permlabel;
if ($langs->trans("Permission".$obj->id.'b') != "Permission".$obj->id.'b') {
print '<br><span class="opacitymedium">'.$langs->trans("Permission".$obj->id.'b').'</span>';
$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 '<br><span class="opacitymedium">'.$langs->trans("Permission".$idtouse.'b').'</span>';
}
if ($langs->trans("Permission".$obj->id.'c') != "Permission".$obj->id.'c') {
print '<br><span class="opacitymedium">'.$langs->trans("Permission".$obj->id.'c').'</span>';

View file

@ -671,8 +671,12 @@ if ($result) {
print '<td>';
}
print $permlabel;
if ($langs->trans("Permission".$obj->id.'b') != "Permission".$obj->id.'b') {
print '<br><span class="opacitymedium">'.$langs->trans("Permission".$obj->id.'b').'</span>';
$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 '<br><span class="opacitymedium">'.$langs->trans("Permission".$idtouse.'b').'</span>';
}
if ($langs->trans("Permission".$obj->id.'c') != "Permission".$obj->id.'c') {
print '<br><span class="opacitymedium">'.$langs->trans("Permission".$obj->id.'c').'</span>';