[gollem] [PATCH] backend permissions...

Amith Varghese amith at xalan.com
Wed Feb 11 06:28:18 PST 2004


Here's a patch that adds backend permissions to gollem (like Turba).  However
right now its only supports SHOW.  I'll add edit and delete a bit later if
there are no problems with this patch.  Let me know if there are any problems.

Amith
-------------- next part --------------
Index: gollem/lib/Gollem.php
===================================================================
RCS file: /repository/gollem/lib/Gollem.php,v
retrieving revision 1.113
diff -u -r1.113 Gollem.php
--- gollem/lib/Gollem.php	28 Jan 2004 19:28:03 -0000	1.113
+++ gollem/lib/Gollem.php	11 Feb 2004 14:09:52 -0000
@@ -56,7 +56,7 @@
                 $backend_key = array_shift(array_keys($_SESSION['gollem']));
             } else {
                 /* Determine the preferred backend. */
-                require GOLLEM_BASE . '/config/backends.php';
+                global $backends; 
                 foreach ($backends as $key => $curBackend) {
                     if (empty($backend_key) && substr($key, 0, 1) != '_') {
                         $backend_key = $key;
@@ -81,8 +81,8 @@
     function createSession($backend_key = '')
     {
         global $conf;
-
-        require GOLLEM_BASE . '/config/backends.php';
+        global $backends;
+        
         if (!empty($backend_key)) {
             $used_backends = array($backend_key => $backends[$backend_key]);
         } else {
@@ -716,4 +716,27 @@
         $notification->notify(array('listeners' => 'status'));
     }
 
+    function permissionsFilter($in, $filter, $permission = PERMS_READ)
+    {
+        global $perms;
+
+        $out = array();
+        $userID = Auth::getAuth();
+
+        switch ($filter) {
+        case 'backend':
+            foreach ($in as $backendID => $name) {
+                $backendTag = 'gollem:backends:' . $backendID;
+                if (!$perms->exists($backendTag) || $perms->hasPermission($backendTag, $userID, $permission)) {
+                    $out[$backendID] = $name;
+                }
+            }
+            break;
+
+        default:
+            $out = $in;
+        }
+
+        return $out;
+    }
 }
Index: gollem/lib/base.php
===================================================================
RCS file: /repository/gollem/lib/base.php,v
retrieving revision 1.45
diff -u -r1.45 base.php
--- gollem/lib/base.php	24 Jan 2004 20:04:36 -0000	1.45
+++ gollem/lib/base.php	11 Feb 2004 14:10:08 -0000
@@ -55,6 +55,7 @@
 // Gollem base library.
 require_once GOLLEM_BASE . '/lib/Gollem.php';
 require GOLLEM_BASE . '/config/backends.php';
+$GLOBALS['backends'] = Gollem::permissionsFilter($backends, 'backend');
 
 // Help.
 require_once HORDE_BASE . '/lib/Help.php';
Index: gollem/login.php
===================================================================
RCS file: /repository/gollem/login.php,v
retrieving revision 1.60
diff -u -r1.60 login.php
--- gollem/login.php	28 Jan 2004 07:13:46 -0000	1.60
+++ gollem/login.php	11 Feb 2004 14:10:20 -0000
@@ -50,6 +50,7 @@
 /* Set the actionID of the login form */
 $actionID = 'login';
 
+global $backends;
 $used_backends = $backends;
 $autologin = true;
 
Index: gollem/templates/prefs/columnselect.inc
===================================================================
RCS file: /repository/gollem/templates/prefs/columnselect.inc,v
retrieving revision 1.2
diff -u -r1.2 columnselect.inc
--- gollem/templates/prefs/columnselect.inc	30 Apr 2003 12:57:59 -0000	1.2
+++ gollem/templates/prefs/columnselect.inc	11 Feb 2004 14:10:35 -0000
@@ -1,6 +1,6 @@
 <?php if (!$prefs->isLocked('columns')):
 
-require GOLLEM_BASE . '/config/backends.php';
+global $backends;
 
 $sources = Gollem::string2Columns($prefs->getValue('columns'));
 


More information about the gollem mailing list