Skip to content

Commit

Permalink
Add default option for ACL rules
Browse files Browse the repository at this point in the history
  • Loading branch information
thongredweb committed May 10, 2016
1 parent ef5b36b commit 7394d30
Showing 1 changed file with 35 additions and 17 deletions.
52 changes: 35 additions & 17 deletions libraries/joomla/form/fields/rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,27 +287,39 @@ protected function getInput()
$assetRule = $assetRules->allow($action->name, $group->value);

// Build the dropdowns for the permissions sliders
if ($assetRule === null)

$inheritSelected = '';
$allowedSelected = '';
$deniedSelected = '';

// Use default option for first use of rules.
if ($assetRule === null && isset($action->default) && !$assetId)
{
$allowedSelected = ($action->default == 1) ? ' selected="selected"' : '';
$deniedSelected = ($action->default == 0) ? ' selected="selected"' : '';
}
elseif ($assetRule === true)
{
$allowedSelected = ' selected="selected"';
}
elseif ($assetRule === false)
{
// If asset Rule is not exist yet. Use default option in action if available
$html[] = '<option value=""' . (!isset($action->default) ? ' selected="selected"' : '') . '>'
. JText::_(empty($group->parent_id) && empty($component) ? 'JLIB_RULES_NOT_SET' : 'JLIB_RULES_INHERITED') . '</option>';
$html[] = '<option value="1"' . (isset($action->default) && ($action->default == 1) ? ' selected="selected"' : '') . '>'
. JText::_('JLIB_RULES_ALLOWED') . '</option>';
$html[] = '<option value="0"' . (isset($action->default) && ($action->default == 0) ? ' selected="selected"' : '') . '>'
. JText::_('JLIB_RULES_DENIED') . '</option>';
$deniedSelected = ' selected="selected"';
}
else
{
// The parent group has "Not Set", all children can rightly "Inherit" from that.
$html[] = '<option value="">'
. JText::_(empty($group->parent_id) && empty($component) ? 'JLIB_RULES_NOT_SET' : 'JLIB_RULES_INHERITED') . '</option>';
$html[] = '<option value="1"' . ($assetRule === true ? ' selected="selected"' : '') . '>' . JText::_('JLIB_RULES_ALLOWED')
. '</option>';
$html[] = '<option value="0"' . ($assetRule === false ? ' selected="selected"' : '') . '>' . JText::_('JLIB_RULES_DENIED')
. '</option>';
$inheritSelected = ' selected="selected"';
}

// The parent group has "Not Set", all children can rightly "Inherit" from that.

$html[] = '<option value=""' . $inheritSelected . '>'
. JText::_(empty($group->parent_id) && empty($component) ? 'JLIB_RULES_NOT_SET' : 'JLIB_RULES_INHERITED') . '</option>';
$html[] = '<option value="1"' . $allowedSelected . '>' . JText::_('JLIB_RULES_ALLOWED')
. '</option>';
$html[] = '<option value="0"' . $deniedSelected . '>' . JText::_('JLIB_RULES_DENIED')
. '</option>';

$html[] = '</select>&#160; ';

// If this asset's rule is allowed, but the inherited rule is deny, we have a conflict.
Expand All @@ -330,11 +342,13 @@ protected function getInput()

if (JAccess::checkGroup($group->value, 'core.admin', $assetId) !== true)
{
if ($inheritedRule === null)
if ($inheritedRule === null && $assetId)
{
$html[] = '<span class="label label-important">' . JText::_('JLIB_RULES_NOT_ALLOWED') . '</span>';
}
elseif ($inheritedRule === true)
elseif ($inheritedRule === true
|| ($inheritedRule === null && !$assetId && isset($action->default) && $action->default
== 1))
{
$html[] = '<span class="label label-success">' . JText::_('JLIB_RULES_ALLOWED') . '</span>';
}
Expand All @@ -350,6 +364,10 @@ protected function getInput()
. '</span>';
}
}
else
{
$html[] = '<span class="label label-important">' . JText::_('JLIB_RULES_NOT_ALLOWED') . '</span>';
}
}
elseif (!empty($component))
{
Expand Down

0 comments on commit 7394d30

Please sign in to comment.