diff --git a/lib/users/User.inc b/lib/users/User.inc index 00346f5..8096586 100644 --- a/lib/users/User.inc +++ b/lib/users/User.inc @@ -499,64 +499,10 @@ class User extends KTEntity { } - function hasPermission(&$oPermissionDescriptor, $iUserId = null) { - if(empty($iUserId)){ - $iUserId = $_SESSION['iUserId']; - } - - $pdgTable = KTUtil::getTableName('permission_descriptor_groups'); - global $default; - $uglTable = $default->users_groups_table; - $sQuery = "SELECT COUNT(*) AS num FROM $pdgTable pd - INNER JOIN $uglTable ug ON ug.group_id = pd.group_id - WHERE pd.descriptor_id = ? AND ug.user_id = ?"; - - $aParams = array($oPermissionDescriptor->getID(), $iUserId); - $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'num'); - - if (PEAR::isError($res) || empty($res)) { - - $aSubGrpOneParams = array($oPermissionDescriptor->getID()); - - //Checking if user is in a subgroup - //Query One is the get any groups with permissions - $sSubGrpQueryOne = "SELECT group_id FROM $pdgTable pd - WHERE pd.descriptor_id = ?"; - $aSubRes = DBUtil::getResultArrayKey(array($sSubGrpQueryOne, $aSubGrpOneParams), 'group_id'); - - if(!(PEAR::isError($aSubRes) || empty($aSubRes))) - { - $list = implode(',', $aSubRes); - - $sSubGroupTable = KTUtil::getTableName('groups_groups_link'); - $aParams = array($iUserId); - - //Query two is to check if the current user's group is a sub group of the - //group with permissions - $sSubGrpQueryTwo = "SELECT COUNT(member_group_id) count FROM $sSubGroupTable ggl - INNER JOIN users_groups_link ugl ON (ugl.group_id = ggl.member_group_id) - WHERE ugl.user_id = ? AND parent_group_id IN ($list)"; - $aSubResTwo = DBUtil::getOneResultKey(array($sSubGrpQueryTwo, $aParams), 'count'); - - if(PEAR::isError($aSubResTwo) || empty($aSubResTwo)) - { - return false; - } - else - { - return true; - } - } - else - { - return false; - } - - } - else - { - return true; - } + function hasPermission($oUser, $oPermission, $oFolderOrDocument) { + return KTPermissionUtil::userHasPermissionOnItem($oUser, $oPermission, $oFolderOrDocument); + } + } ?> \ No newline at end of file diff --git a/plugins/ktcore/folder/Permissions.php b/plugins/ktcore/folder/Permissions.php index b2455f4..17ad3d4 100644 --- a/plugins/ktcore/folder/Permissions.php +++ b/plugins/ktcore/folder/Permissions.php @@ -216,7 +216,7 @@ class KTFolderPermissionsAction extends KTFolderAction { // TODO : paginate this page, when there are too many users foreach ($aUsers as $oUser) { if ($everyone || ($authenticated && $oUser->isAnonymous()) || - $oUser->hasPermission($oDescriptor, $oUser->getId())) { + KTPermissionUtil::userHasPermissionOnItem($oUser, $oPermission, $this->oFolder)){ $aMapPermissionUser[$iPermissionID][$oUser->getId()] = true; } }