]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
Fix bug #2674961: editAllowed optimization - make less queries for each bookmark
authorcweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>
Tue, 22 Sep 2009 06:12:25 +0000 (06:12 +0000)
committercweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>
Tue, 22 Sep 2009 06:12:25 +0000 (06:12 +0000)
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@366 b3834d28-1941-0410-a4f8-b48e95affb8f

services/bookmarkservice.php
services/userservice.php

index 6a50df5b8b7c08cf109b435c613669c8c3bcac6a..f1195930da8c122c9f04a2c9c326d3fc02c9daa4 100644 (file)
@@ -97,22 +97,38 @@ class BookmarkService {
                return $this->db->sql_fetchfield(0, 0);
        }
 
-       function editAllowed($bookmark) {
-               if (!is_numeric($bookmark) && (!is_array($bookmark) || !is_numeric($bookmark['bId'])))
-               return false;
+       /**
+        * Check if a bookmark may be edited by the current user
+     *
+        * @param integer|array $bookmark Bookmark uId or bookmark array
+        *
+        * @return boolean True if allowed
+        */
+       function editAllowed($bookmark)
+       {
+               if (!is_numeric($bookmark) && (!is_array($bookmark)
+                       || !is_numeric($bookmark['bId']))
+               ) {
+                       return false;
+               }
 
-               if (!is_array($bookmark))
-               if (!($bookmark = $this->getBookmark($bookmark)))
-               return false;
+               if (!is_array($bookmark)
+                        && !($bookmark = $this->getBookmark($bookmark))
+               ) {
+                       return false;
+               }
 
-               $userservice = & ServiceFactory :: getServiceInstance('UserService');
-               $userid = $userservice->getCurrentUserId();
-               if(!is_numeric($userid))
-               return false;  // useful for few servers configuration (see brunaud bugs)               
-               if ($GLOBALS['adminsCanModifyBookmarksFromOtherUsers'] && $userservice->isAdmin($userid) && !$userservice->isAdmin($bookmark['uId']))
-               return true;
-               else
-               return ($bookmark['uId'] == $userid);
+               $userservice = & ServiceFactory::getServiceInstance('UserService');
+               $user = $userservice->getCurrentUser();
+
+               //user has to be either admin, or owner
+               if ($GLOBALS['adminsCanModifyBookmarksFromOtherUsers']
+                       && $userservice->isAdmin($user)
+               ) {
+                       return true;
+               } else {
+                       return ($bookmark['uId'] == $user['uId']);
+               }
        }
 
        function bookmarkExists($address = false, $uid = NULL) {
index 512204c00a32e64155e73c51d0dde5bda7d608cf..a24c7ba2ef1d586f802ced78da318d743a5af882 100644 (file)
@@ -213,11 +213,24 @@ class UserService {
                }
        }
 
-       function isAdmin($userid) {
-               $user = $this->getUser($userid);
+       /**
+        * Checks if the given user is an administrator.
+        * Uses global admin_users property containing admin
+        * user names
+        *
+        * @param integer|array $user User ID or user row from DB
+        *
+        * @return boolean True if the user is admin
+        */
+       function isAdmin($user)
+       {
+               if (is_numeric($user)) {
+                       $user = $this->getUser($user);
+               }
 
-               if(isset($GLOBALS['admin_users'])
-               && in_array($user['username'], $GLOBALS['admin_users'])) {
+               if (isset($GLOBALS['admin_users'])
+                       && in_array($user['username'], $GLOBALS['admin_users'])
+               ) {
                        return true;
                } else {
                        return false;