Non-fatal SQL errors when running unit tests.
[platal.git] / classes / plsession.php
index 688f5f5..9b6f90e 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2008 Polytechnique.org                              *
+ *  Copyright (C) 2003-2010 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -103,7 +103,6 @@ abstract class PlSession
      */
     public function start($level)
     {
-        $backup = S::i($level);
         if ($this->checkAuth($level)) {
             return true;
         }
@@ -171,14 +170,23 @@ 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')) {
+        if (S::suid()) {
             return false;
         }
         $backup   = $_SESSION;
@@ -190,6 +198,9 @@ abstract class PlSession
             return false;
         }
         S::set('user', $user);
+        if (!is_null($perms)) {
+            $this->makePerms($perms, false);
+        }
         return true;
     }
 
@@ -197,7 +208,7 @@ abstract class PlSession
      */
     public function stopSUID()
     {
-        if (!S::has('suid')) {
+        if (!S::suid()) {
             return false;
         }
         $_SESSION = $_SESSION['suid'];