Skip to content

Commit

Permalink
Add closure function to check edit ID
Browse files Browse the repository at this point in the history
Signed-off-by: Roland Dalmulder <[email protected]>
  • Loading branch information
roland-d committed Jan 9, 2025
1 parent 6804539 commit f5854a5
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions www/components/com_volunteers/volunteers.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
$jlang->load('com_users', JPATH_SITE, $jlang->getDefault(), true);
$jlang->load('com_users', JPATH_SITE, null, true);

$controller = JControllerLegacy::getInstance('Volunteers');
$document = JFactory::getDocument();
$input = JFactory::getApplication()->input;

Expand All @@ -31,48 +30,54 @@
$vName = $input->getCmd('view');
$vFormat = $document->getType();
$lName = $input->getCmd('layout', 'default');
$checkEditId = function($context, $id) {
$values = (array) \JFactory::getApplication()->getUserState($context . '.id');

return in_array((int) $id, $values);
};

// Check for edit department form.
if ($vName == 'department' && $lName == 'edit' && !$controller->checkEditId('com_volunteers.edit.department', $id))
if ($vName == 'department' && $lName == 'edit' && !$checkEditId('com_volunteers.edit.department', $id))
{
// Somehow the person just went to the form - we don't allow that.
return JError::raiseError(403, JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id));
}

// Check for edit member form.
if ($vName == 'member' && $lName == 'edit' && !$controller->checkEditId('com_volunteers.edit.member', $id))
if ($vName == 'member' && $lName == 'edit' && !$checkEditId('com_volunteers.edit.member', $id))
{
// Somehow the person just went to the form - we don't allow that.
return JError::raiseError(403, JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id));
}

// Check for edit report form.
if ($vName == 'report' && $lName == 'edit' && !$controller->checkEditId('com_volunteers.edit.report', $id))
if ($vName == 'report' && $lName == 'edit' && !$checkEditId('com_volunteers.edit.report', $id))
{
// Somehow the person just went to the form - we don't allow that.
return JError::raiseError(403, JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id));
}

// Check for edit role form.
if ($vName == 'role' && $lName == 'edit' && !$controller->checkEditId('com_volunteers.edit.role', $id))
if ($vName == 'role' && $lName == 'edit' && !$checkEditId('com_volunteers.edit.role', $id))
{
// Somehow the person just went to the form - we don't allow that.
return JError::raiseError(403, JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id));
}

// Check for edit team form.
if ($vName == 'team' && $lName == 'edit' && !$controller->checkEditId('com_volunteers.edit.team', $id))
if ($vName == 'team' && $lName == 'edit' && !$checkEditId('com_volunteers.edit.team', $id))
{
// Somehow the person just went to the form - we don't allow that.
return JError::raiseError(403, JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id));
}

// Check for edit volunteer form.
if ($vName == 'volunteer' && $lName == 'edit' && !$controller->checkEditId('com_volunteers.edit.volunteer', $id))
if ($vName == 'volunteer' && $lName == 'edit' && !$checkEditId('com_volunteers.edit.volunteer', $id))
{
// Somehow the person just went to the form - we don't allow that.
return JError::raiseError(403, JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id));
}

$controller = JControllerLegacy::getInstance('Volunteers');
$controller->execute(JFactory::getApplication()->input->get('task'));
$controller->redirect();

0 comments on commit f5854a5

Please sign in to comment.