Use permissions from account_types:
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Mon, 22 Dec 2008 16:47:36 +0000 (17:47 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Mon, 22 Dec 2008 16:47:36 +0000 (17:47 +0100)
-> logged users have the 'user' permission.
-> site administrators have the 'admin' permission.
-> other permissions comes from account_types.

Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/user.php
classes/xorgsession.php
core

index f4c2732..616ce56 100644 (file)
@@ -139,8 +139,11 @@ class User extends PlUser
                                    CONCAT(af.alias, '@{$globals->mail->domain}') AS forlife,
                                    CONCAT(ab.alias, '@{$globals->mail->domain}') AS bestalias,
                                    a.full_name, a.display_name, a.sex = 'female' AS gender,
-                                   a.email_format, a.state AS perms
+                                   a.email_format,
+                                   IF (a.state = 'active', at.perms, '') AS perms,
+                                   a.is_admin
                              FROM  accounts AS a
+                       INNER JOIN  account_types AS at ON (at.type = a.type)
                        INNER JOIN  profile_display AS d ON (d.uid = a.uid)
                         LEFT JOIN  aliases AS af ON (af.id = a.uid AND af.type = 'a_vie')
                         LEFT JOIN  aliases AS ab ON (ab.id = a.uid AND FIND_IN_SET('bestalias', ab.flags))
@@ -195,7 +198,7 @@ class User extends PlUser
         if ($this->perms === null) {
              $this->loadMainFields();
         }
-        $this->perm_flags = self::makePerms($this->perms);
+        $this->perm_flags = self::makePerms($this->perms, $this->is_admin);
     }
 
     /** Return the main profile attached with this account if any.
@@ -206,14 +209,11 @@ class User extends PlUser
     }
 
     // Return permission flags for a given permission level.
-    public static function makePerms($perms)
+    public static function makePerms($perms, $is_admin)
     {
-        $flags = new PlFlagSet();
-        if (is_null($flags) || $perms == 'disabled' || $perms == 'ext') {
-            return $flags;
-        }
+        $flags = new PlFlagSet($perms);
         $flags->addFlag(PERMS_USER);
-        if ($perms == 'admin') {
+        if ($is_admin) {
             $flags->addFlag(PERMS_ADMIN);
         }
         return $flags;
index ed3382d..c0166fd 100644 (file)
@@ -192,8 +192,9 @@ class XorgSession extends PlSession
                                     UNIX_TIMESTAMP(q.banana_last) AS banana_last, q.watch_last,
                                     q.last_version, g.g_account_name IS NOT NULL AS googleapps,
                                     UNIX_TIMESTAMP(s.start) AS lastlogin, s.host,
-                                    IF(a.is_admin, 'admin', 'user') AS perms
+                                    a.is_admin, at.perms
                               FROM  accounts        AS a
+                        INNER JOIN  account_types   AS at ON(a.type = at.type)
                         INNER JOIN  auth_user_quick AS q  ON(a.uid = q.user_id)
                          LEFT JOIN  gapps_accounts  AS g  ON(a.uid = g.l_userid AND g.g_status = 'active')
                          LEFT JOIN  logger.last_sessions AS ls ON (ls.uid = a.uid)
@@ -224,7 +225,7 @@ class XorgSession extends PlSession
         }
 
         // Finalizes the session setup.
-        S::set('perms', User::makePerms($perms));
+        $this->makePerms($perms, S::b('is_admin'));
         $this->securityChecks();
         $this->setSkin();
         $this->updateNbNotifs();
@@ -271,18 +272,9 @@ class XorgSession extends PlSession
         return null;
     }
 
-    public function makePerms($perm)
+    protected function makePerms($perm, $is_admin)
     {
-        $flags = new PlFlagSet();
-        if ($perm == 'disabled' || $perm == 'ext') {
-            S::set('perms', $flags);
-            return;
-        }
-        $flags->addFlag(PERMS_USER);
-        if ($perm == 'admin') {
-            $flags->addFlag(PERMS_ADMIN);
-        }
-        S::set('perms', $flags);
+        S::set('perms', User::makePerms($perm, $is_admin));
     }
 
     public function setSkin()
diff --git a/core b/core
index 7c8d702..db3659b 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit 7c8d7022042ef34cbf8c16531a3b5eaecf46bfd2
+Subproject commit db3659bb4a5790db592359ae50c64ae340a806dd