Some API breakage:
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Mon, 22 Dec 2008 16:36:32 +0000 (17:36 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Mon, 22 Dec 2008 16:36:32 +0000 (17:36 +0100)
 * plsession officially contains an abstract *protected* method named makePerms.
 * startSUID takes an optionnal argument with destination permission level.
 * Adds S::b($key) to get a session variable as a boolean.

Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/plsession.php
classes/s.php
modules/core.php

index 688f5f5..d4549c9 100644 (file)
@@ -171,12 +171,21 @@ abstract class PlSession
      */
     abstract public function tokenAuth($login, $token);
 
+    /** Set the permissions to the given flagset.
+     *
+     * This function sets S::set('perms') with a flagset represeting the combination of
+     * $perms and $is_admin.
+     *
+     * $perms is an abstract object representing the permissions.
+     * $is_admin is a boolean, true if the current user has site-administration rights.
+     */
+    abstract protected function makePerms($perms, $is_admin);
 
     /*** SUID management ***/
 
     /** Start a new SUID session.
      */
-    public function startSUID($user)
+    public function startSUID($user, $perms = null)
     {
         if (S::has('suid')) {
             return false;
@@ -190,6 +199,9 @@ abstract class PlSession
             return false;
         }
         S::set('user', $user);
+        if (!is_null($perms)) {
+            $this->makePerms($perms, false);
+        }
         return true;
     }
 
index e14c440..ff29982 100644 (file)
@@ -49,6 +49,11 @@ class S
         return (string)S::v($key, $default);
     }
 
+    public static function b($key, $default = false)
+    {
+        return (bool)S::v($key, $default);
+    }
+
     public static function i($key, $default = 0)
     {
         $i = S::v($key, $default);
index 42b0c4c..44b4595 100644 (file)
@@ -129,8 +129,7 @@ class CoreModule extends PLModule
         if (isset($_SESSION['log'])) {
             S::logger()->log("suid_start", "login by " . S::user()->login());
         }
-        Platal::session()->startSUID(S::i('uid'));
-        Platal::session()->makePerms($level);
+        Platal::session()->startSUID(S::i('uid'), $level);
 
         pl_redirect('/');
     }