Commit 8b26c06734716e105747525b961cbbbb63c7aa24
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
Showing
2 changed files
with
37 additions
and
18 deletions
lib/groups/GroupUtil.php
| @@ -8,31 +8,31 @@ | @@ -8,31 +8,31 @@ | ||
| 8 | * Document Management Made Simple | 8 | * Document Management Made Simple |
| 9 | * Copyright (C) 2008, 2009 KnowledgeTree Inc. | 9 | * Copyright (C) 2008, 2009 KnowledgeTree Inc. |
| 10 | * Portions copyright The Jam Warehouse Software (Pty) Limited | 10 | * Portions copyright The Jam Warehouse Software (Pty) Limited |
| 11 | - * | 11 | + * |
| 12 | * This program is free software; you can redistribute it and/or modify it under | 12 | * This program is free software; you can redistribute it and/or modify it under |
| 13 | * the terms of the GNU General Public License version 3 as published by the | 13 | * the terms of the GNU General Public License version 3 as published by the |
| 14 | * Free Software Foundation. | 14 | * Free Software Foundation. |
| 15 | - * | 15 | + * |
| 16 | * This program is distributed in the hope that it will be useful, but WITHOUT | 16 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 18 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | 18 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 19 | * details. | 19 | * details. |
| 20 | - * | 20 | + * |
| 21 | * You should have received a copy of the GNU General Public License | 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 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 | * California 94120-7775, or email info@knowledgetree.com. | 25 | * California 94120-7775, or email info@knowledgetree.com. |
| 26 | - * | 26 | + * |
| 27 | * The interactive user interfaces in modified source and object code versions | 27 | * The interactive user interfaces in modified source and object code versions |
| 28 | * of this program must display Appropriate Legal Notices, as required under | 28 | * of this program must display Appropriate Legal Notices, as required under |
| 29 | * Section 5 of the GNU General Public License version 3. | 29 | * Section 5 of the GNU General Public License version 3. |
| 30 | - * | 30 | + * |
| 31 | * In accordance with Section 7(b) of the GNU General Public License version 3, | 31 | * In accordance with Section 7(b) of the GNU General Public License version 3, |
| 32 | * these Appropriate Legal Notices must retain the display of the "Powered by | 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 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices | 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 | * copyright notice. | 36 | * copyright notice. |
| 37 | * Contributor( s): ______________________________________ | 37 | * Contributor( s): ______________________________________ |
| 38 | */ | 38 | */ |
| @@ -251,6 +251,24 @@ class GroupUtil { | @@ -251,6 +251,24 @@ class GroupUtil { | ||
| 251 | return $aRet; | 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 | // {{{ _listGroupsIDsForUserExpand | 272 | // {{{ _listGroupsIDsForUserExpand |
| 255 | function _listGroupIDsForUserExpand ($oUser) { | 273 | function _listGroupIDsForUserExpand ($oUser) { |
| 256 | $iUserId = KTUtil::getId($oUser); | 274 | $iUserId = KTUtil::getId($oUser); |
| @@ -265,8 +283,11 @@ class GroupUtil { | @@ -265,8 +283,11 @@ class GroupUtil { | ||
| 265 | if (KTLOG_CACHE) $default->log->debug(sprintf("Using group cache for _listGroupIDsForUserExpand %d", $iUserId)); | 283 | if (KTLOG_CACHE) $default->log->debug(sprintf("Using group cache for _listGroupIDsForUserExpand %d", $iUserId)); |
| 266 | return $mCached; | 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 | $sQuery = "SELECT group_id FROM $default->users_groups_table WHERE user_id = ?"; | 291 | $sQuery = "SELECT group_id FROM $default->users_groups_table WHERE user_id = ?"; |
| 271 | $aParams = array($iUserId); | 292 | $aParams = array($iUserId); |
| 272 | $aGroupIDs = DBUtil::getResultArrayKey(array($sQuery, $aParams), "group_id"); | 293 | $aGroupIDs = DBUtil::getResultArrayKey(array($sQuery, $aParams), "group_id"); |
lib/permissions/permissionutil.inc.php
| @@ -511,23 +511,21 @@ class KTPermissionUtil { | @@ -511,23 +511,21 @@ class KTPermissionUtil { | ||
| 511 | } | 511 | } |
| 512 | // check if permission has been set | 512 | // check if permission has been set |
| 513 | // $permArr[permId] = array('folders' => array('id' => bool), 'docs' => array('id' => bool)); | 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 | $oPL = KTPermissionLookup::get($oFolderOrDocument->getPermissionLookupID()); | 518 | $oPL = KTPermissionLookup::get($oFolderOrDocument->getPermissionLookupID()); |
| 521 | $oPLA = KTPermissionLookupAssignment::getByPermissionAndLookup($oPermission, $oPL); | 519 | $oPLA = KTPermissionLookupAssignment::getByPermissionAndLookup($oPermission, $oPL); |
| 522 | if (PEAR::isError($oPLA)) { | 520 | if (PEAR::isError($oPLA)) { |
| 523 | //print $oPL->getID(); | 521 | //print $oPL->getID(); |
| 524 | - $permArr[$iPermId][$lookup][$iDocId] = false; | 522 | + KTPermissionUtil::$permArr[$iPermId][$lookup][$iDocId] = false; |
| 525 | return false; | 523 | return false; |
| 526 | } | 524 | } |
| 527 | $oPD = KTPermissionDescriptor::get($oPLA->getPermissionDescriptorID()); | 525 | $oPD = KTPermissionDescriptor::get($oPLA->getPermissionDescriptorID()); |
| 528 | 526 | ||
| 529 | // set permission array to true | 527 | // set permission array to true |
| 530 | - $permArr[$iPermId][$lookup][$iDocId] = true; | 528 | + KTPermissionUtil::$permArr[$iPermId][$lookup][$iDocId] = true; |
| 531 | 529 | ||
| 532 | // check for permissions | 530 | // check for permissions |
| 533 | $aGroups = GroupUtil::listGroupsForUserExpand($oUser); | 531 | $aGroups = GroupUtil::listGroupsForUserExpand($oUser); |
| @@ -537,7 +535,7 @@ class KTPermissionUtil { | @@ -537,7 +535,7 @@ class KTPermissionUtil { | ||
| 537 | else if ($oPD->hasRoles(array(-4)) && !$oUser->isAnonymous()) { return true; } | 535 | else if ($oPD->hasRoles(array(-4)) && !$oUser->isAnonymous()) { return true; } |
| 538 | 536 | ||
| 539 | // permission isn't true, set to false | 537 | // permission isn't true, set to false |
| 540 | - $permArr[$iPermId][$lookup][$iDocId] = false; | 538 | + KTPermissionUtil::$permArr[$iPermId][$lookup][$iDocId] = false; |
| 541 | return false; | 539 | return false; |
| 542 | } | 540 | } |
| 543 | // }}} | 541 | // }}} |