[dev] [patch] Permissions for Menus

Joe Wilson joe.wilson at mindcandy.org
Sat May 3 23:02:35 PDT 2003


The following patch provides the ability to use the permissions subsystem to
control whether a given menu option is displayed in the main Horde navigation
menu.  If the $app['status'] parameter is set to 'perm', the permission of the
user is checked for 'menu:'.$app.  If the user has read permission, the menu
item is listed as active, inactive otherwise.  For example, to allow a user to
access imp, you would create the permission "menu:imp" and give the user read
access.

Joe

Index: horde/menu.php
===================================================================
RCS file: /usr/local/cvs/horde/horde/menu.php,v
retrieving revision 2.38
diff -r2.38 menu.php
21,23c21,24
<     foreach ($registry->applications as $app => $params) {
<         if (array_key_exists('menu_parent', $params)) {
<             $children[$params['menu_parent']][$app] = $params;
---
>     foreach ($registry->listApps(array('active', 'heading', 'notoolbar')) as
$app) {
>       $menu_parent = $registry->getParam('menu_parent', $app);
>         if ($menu_parent) {
>             $children[$menu_parent][$app] = $registry->applications[$app];
29,30c30,31
<     foreach ($registry->applications as $app => $params) {
<         $tmp[$app] = $params;
---
>     foreach ($registry->listApps(array('active', 'heading', 'notoolbar')) as
$app) {
>         $tmp[$app] = $registry->applications[$app];
36c37
<                 if ($cparams['status'] == 'active') {
---
>                 if ($registry->getParam('status', $capp) == 'active') {
43c44,48
<         }
---
>         } else {
>           if ($registry->getParam('status', $app) == 'heading') {
>               unset($tmp[$app]);
>           }
>       }
Index: horde/lib/Registry.php
===================================================================
RCS file: /usr/local/cvs/horde/horde/lib/Registry.php,v
retrieving revision 1.150
diff -r1.150 Registry.php
179c179,180
<             if (in_array($params['status'], $filter)) {
---
>           $status = $this->getParam('status', $app);
>             if (in_array($status, $filter)) {
756a758,768
>
>       if ($parameter == 'status' && $ret == 'perm') {
>               require_once HORDE_BASE . '/lib/Perms.php';
>               $perm = &Perms::singleton();
>               if ($perm->hasPermission("menu:" . $app, Auth::getAuth(),
_PERMS_READ)) {
>                   $ret = 'active';
>               } else {
>                   $ret = 'inactive';
>               }
>       }
>




More information about the dev mailing list