Skip to content

Commit

Permalink
Fix missing tests on permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Sep 3, 2024
1 parent e7c0913 commit c79f72f
Show file tree
Hide file tree
Showing 20 changed files with 116 additions and 102 deletions.
4 changes: 1 addition & 3 deletions htdocs/compta/sociales/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,7 @@
$formconfirm = $hookmanager->resPrint;
}

/*
* View card
*/

print dol_get_fiche_head($head, 'card', $langs->trans("SocialContribution"), -1, 'bill', 0, '', '', 0, '', 1);

// Print form confirm
Expand Down
2 changes: 1 addition & 1 deletion htdocs/contact/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@
$uploaddir = $conf->societe->dir_output;
include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';

if ($action == 'setstcomm') {
if ($action == 'setstcomm' && $permissiontoadd) {
$object = new Contact($db);
$result = $object->fetch(GETPOST('stcommcontactid'));
$object->stcomm_id = dol_getIdFromCode($db, GETPOST('stcomm', 'alpha'), 'c_stcommcontact');
Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/ajax/check_notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
* Actions
*/

if ($action == 'stopreminder') {
if ($action == 'stopreminder') { // Test on permission not required here. Endpoint can be called
dol_syslog("Clear notification for listofreminderids=".$listofreminderids);
$listofreminderid = GETPOST('listofreminderids', 'intcomma');

Expand Down
21 changes: 13 additions & 8 deletions htdocs/core/ajax/constantonoff.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,28 @@


/*
* View
* Actions
*/

top_httphead();

//print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";

// Registering the new value of constant
if (!empty($action) && !empty($name)) {
if ($action == 'set') {
if ($action == 'set') { // Test on permission not required here. Already done into test on user->admin in header.
dolibarr_set_const($db, $name, $value, 'chaine', 0, '', $entity);
} elseif ($action == 'del') {
} elseif ($action == 'del') { // Test on permission not required here. Already done into test on user->admin in header.
dolibarr_del_const($db, $name, $entity);
if ($entity == 1) { // Sometimes the param was saved in both entity 0 and 1. When we work on master entity, we should clean also if entity is 0
dolibarr_del_const($db, $name, 0);
}
}
} else {
http_response_code(403);
httponly_accessforbidden('Param action and name is required', 403);
}


/*
* View
*/

top_httphead();

//print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
12 changes: 8 additions & 4 deletions htdocs/ecm/index_medias.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,19 @@

$result = restrictedArea($user, 'ecm', 0);

$permissiontoread = ($user->hasRight('ecm', 'read') || $user->hasRight('mailing', 'lire') || $user->hasRight('website', 'read'));
$permissiontouploadfile = ($user->hasRight('ecm', 'setup') || $user->hasRight('mailing', 'creer') || $user->hasRight('website', 'write'));
$permissiontoadd = $permissiontouploadfile; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles


$diroutput = $conf->medias->multidir_output[$conf->entity];

$relativepath = $section_dir;
$upload_dir = preg_replace('/\/$/', '', $diroutput).'/'.preg_replace('/^\//', '', $relativepath);

$websitekey = '';

$permissiontoadd = $permissiontouploadfile; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles


/*
* Actions
Expand All @@ -124,7 +128,7 @@

$backtopage = $savbacktopage;

if ($action == 'renamefile') { // Must be after include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php'; If action were renamefile, we set it to 'file_manager'
if ($action == 'renamefile') { // Test on permission not required here. Must be after include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php'; If action were renamefile, we set it to 'file_manager'
$action = 'file_manager';
}

Expand All @@ -148,7 +152,7 @@
}

// Remove directory
if ($action == 'confirm_deletesection' && GETPOST('confirm', 'alpha') == 'yes') {
if ($action == 'confirm_deletesection' && GETPOST('confirm', 'alpha') == 'yes' && $permissiontoadd) {
$result = $ecmdir->delete($user);
setEventMessages($langs->trans("ECMSectionWasRemoved", $ecmdir->label), null, 'mesgs');

Expand All @@ -158,7 +162,7 @@
// Refresh directory view
// This refresh list of dirs, not list of files (for performance reason). List of files is refresh only if dir was not synchronized.
// To refresh content of dir with cache, just open the dir in edit mode.
if ($action == 'refreshmanual') {
if ($action == 'refreshmanual' && $permissiontoread) {
$ecmdirtmp = new EcmDirectory($db);

// This part of code is same than into file ecm/ajax/ecmdatabase.php TODO Remove duplicate
Expand Down
10 changes: 9 additions & 1 deletion htdocs/expedition/ajax/searchfrombarcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,21 @@
httponly_accessforbidden('Not allowed by restrictArea (module='.$object->module.' table_element='.$object->table_element.')');
}


/*
* Action
*/

// None


/*
* View
*/

top_httphead('application/json');

if ($action == "existbarcode" && !empty($barcode)) {
if ($action == "existbarcode" && !empty($barcode) && $user->hasRight('stock', 'lire')) {
if (!empty($mode) && $mode == "lotserial") {
$sql = "SELECT ps.fk_entrepot, ps.fk_product, p.barcode, ps.reel, pb.batch";
$sql .= " FROM ".MAIN_DB_PREFIX."product_batch as pb";
Expand Down
22 changes: 7 additions & 15 deletions htdocs/expedition/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@
setEventMessages($object->error, $object->errors, 'errors');
}
// TODO add alternative status
//} elseif ($action == 'reopen' && (!empty($user->rights->expedition->creer) || !empty($user->rights->expedition->shipping_advance->validate)))
//} elseif ($action == 'reopen' && ($user->hasRight('expedition', 'creer') || $user->hasRight('expedition', 'shipping_advance', 'validate')))
//{
// $result = $object->setStatut(0);
// if ($result < 0)
Expand All @@ -544,15 +544,7 @@
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
}
} elseif (($action == 'settracking_number'
|| $action == 'settracking_url'
|| $action == 'settrueWeight'
|| $action == 'settrueWidth'
|| $action == 'settrueHeight'
|| $action == 'settrueDepth'
|| $action == 'setshipping_method_id')
&& $user->hasRight('expedition', 'creer')
) {
} elseif (in_array($action, array('settracking_number', 'settracking_url', 'settrueWeight', 'settrueWidth', 'settrueHeight', 'settrueDepth', 'setshipping_method_id')) && $user->hasRight('expedition', 'creer')) {
// Action update
$error = 0;

Expand Down Expand Up @@ -589,23 +581,23 @@
}

$action = "";
} elseif ($action == 'classifybilled') {
} elseif ($action == 'classifybilled' && $permissiontoadd) {
$object->fetch($id);
$result = $object->setBilled();
if ($result >= 0) {
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
exit();
}
setEventMessages($object->error, $object->errors, 'errors');
} elseif ($action == 'classifyclosed') {
} elseif ($action == 'classifyclosed' && $permissiontoadd) {
$object->fetch($id);
$result = $object->setClosed();
if ($result >= 0) {
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
exit();
}
setEventMessages($object->error, $object->errors, 'errors');
} elseif ($action == 'deleteline' && !empty($line_id)) {
} elseif ($action == 'deleteline' && !empty($line_id) && $permissiontoadd) {
// delete a line
$object->fetch($id);
$lines = $object->lines;
Expand Down Expand Up @@ -640,7 +632,7 @@
} else {
setEventMessages($line->error, $line->errors, 'errors');
}
} elseif ($action == 'updateline' && $user->hasRight('expedition', 'creer') && GETPOST('save')) {
} elseif ($action == 'updateline' && $permissiontoadd && GETPOST('save')) {
// Update a line
// Clean parameters
$qty = 0;
Expand Down Expand Up @@ -876,7 +868,7 @@
header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // To redisplay the form being edited
exit();
}
} elseif ($action == 'updateline' && $user->hasRight('expedition', 'creer') && GETPOST('cancel', 'alpha') == $langs->trans("Cancel")) {
} elseif ($action == 'updateline' && $permissiontoadd && GETPOST('cancel', 'alpha') == $langs->trans("Cancel")) {
header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // To redisplay the form being edited
exit();
}
Expand Down
4 changes: 2 additions & 2 deletions htdocs/exports/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,10 @@

if (($action == 'downfield' || $action == 'upfield') && $user->hasRight('export', 'creer')) {
$pos = $array_selected[GETPOST("field")];
if ($action == 'downfield') {
if ($action == 'downfield') { // Test on permission already done
$newpos = $pos + 1;
}
if ($action == 'upfield') {
if ($action == 'upfield') { // Test on permission already done
$newpos = $pos - 1;
}
// Recherche code avec qui switcher
Expand Down
10 changes: 5 additions & 5 deletions htdocs/fourn/commande/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@
}

// Force mandatory order method
if ($action == 'commande') { // Not a real action so no permission test
if ($action == 'commande') { // Test on permission not required here
$methodecommande = GETPOSTINT('methodecommande');

if ($cancel) {
Expand Down Expand Up @@ -1546,8 +1546,8 @@
}
}

if (getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB') && $permissiontoadd) {
if ($action == 'addcontact') {
if (getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
if ($action == 'addcontact' && $permissiontoadd) {
if ($object->id > 0) {
$contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
$typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
Expand All @@ -1565,10 +1565,10 @@
setEventMessages($object->error, $object->errors, 'errors');
}
}
} elseif ($action == 'swapstatut' && $object->id > 0) {
} elseif ($action == 'swapstatut' && $object->id > 0 && $permissiontoadd) {
// bascule du statut d'un contact
$result = $object->swapContactStatus(GETPOSTINT('ligne'));
} elseif ($action == 'deletecontact' && $object->id > 0) {
} elseif ($action == 'deletecontact' && $object->id > 0 && $permissiontoadd) {
// Efface un contact
$result = $object->delete_contact(GETPOSTINT("lineid"));

Expand Down
7 changes: 3 additions & 4 deletions htdocs/fourn/facture/card-rec.php
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@
}

/*
* View
* View
*/

$help_url = '';
Expand All @@ -889,9 +889,8 @@
$now = dol_now();
$nowlasthour = dol_get_last_hour($now);

/*
* Create mode
*/
// Create mode

if ($action == 'create') {
print load_fiche_titre($langs->trans("CreateRepeatableInvoice"), '', 'bill');

Expand Down
2 changes: 1 addition & 1 deletion htdocs/fourn/facture/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -2050,7 +2050,7 @@


/*
* View
* View
*/

$form = new Form($db);
Expand Down
19 changes: 9 additions & 10 deletions htdocs/fourn/paiement/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,16 @@
accessforbidden();
}

$permissiontoadd = ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "write"));
$permissiontovalidate = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "write"))) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight("fournisseur", "supplier_invoice_advance", "validate")));
$permissiontodelete = ($user->hasRight("fournisseur", "facture", "supprimer") || $user->hasRight("supplier_invoice", "delete"));


/*
* Actions
*/

if ($action == 'setnote' && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"))) {
if ($action == 'setnote' && $permissiontoadd) {
$db->begin();

$object->fetch($id);
Expand All @@ -87,7 +91,7 @@
}
}

if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight("fournisseur", "facture", "supprimer")) {
if ($action == 'confirm_delete' && $confirm == 'yes' && $permissiontodelete) {
$db->begin();

$object->fetch($id);
Expand All @@ -102,10 +106,7 @@
}
}

if ($action == 'confirm_validate' && $confirm == 'yes' &&
((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer")))
|| (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight("fournisseur", "supplier_invoice_advance", "validate")))
) {
if ($action == 'confirm_validate' && $confirm == 'yes' && $permissiontovalidate) {
$db->begin();

$object->fetch($id);
Expand All @@ -119,7 +120,7 @@
}
}

if ($action == 'setnum_paiement' && GETPOST('num_paiement')) {
if ($action == 'setnum_paiement' && GETPOST('num_paiement') && $permissiontoadd) {
$object->fetch($id);
$res = $object->update_num(GETPOST('num_paiement'));
if ($res === 0) {
Expand All @@ -129,7 +130,7 @@
}
}

if ($action == 'setdatep' && GETPOST('datepday')) {
if ($action == 'setdatep' && GETPOST('datepday') && $permissiontoadd) {
$object->fetch($id);
$datepaye = dol_mktime(GETPOSTINT('datephour'), GETPOSTINT('datepmin'), GETPOSTINT('datepsec'), GETPOSTINT('datepmonth'), GETPOSTINT('datepday'), GETPOSTINT('datepyear'));
$res = $object->update_date($datepaye);
Expand All @@ -142,8 +143,6 @@

// Build document
$upload_dir = $conf->fournisseur->payment->dir_output;
// TODO: get the appropriate permission
$permissiontoadd = true;
include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';

// Actions to send emails
Expand Down
Loading

0 comments on commit c79f72f

Please sign in to comment.