From f8b161ad3b2bd9aa5f176328fe9f2ee1b6ca9ee9 Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Sun, 27 Jul 2008 23:43:28 +0200 Subject: [PATCH] Add permission checking in the PlUser class. Signed-off-by: Florent Bruneau --- classes/pluser.php | 60 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/classes/pluser.php b/classes/pluser.php index 5b36897..1d639b2 100644 --- a/classes/pluser.php +++ b/classes/pluser.php @@ -60,6 +60,10 @@ abstract class PlUser protected $full_name = null; protected $promo = null; + // Permissions + protected $perms = null; + protected $perm_flags = null; + // Other properties are listed in this key-value hash map. protected $data = array(); @@ -105,20 +109,42 @@ abstract class PlUser * Accessors to the main properties, ie. those available as top level * object variables. */ - public function id() { return $this->user_id; } - public function login() { return $this->hruid; } + public function id() + { + return $this->user_id; + } - public function bestEmail() { return $this->bestalias; } - public function forlifeEmail() { return $this->forlife; } + public function login() + { + return $this->hruid; + } - public function displayName() { return $this->display_name; } - public function fullName() { return $this->full_name; } + public function bestEmail() + { + return $this->bestalias; + } + public function forlifeEmail() + { + return $this->forlife; + } + + public function displayName() + { + return $this->display_name; + } + public function fullName() + { + return $this->full_name; + } /** * Other properties are available directly through the $data array, or as * standard object variables, using a getter. */ - public function data() { return $this->data; } + public function data() + { + return $this->data; + } public function __get($name) { @@ -160,6 +186,26 @@ abstract class PlUser /** + * Build the permissions flags for the user. + */ + abstract protected function buildPerms(); + + /** + * Check wether the user got the given permission combination. + */ + public function checkPerms($perms) + { + if (is_null($this->perm_flags)) { + $this->buildPerms(); + } + if (is_null($this->perm_flags)) { + return false; + } + return $this->perm_flags->hasFlagCombination($perms); + } + + + /** * Returns a valid User object built from the @p id and optionnal @p values, * or returns false and calls the callback if the @p id is not valid. */ -- 2.1.4