fix: address PR review findings - CSRF response, N+1 query, error handling
- togglePublished: return JSON on CSRF failure instead of die() - Conditions view: fold group/rule counts into main query as subselects instead of N+1 per-item queries - All 5 toggle-published templates: add .catch() for AJAX error feedback Claude-Session: https://claude.ai/code/session_01Jo2JpjCwfHAh2HHRSjczKq
This commit is contained in:
@@ -812,7 +812,11 @@ class DisplayController extends BaseController
|
||||
|
||||
public function togglePublished()
|
||||
{
|
||||
Session::checkToken() or die(Text::_('JINVALID_TOKEN'));
|
||||
if (!Session::checkToken())
|
||||
{
|
||||
$this->jsonResponse(['success' => false, 'message' => Text::_('JINVALID_TOKEN')]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->checkAcl('core.admin'))
|
||||
{
|
||||
|
||||
@@ -31,6 +31,12 @@ class ConditionsModel extends BaseDatabaseModel
|
||||
$db->quoteName('c.color'),
|
||||
$db->quoteName('c.match_all'),
|
||||
$db->quoteName('c.published'),
|
||||
'(SELECT COUNT(*) FROM ' . $db->quoteName('#__mokosuiteclient_conditions_groups')
|
||||
. ' WHERE ' . $db->quoteName('condition_id') . ' = ' . $db->quoteName('c.id') . ') AS group_count',
|
||||
'(SELECT COUNT(*) FROM ' . $db->quoteName('#__mokosuiteclient_conditions_rules', 'r')
|
||||
. ' INNER JOIN ' . $db->quoteName('#__mokosuiteclient_conditions_groups', 'g')
|
||||
. ' ON ' . $db->quoteName('g.id') . ' = ' . $db->quoteName('r.group_id')
|
||||
. ' WHERE ' . $db->quoteName('g.condition_id') . ' = ' . $db->quoteName('c.id') . ') AS rule_count',
|
||||
])
|
||||
->from($db->quoteName('#__mokosuiteclient_conditions', 'c'));
|
||||
|
||||
|
||||
@@ -39,12 +39,6 @@ class HtmlView extends BaseHtmlView
|
||||
$this->items = $model->getItems($this->filters, $limit, $offset);
|
||||
$this->total = $model->getTotal($this->filters);
|
||||
|
||||
foreach ($this->items as $item)
|
||||
{
|
||||
$item->group_count = $model->getGroupCount((int) $item->id);
|
||||
$item->rule_count = $model->getRuleCount((int) $item->id);
|
||||
}
|
||||
|
||||
$this->addToolbar();
|
||||
|
||||
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
|
||||
|
||||
@@ -132,6 +132,9 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
badge.className = 'mokosuite-toggle-published badge bg-' + (pub ? 'success' : 'danger');
|
||||
badge.textContent = pub ? 'Published' : 'Unpublished';
|
||||
}
|
||||
}).catch(function() {
|
||||
badge.textContent = 'Error';
|
||||
badge.className = 'mokosuite-toggle-published badge bg-warning text-dark';
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -142,6 +142,9 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
badge.className = 'mokosuite-toggle-module badge bg-' + (pub ? 'success' : 'danger');
|
||||
badge.textContent = pub ? 'Published' : 'Unpublished';
|
||||
}
|
||||
}).catch(function() {
|
||||
badge.textContent = 'Error';
|
||||
badge.className = 'mokosuite-toggle-module badge bg-warning text-dark';
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -132,6 +132,9 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
badge.className = 'mokosuite-toggle-published badge bg-' + (pub ? 'success' : 'danger');
|
||||
badge.textContent = pub ? 'Published' : 'Unpublished';
|
||||
}
|
||||
}).catch(function() {
|
||||
badge.textContent = 'Error';
|
||||
badge.className = 'mokosuite-toggle-published badge bg-warning text-dark';
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -131,6 +131,9 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
badge.className = 'mokosuite-toggle-published badge bg-' + (pub ? 'success' : 'danger');
|
||||
badge.textContent = pub ? 'Published' : 'Unpublished';
|
||||
}
|
||||
}).catch(function() {
|
||||
badge.textContent = 'Error';
|
||||
badge.className = 'mokosuite-toggle-published badge bg-warning text-dark';
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -131,6 +131,9 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
badge.className = 'mokosuite-toggle-published badge bg-' + (pub ? 'success' : 'danger');
|
||||
badge.textContent = pub ? 'Published' : 'Unpublished';
|
||||
}
|
||||
}).catch(function() {
|
||||
badge.textContent = 'Error';
|
||||
badge.className = 'mokosuite-toggle-published badge bg-warning text-dark';
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user