[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX][ENH] Comments: More specific error message when loading comments fails
"ushindi bienvenu \(@usbbush\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <6a15585992ceb_38192b849401a@gitlab-sidekiq-low-urgency-cpu-bound-v2-5bd7895658-sbsws.mail> |
ushindi bienvenu pushed to branch master at Tiki Wiki CMS Groupware / Tiki
Commits:
7ac76799 by NasserNgandu at 2026-05-26T08:06:52+00:00
[FIX][ENH] Comments: More specific error message when loading comments fails
---
* [FIX][ENH] Comments: More specific error message when loading comments fails
See merge request tikiwiki/tiki!10369
- - - - -
2 changed files:
- lib/core/Services/Comment/Controller.php
- lib/jquery_tiki/tiki-jquery.js
Changes:
=====================================
lib/core/Services/Comment/Controller.php
=====================================
@@ -22,6 +22,7 @@ class Services_Comment_Controller
public function action_list($input)
{
global $prefs;
+ $access = TikiLib::lib('access');
$type = $input->type->alphaspace();
if ($type === 'wiki page') {
@@ -31,17 +32,28 @@ class Services_Comment_Controller
}
$objectlib = TikiLib::lib('object');
- if ($objectId !== $input->objectId->none() || ! $objectlib->isValidObject($type, $objectId)) {
- $objectId = $input->objectId->xss();
- throw new Services_Exception(tr('Invalid %0 ID: %1', $type, $objectId), 403);
- }
-
- if (! $this->isEnabled($type, $objectId)) {
- throw new Services_Exception(tr('Comments not allowed on this page.'), 403);
- }
-
- if (! $this->canView($type, $objectId)) {
- throw new Services_Exception(tr('Permission denied.'), 403);
+ try {
+ if ($objectId !== $input->objectId->none() || ! $objectlib->isValidObject($type, $objectId)) {
+ $objectId = $input->objectId->xss();
+ throw new Services_Exception(tr('Invalid %0 ID: %1', $type, $objectId), 403);
+ }
+ if (! $this->isEnabled($type, $objectId)) {
+ throw new Services_Exception(tr('Comments not allowed on this page.'), 403);
+ }
+ if (! $this->canView($type, $objectId)) {
+ throw new Services_Exception(tr('You do not have permission to view comments.'), 403);
+ }
+ } catch (Services_Exception $e) {
+ if ($access->is_xml_http_request()) {
+ http_response_code($e->getCode() ?: 403);
+ header('Content-Type: application/json; charset=utf-8');
+ echo json_encode([
+ 'status' => 'error',
+ 'message' => $e->getMessage()
+ ]);
+ exit;
+ }
+ throw $e;
}
$commentslib = TikiLib::lib('comments');
=====================================
lib/jquery_tiki/tiki-jquery.js
=====================================
@@ -18,7 +18,18 @@ jQuery.fn.load = function (url, _data, _complete) {
var complete = function (responseText, textStatus, jqXHR) {
element.tikiModal();
if (textStatus === 'error') {
- let errorStatusMsg = tr('Error %0: %1').replace('%0', jqXHR.status).replace('%1', jqXHR.statusText);
+ let errorDetails = jqXHR.statusText;
+ if (jqXHR.responseText) {
+ try {
+ let jsonResponse = JSON.parse(jqXHR.responseText);
+ if (jsonResponse && jsonResponse.message) {
+ errorDetails = jsonResponse.message;
+ }
+ } catch (e) {
+ errorDetails = jqXHR.responseText;
+ }
+ }
+ let errorStatusMsg = tr('Error %0: %1').replace('%0', jqXHR.status).replace('%1', errorDetails);
element.html('<div class="alert alert-danger alert-dismissible" role="alert">'
+ '<button type="button" class="close btn-close" data-bs-dismiss="alert" aria-label="' + tr('Close') + '"></button>'
+ '<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>'
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/7ac76799ee8c2d341c29ab61ade80338ef01322c
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/7ac76799ee8c2d341c29ab61ade80338ef01322c
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help
_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs