fix: report delete in the reports ajax reports a failed delete instead of success refs #7907 (#7908)

This commit is contained in:
Jash Ambaliya authored and GitHub committed 2026-11-24 22:36:15 -05:00
1 parent 0add0033e4
commit fa5c1ba199
2 files changed
+64 -2

No files matched your search

@@ -0,0 +1,62 @@
<?php
// The reports delete branch used to call $report->delete() and ignore its result, so a
// failed DELETE was reported as success. deleteRequest() now reports the failure like
// snapshots.php does. The function is extracted from the ajax script (which cannot be
// included because of its top-level request handling) and run against a stub Report.
//
// Run as: php tests/php/test_ajax_reports_delete_result.php [root] (root defaults to the repo)
namespace ZM {
class Report {
private $id;
public function __construct($id) {
$this->id = ((int)$id === 0) ? 0 : $id;
}
public function Id() { return $this->id; }
public function canEdit() { return $GLOBALS['reportCanEdit']; }
public function delete() { return $GLOBALS['reportDeleteResult']; }
}
}
namespace {
$failures = 0;
function check($name, $got, $want) {
global $failures;
if ($got === $want) {
echo "ok - $name\n";
} else {
$failures++;
echo "FAIL - $name (got ".var_export($got, true).", want ".var_export($want, true).")\n";
}
}
$root = isset($argv[1]) ? $argv[1] : __DIR__.'/../..';
$path = $root.'/web/ajax/reports.php';
$src = file_get_contents($path);
if (!preg_match('/^function deleteRequest\(.*?\n\}/ms', $src, $m)) {
echo "Could not find deleteRequest() in $path\n";
exit(1);
}
eval($m[0]);
$GLOBALS['reportCanEdit'] = true;
$GLOBALS['reportDeleteResult'] = true;
check('a delete that works reports nothing', deleteRequest(4), array());
$GLOBALS['reportDeleteResult'] = false;
$messages = deleteRequest(4);
check('a failed delete is reported', count($messages) > 0, true);
check('a failed delete mentions the report id', strpos(implode(' ', $messages), '4') !== false, true);
$GLOBALS['reportDeleteResult'] = true;
check('a missing report is reported', deleteRequest(0), array('Report not found.'));
$GLOBALS['reportCanEdit'] = false;
$messages = deleteRequest(7);
check('a denied delete reports one message', count($messages), 1);
check('a denied delete mentions permission', strpos($messages[0], 'You do not have permission') === 0, true);
echo $failures ? "\n$failures failed\n" : "\nall passed\n";
exit($failures ? 1 : 0);
}
+2 -2
View File
@@ -110,8 +110,8 @@ function deleteRequest($id) {
$message[] = 'Report not found.';
} else if (!$report->canEdit()) {
$message[] = 'You do not have permission to delete report '.$report->Id();
} else {
$report->delete();
} else if ( !$report->delete() ) {
$message[] = 'Report '.$id.' could not be deleted.';
}
return $message;