FIX Delete of website page need permission. Conflict with mass action.

This commit is contained in:
Laurent Destailleur 2020-06-03 00:46:09 +02:00
parent 3755c7d25b
commit d4db1836d1
4 changed files with 93 additions and 24 deletions

View File

@ -878,7 +878,10 @@ if (!$error && $massaction == 'cancelorders')
setEventMessages($langs->trans("ErrorObjectMustHaveStatusValidToBeCanceled", $cmd->ref), null, 'errors');
$error++;
break;
} else $result = $cmd->cancel();
} else {
// TODO We do not provide warehouse so no stock change here for the moment.
$result = $cmd->cancel();
}
if ($result < 0)
{

View File

@ -4036,18 +4036,18 @@ class Form
* print '});'."\n";
* print '</script>'."\n";
*
* @param string $page Url of page to call if confirmation is OK. Can contains parameters (param 'action' and 'confirm' will be reformated)
* @param string $title Title
* @param string $question Question
* @param string $action Action
* @param array $formquestion An array with complementary inputs to add into forms: array(array('label'=> ,'type'=> , ))
* type can be 'hidden', 'text', 'password', 'checkbox', 'radio', 'date', 'morecss', ...
* @param string $selectedchoice '' or 'no', or 'yes' or '1' or '0'
* @param int|string $useajax 0=No, 1=Yes, 2=Yes but submit page with &confirm=no if choice is No, 'xxx'=Yes and preoutput confirm box with div id=dialog-confirm-xxx
* @param int $height Force height of box (0 = auto)
* @param int $width Force width of box ('999' or '90%'). Ignored and forced to 90% on smartphones.
* @param int $disableformtag 1=Disable form tag. Can be used if we are already inside a <form> section.
* @return string HTML ajax code if a confirm ajax popup is required, Pure HTML code if it's an html form
* @param string $page Url of page to call if confirmation is OK. Can contains parameters (param 'action' and 'confirm' will be reformated)
* @param string $title Title
* @param string $question Question
* @param string $action Action
* @param array|string $formquestion An array with complementary inputs to add into forms: array(array('label'=> ,'type'=> , ))
* type can be 'hidden', 'text', 'password', 'checkbox', 'radio', 'date', 'morecss', ...
* @param string $selectedchoice '' or 'no', or 'yes' or '1' or '0'
* @param int|string $useajax 0=No, 1=Yes, 2=Yes but submit page with &confirm=no if choice is No, 'xxx'=Yes and preoutput confirm box with div id=dialog-confirm-xxx
* @param int $height Force height of box (0 = auto)
* @param int $width Force width of box ('999' or '90%'). Ignored and forced to 90% on smartphones.
* @param int $disableformtag 1=Disable form tag. Can be used if we are already inside a <form> section.
* @return string HTML ajax code if a confirm ajax popup is required, Pure HTML code if it's an html form
*/
public function formconfirm($page, $title, $question, $action, $formquestion = '', $selectedchoice = '', $useajax = 0, $height = 0, $width = 500, $disableformtag = 0)
{
@ -4193,7 +4193,7 @@ class Form
}
// Show JQuery confirm box.
$formconfirm .= '<div id="'.$dialogconfirm.'" title="'.dol_escape_htmltag($title).'" style="display: none;">';
if (!empty($formquestion['text'])) {
if (is_array($formquestion) && !empty($formquestion['text'])) {
$formconfirm .= '<div class="confirmtext">'.$formquestion['text'].'</div>'."\n";
}
if (!empty($more)) {
@ -4288,7 +4288,7 @@ class Form
$formconfirm .= '<tr class="validtitre"><td class="validtitre" colspan="3">'.img_picto('', 'recent').' '.$title.'</td></tr>'."\n";
// Line text
if (!empty($formquestion['text'])) {
if (is_array($formquestion) && !empty($formquestion['text'])) {
$formconfirm .= '<tr class="valid"><td class="valid" colspan="3">'.$formquestion['text'].'</td></tr>'."\n";
}

View File

@ -206,6 +206,8 @@ function dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage)
$tplcontent .= '<?php if ($website->use_manifest) { print \'<link rel="manifest" href="/manifest.json.php" />\'."\n"; } ?>'."\n";
$tplcontent .= '<!-- Include link to CSS file -->'."\n";
$tplcontent .= '<link rel="stylesheet" href="/styles.css.php?website=<?php echo $websitekey; ?>" type="text/css" />'."\n";
$tplcontent .= '<!-- Include link to JS file -->'."\n";
$tplcontent .= '<script src="/javascript.js.php"></script>'."\n";
$tplcontent .= '<!-- Include HTML header from common file -->'."\n";
$tplcontent .= '<?php print preg_replace(\'/<\/?html>/ims\', \'\', file_get_contents(DOL_DATA_ROOT."/website/".$websitekey."/htmlheader.html")); ?>'."\n";
$tplcontent .= '<!-- Include HTML header from page header block -->'."\n";
@ -330,7 +332,7 @@ function dolSaveCssFile($filecss, $csscontent)
}
/**
* Save content of a page on disk
* Save content of a page on disk. For example into documents/website/mywebsite/javascript.js.php file.
*
* @param string $filejs Full path of filename to generate
* @param string $jscontent Content of file

View File

@ -293,7 +293,7 @@ if ($action == 'replacesiteconfirm') {
}
$usercanedit = $user->rights->website->write;
$permissiontodelete = $user->rights->website->delete;
/*
@ -386,12 +386,12 @@ if ($massaction == 'replace' && GETPOST('confirmmassaction', 'alpha') && !$searc
if ($massaction == 'setcategory' && GETPOST('confirmmassaction', 'alpha') && $usercanedit)
{
$error = 0;
$nbupdate = 0;
$db->begin();
$categoryid = GETPOST('setcategory', 'none');
if ($categoryid > 0) {
$nbupdate = 0;
$tmpwebsitepage = new WebsitePage($db);
$category = new Categorie($db);
$category->fetch($categoryid);
@ -1153,9 +1153,8 @@ if ($action == 'confirm_deletesite' && $confirm == 'yes')
}
}
// Delete page
if ($action == 'delete')
{
// Delete page (from website page menu)
if (GETPOSTISSET('pageid') && $action == 'delete' && $permissiontodelete) {
$error = 0;
$db->begin();
@ -1188,6 +1187,62 @@ if ($action == 'delete')
dol_print_error($db);
}
}
// Delete page (from menu search)
if (! GETPOSTISSET('pageid')) {
$objectclass = 'WebsitePage';
// Add part of code from actions_massactions.inc.php
// Delete record from mass action (massaction = 'delete' for direct delete, action/confirm='delete'/'yes' with a confirmation step before)
if (!$error && ($massaction == 'delete' || ($action == 'delete' && $confirm == 'yes')) && $permissiontodelete)
{
$db->begin();
$objecttmp = new $objectclass($db);
$nbok = 0;
foreach ($toselect as $toselectid)
{
$result = $objecttmp->fetch($toselectid);
if ($result > 0)
{
$result = $objecttmp->delete($user);
if ($result <= 0)
{
setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
$error++;
break;
} else $nbok++;
} else {
setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
$error++;
break;
}
}
if (!$error)
{
if ($nbok > 1) setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs');
else setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs');
$db->commit();
} else {
$db->rollback();
}
//var_dump($listofobjectthirdparties);exit;
}
if ($action == 'delete') {
$action = 'replacesiteconfirm';
$containertype = GETPOST('optioncontainertype', 'aZ09') != '-1' ? GETPOST('optioncontainertype', 'aZ09') : '';
$langcode = GETPOST('optionlanguage', 'aZ09');
$otherfilters = array();
if (GETPOST('optioncategory', 'int') > 0) {
$otherfilters['category'] = GETPOST('optioncategory', 'int');
}
$listofpages = getPagesFromSearchCriterias($containertype, $algo, $searchkey, 1000, $sortfield, $sortorder, $langcode, $otherfilters);
}
}
// Update css Update site properties
if ($action == 'updatecss')
@ -2391,7 +2446,7 @@ if (!GETPOST('hide_websitemenu'))
// Toolbar for pages
if ($websitekey && $websitekey != '-1' && !in_array($action, array('editcss', 'editmenu', 'importsite')))
if ($websitekey && $websitekey != '-1' && !in_array($action, array('editcss', 'editmenu', 'importsite', 'file_manager', 'replacesite', 'replacesiteconfirm')))
{
print '</div>'; // Close current websitebar to open a new one
@ -2931,7 +2986,10 @@ if ($action == 'editcss')
// JS file
print '<tr><td class="tdtop">';
print $langs->trans('WEBSITE_JS_INLINE');
$textwithhelp = $langs->trans('WEBSITE_JS_INLINE');
$htmlhelp2 = $langs->trans("LinkAndScriptsHereAreNotLoadedInEditor").'<br>';
print $form->textwithpicto($textwithhelp, $htmlhelp2, 1, 'warning', '', 0, 2, 'htmljstooltip2');
print '</td><td>';
$doleditor = new DolEditor('WEBSITE_JS_INLINE', $jscontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '');
@ -3688,7 +3746,7 @@ if ($action == 'replacesite' || $action == 'replacesiteconfirm' || $massaction =
$param = '';
$nbtotalofrecords = count($listofpages['list']);
$num = $limit;
$permissiontodelete = 0;
$permissiontodelete = $user->rights->website->delete;
// List of mass actions available
$arrayofmassactions = array();
@ -3715,6 +3773,12 @@ if ($action == 'replacesite' || $action == 'replacesiteconfirm' || $massaction =
print_barre_liste($langs->trans("Results"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'generic', 0, '', '', $limit, 1, 1, 1);
$topicmail = "WebsitePageRef";
$modelmail = "websitepage_send";
$objecttmp = new WebsitePage($db);
$trackid = 'wsp'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
$param = 'action=replacesiteconfirm&website='.urlencode($website->ref);
$param .= '&searchstring='.urlencode($searchkey);
if (GETPOST('optioncontent')) $param .= '&optioncontent=content';