diff options
| author | Greg Roach <fisharebest@gmail.com> | 2015-03-07 11:33:29 +0000 |
|---|---|---|
| committer | Greg Roach <fisharebest@gmail.com> | 2015-03-08 16:23:35 +0000 |
| commit | 4b9ff166b3342695f2a94855b7a33368e6d55c35 (patch) | |
| tree | 0a1c31662df08206dbd7d04fe6983f438f4e6877 /app/Auth.php | |
| parent | 1784a549f5382ce854e7a2b015c1367735d8b2e0 (diff) | |
| download | webtrees-4b9ff166b3342695f2a94855b7a33368e6d55c35.tar.gz webtrees-4b9ff166b3342695f2a94855b7a33368e6d55c35.tar.bz2 webtrees-4b9ff166b3342695f2a94855b7a33368e6d55c35.zip | |
Remove constants, to improve multi-tree handling
Diffstat (limited to 'app/Auth.php')
| -rw-r--r-- | app/Auth.php | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/app/Auth.php b/app/Auth.php index fb3022101a..45c43a9826 100644 --- a/app/Auth.php +++ b/app/Auth.php @@ -22,13 +22,19 @@ use Zend_Session; * Class Auth - authentication functions */ class Auth { + // Privacy constants + const PRIV_PRIVATE = 2; // Allows visitors to view the item + const PRIV_USER = 1; // Allows members to access the item + const PRIV_NONE = 0; // Allows managers to access the item + const PRIV_HIDE = -1; // Hide the item to all users + /** * Are we currently logged in? * * @return boolean */ public static function check() { - return Auth::id() !== null; + return self::id() !== null; } /** @@ -47,7 +53,7 @@ class Auth { } /** - * Is a user a manager of a tree? + * Is the specified/current user a manager of a tree? * * @param Tree $tree * @param User|null $user @@ -63,7 +69,7 @@ class Auth { } /** - * Is a user a moderator of a tree? + * Is the specified/current user a moderator of a tree? * * @param Tree $tree * @param User|null $user @@ -79,7 +85,7 @@ class Auth { } /** - * Is a user an editor of a tree? + * Is the specified/current user an editor of a tree? * * @param Tree $tree * @param User|null $user @@ -96,7 +102,7 @@ class Auth { } /** - * Is a user a member of a tree? + * Is the specified/current user a member of a tree? * * @param Tree $tree * @param User|null $user @@ -112,6 +118,28 @@ class Auth { } /** + * What is the specified/current user's access level within a tree? + * + * @param Tree $tree + * @param User|null $user + * + * @return boolean + */ + public static function accessLevel(Tree $tree, User $user = null) { + if ($user === null) { + $user = self::user(); + } + + if (self::isManager($tree, $user)) { + return self::PRIV_NONE; + } elseif (self::isMember($tree, $user)) { + return self::PRIV_USER; + } else { + return self::PRIV_PRIVATE; + } + } + + /** * Is the current visitor a search engine? The global is set in session.php * * @return boolean @@ -139,7 +167,7 @@ class Auth { * @return User */ public static function user() { - $user = User::find(Auth::id()); + $user = User::find(self::id()); if ($user === null) { $visitor = new \stdClass; $visitor->user_id = ''; |
