Reputation: 26421
I want to restrict components to access by Manager role in Joomla 1.5.
And it will be good if it is possible by just some line of code rather using any component / extension.
Any help will be appreciated.
Thanks
Upvotes: 1
Views: 1177
Reputation: 1
Thanks a lot, Rakesh. it works great.
Please note: in my case, the code from above: if($login_user->gid == '23') had to be changed to if($user->gid == '23') as $login_user was undefined.
Also, you have add 1 extra } at the end to match the {}.
Upvotes: -1
Reputation: 34
As you want to user custom coding to restrict components for manager only. so open the file administrator/modules/mod_menu/helper.php
On line number 167. there is a foreach for components.
$login_user = JFactory::getUser(); // <--------------object for login user------------------------->
foreach ($comps as $row)
{
if ($editAllComponents | $user->authorize('administration', 'edit', 'components', $row->option))
{
if ($row->parent == 0 && (trim($row->admin_menu_link) || array_key_exists($row->id, $subs)))
{
if($login_user->gid == '23') // <--------------check for manager------------------------->
{
$text = $lang->hasKey($row->option) ? JText::_($row->option) : $row->name;
if($text == 'Banner' or $text == 'Polls' ) // <--------------write component name which is visibal to manager only------------------------->
{
$link = $row->admin_menu_link ? "index.php?$row->admin_menu_link" : "index.php?option=$row->option";
if (array_key_exists($row->id, $subs)) {
$menu->addChild(new JMenuNode($text, $link, $row->admin_menu_img), true);
foreach ($subs[$row->id] as $sub) {
$key = $row->option.'.'.$sub->name;
$text = $lang->hasKey($key) ? JText::_($key) : $sub->name;
$link = $sub->admin_menu_link ? "index.php?$sub->admin_menu_link" : null;
$menu->addChild(new JMenuNode($text, $link, $sub->admin_menu_img));
}
$menu->getParent();
} else {
$menu->addChild(new JMenuNode($text, $link, $row->admin_menu_img));
}
}
}else // <--------------else for other group------------------------->
{
// no change in it
$text = $lang->hasKey($row->option) ? JText::_($row->option) : $row->name;
$link = $row->admin_menu_link ? "index.php?$row->admin_menu_link" : "index.php?option=$row->option";
if (array_key_exists($row->id, $subs)) {
$menu->addChild(new JMenuNode($text, $link, $row->admin_menu_img), true);
foreach ($subs[$row->id] as $sub) {
$key = $row->option.'.'.$sub->name;
$text = $lang->hasKey($key) ? JText::_($key) : $sub->name;
$link = $sub->admin_menu_link ? "index.php?$sub->admin_menu_link" : null;
$menu->addChild(new JMenuNode($text, $link, $sub->admin_menu_img));
}
$menu->getParent();
} else {
$menu->addChild(new JMenuNode($text, $link, $row->admin_menu_img));
}
}
}
}
}
Upvotes: 1
Reputation: 10609
You are not going to be able to achieve access control levels with just a few lines of code. If it was that simple, ACL would not be such a big deal.
You need an extension that allows you to manage the admin access levels. Take a look at these -
http://extensions.joomla.org/extensions/access-a-security/backend-a-full-access-control/13524
http://extensions.joomla.org/extensions/access-a-security/backend-a-full-access-control/2587
http://extensions.joomla.org/extensions/access-a-security/backend-a-full-access-control/9040 - there is also a more advanced pro version as well
Each of these should give you the control you need.
Upvotes: 1