Commit 8b26c06734716e105747525b961cbbbb63c7aa24

Authored by Megan Watson
1 parent f79ba683

KTS-4245 Replaced the function which hits the DB for every single group with one…

… that only checks for subgroups.Added a static variable to store the permissions.

Committed by: Megan Watson
Reviewed by: Kevin Fourie
lib/groups/GroupUtil.php
... ... @@ -8,31 +8,31 @@
8 8 * Document Management Made Simple
9 9 * Copyright (C) 2008, 2009 KnowledgeTree Inc.
10 10 * Portions copyright The Jam Warehouse Software (Pty) Limited
11   - *
  11 + *
12 12 * This program is free software; you can redistribute it and/or modify it under
13 13 * the terms of the GNU General Public License version 3 as published by the
14 14 * Free Software Foundation.
15   - *
  15 + *
16 16 * This program is distributed in the hope that it will be useful, but WITHOUT
17 17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 18 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 19 * details.
20   - *
  20 + *
21 21 * You should have received a copy of the GNU General Public License
22 22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23   - *
24   - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
  23 + *
  24 + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
25 25 * California 94120-7775, or email info@knowledgetree.com.
26   - *
  26 + *
27 27 * The interactive user interfaces in modified source and object code versions
28 28 * of this program must display Appropriate Legal Notices, as required under
29 29 * Section 5 of the GNU General Public License version 3.
30   - *
  30 + *
31 31 * In accordance with Section 7(b) of the GNU General Public License version 3,
32 32 * these Appropriate Legal Notices must retain the display of the "Powered by
33   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  33 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
34 34 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
35   - * must display the words "Powered by KnowledgeTree" and retain the original
  35 + * must display the words "Powered by KnowledgeTree" and retain the original
36 36 * copyright notice.
37 37 * Contributor( s): ______________________________________
38 38 */
... ... @@ -251,6 +251,24 @@ class GroupUtil {
251 251 return $aRet;
252 252 }
253 253  
  254 + /**
  255 + * Lists all the available sub groups
  256 + */
  257 + function _listSubGroups()
  258 + {
  259 + global $default;
  260 + $sql = 'SELECT parent_group_id, member_group_id FROM '.$default->groups_groups_table;
  261 + $aGroups = DBUtil::getResultArray($sql);
  262 +
  263 + foreach ($aGroups as $aRow) {
  264 + $aList = KTUtil::arrayGet($aDirectGroups, $aRow['parent_group_id'], array());
  265 + $aList[] = $aRow['member_group_id'];
  266 + $aDirectGroups[$aRow['parent_group_id']] = $aList;
  267 + }
  268 +
  269 + return GroupUtil::expandGroupArray($aDirectGroups);
  270 + }
  271 +
254 272 // {{{ _listGroupsIDsForUserExpand
255 273 function _listGroupIDsForUserExpand ($oUser) {
256 274 $iUserId = KTUtil::getId($oUser);
... ... @@ -265,8 +283,11 @@ class GroupUtil {
265 283 if (KTLOG_CACHE) $default->log->debug(sprintf("Using group cache for _listGroupIDsForUserExpand %d", $iUserId));
266 284 return $mCached;
267 285 }
268   - $aGroupArray = GroupUtil::_invertGroupArray(GroupUtil::buildGroupArray());
269   - $aDirectGroups = GroupUtil::listGroupsForUser($oUser);
  286 +
  287 + // Get all subgroups
  288 + $aGroupArray = GroupUtil::_invertGroupArray(GroupUtil::_listSubGroups());
  289 + //$aGroupArray = GroupUtil::_invertGroupArray(GroupUtil::buildGroupArray());
  290 + //$aDirectGroups = GroupUtil::listGroupsForUser($oUser);
270 291 $sQuery = "SELECT group_id FROM $default->users_groups_table WHERE user_id = ?";
271 292 $aParams = array($iUserId);
272 293 $aGroupIDs = DBUtil::getResultArrayKey(array($sQuery, $aParams), "group_id");
... ...
lib/permissions/permissionutil.inc.php
... ... @@ -511,23 +511,21 @@ class KTPermissionUtil {
511 511 }
512 512 // check if permission has been set
513 513 // $permArr[permId] = array('folders' => array('id' => bool), 'docs' => array('id' => bool));
514   - if(isset($permArr[$iPermId][$lookup][$iDocId])){
515   - return $permArr[$iPermId][$lookup][$iDocId];
  514 + if(isset(KTPermissionUtil::$permArr[$iPermId][$lookup][$iDocId])){
  515 + return KTPermissionUtil::$permArr[$iPermId][$lookup][$iDocId];
516 516 }
517 517  
518   -
519   -
520 518 $oPL = KTPermissionLookup::get($oFolderOrDocument->getPermissionLookupID());
521 519 $oPLA = KTPermissionLookupAssignment::getByPermissionAndLookup($oPermission, $oPL);
522 520 if (PEAR::isError($oPLA)) {
523 521 //print $oPL->getID();
524   - $permArr[$iPermId][$lookup][$iDocId] = false;
  522 + KTPermissionUtil::$permArr[$iPermId][$lookup][$iDocId] = false;
525 523 return false;
526 524 }
527 525 $oPD = KTPermissionDescriptor::get($oPLA->getPermissionDescriptorID());
528 526  
529 527 // set permission array to true
530   - $permArr[$iPermId][$lookup][$iDocId] = true;
  528 + KTPermissionUtil::$permArr[$iPermId][$lookup][$iDocId] = true;
531 529  
532 530 // check for permissions
533 531 $aGroups = GroupUtil::listGroupsForUserExpand($oUser);
... ... @@ -537,7 +535,7 @@ class KTPermissionUtil {
537 535 else if ($oPD->hasRoles(array(-4)) && !$oUser->isAnonymous()) { return true; }
538 536  
539 537 // permission isn't true, set to false
540   - $permArr[$iPermId][$lookup][$iDocId] = false;
  538 + KTPermissionUtil::$permArr[$iPermId][$lookup][$iDocId] = false;
541 539 return false;
542 540 }
543 541 // }}}
... ...