Index: branches/5.2.x/core/kernel/db/cat_event_handler.php =================================================================== diff -u -N -r15608 -r15761 --- branches/5.2.x/core/kernel/db/cat_event_handler.php (.../cat_event_handler.php) (revision 15608) +++ branches/5.2.x/core/kernel/db/cat_event_handler.php (.../cat_event_handler.php) (revision 15761) @@ -1,6 +1,6 @@ getObject(); - /* @var $object kDBList */ + /* @var $object kCatDBList */ // add category filter if needed if ($event->Special != 'showall' && $event->Special != 'user') { @@ -648,22 +648,8 @@ $object->addFilter('owner_filter', '%1$s.'.$this->getOwnerField($event->Prefix).' = '.$editable_user); } - // add permission filter - if ($this->Application->RecallVar('user_id') == USER_ROOT) { - // for "root" CATEGORY.VIEW permission is checked for items lists too - $view_perm = 1; - } - else { - // for any real user itemlist view permission is checked instead of CATEGORY.VIEW - $count_helper = $this->Application->recallObject('CountHelper'); - /* @var $count_helper kCountHelper */ + $this->applyViewPermissionFilter($object); - list ($view_perm, $view_filter) = $count_helper->GetPermissionClause($event->Prefix, 'perm'); - $object->addFilter('perm_filter2', $view_filter); - } - - $object->addFilter('perm_filter', 'perm.PermId = '.$view_perm); - $types = $event->getEventParam('types'); $this->applyItemStatusFilter($object, $types); @@ -677,6 +663,36 @@ } /** + * Adds filter, that uses *.VIEW permissions to determine if an item should be shown to a user. + * + * @param kCatDBList $object Object. + * + * @return void + * @access protected + */ + protected function applyViewPermissionFilter(kCatDBList $object) + { + if ( !$this->Application->ConfigValue('CheckViewPermissionsInCatalog') ) { + return; + } + + if ( $this->Application->RecallVar('user_id') == USER_ROOT ) { + // for "root" CATEGORY.VIEW permission is checked for items lists too + $view_perm = 1; + } + else { + // for any real user item list view permission is checked instead of CATEGORY.VIEW + $count_helper = $this->Application->recallObject('CountHelper'); + /* @var $count_helper kCountHelper */ + + list ($view_perm, $view_filter) = $count_helper->GetPermissionClause($object->Prefix, 'perm'); + $object->addFilter('perm_filter2', $view_filter); + } + + $object->addFilter('perm_filter', 'perm.PermId = ' . $view_perm); + } + + /** * Adds filter that filters out items with non-required statuses * * @param kDBList $object @@ -2810,6 +2826,8 @@ parent::OnAfterConfigRead($event); if (defined('IS_INSTALL') && IS_INSTALL) { + $this->addViewPermissionJoin($event); + return ; } @@ -2821,7 +2839,7 @@ $file_helper->createItemFiles($event->Prefix, false); // create file fields } - $this->changeSortings($event); + $this->changeSortings($event)->addViewPermissionJoin($event); // add grids for advanced view (with primary category column) $grids = $this->Application->getUnitOption($this->Prefix, 'Grids'); @@ -2845,7 +2863,15 @@ $this->Application->setUnitOption($event->Prefix, 'VirtualFields', $virtual_fields); } - function changeSortings($event) + /** + * Changes default sorting according to system settings. + * + * @param kEvent $event Event. + * + * @return self + * @access protected + */ + protected function changeSortings(kEvent $event) { $remove_sortings = Array (); @@ -2863,7 +2889,7 @@ } if ( !$remove_sortings ) { - return; + return $this; } $list_sortings = $this->Application->getUnitOption($event->Prefix, 'ListSortings', Array ()); @@ -2876,9 +2902,40 @@ } $this->Application->setUnitOption($event->Prefix, 'ListSortings', $list_sortings); + + return $this; } /** + * Adds permission table table JOIN clause only, when advanced catalog view permissions enabled. + * + * @param kEvent $event Event. + * + * @return self + * @access protected + */ + protected function addViewPermissionJoin(kEvent $event) + { + if ( $this->Application->ConfigValue('CheckViewPermissionsInCatalog') ) { + $join_clause = 'LEFT JOIN ' . TABLE_PREFIX . 'CategoryPermissionsCache perm ON perm.CategoryId = ' . TABLE_PREFIX . '%3$sCategoryItems.CategoryId'; + } + else { + $join_clause = ''; + } + + $list_sqls = $this->Application->getUnitOption($event->Prefix, 'ListSQLs'); + /* @var $list_sqls array */ + + foreach ($list_sqls as $special => $list_sql) { + $list_sqls[$special] = str_replace('{PERM_JOIN}', $join_clause, $list_sql); + } + + $this->Application->setUnitOption($event->Prefix, 'ListSQLs', $list_sqls); + + return $this; + } + + /** * Returns file contents associated with item * * @param kEvent $event