/** * Debug permissions * * @return void */ public function debugTask() { include_once dirname(dirname(__DIR__)) . DS . 'helpers' . DS . 'debug.php'; // Get filters $filters = array('search' => urldecode(Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', '')), 'sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'lft'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'ASC'), 'level_start' => Request::getState($this->_option . '.' . $this->_controller . '.filter_level_start', 'filter_level_start', 0, 'int'), 'level_end' => Request::getState($this->_option . '.' . $this->_controller . '.filter_level_end', 'filter_level_end', 0, 'int'), 'component' => Request::getState($this->_option . '.' . $this->_controller . '.filter_component', 'filter_component', '')); if ($filters['level_end'] > 0 && $filters['level_end'] < $filters['level_start']) { $filters['level_end'] = $filters['level_start']; } $id = Request::getInt('id', 0); // Load access group $accessgroup = Accessgroup::oneOrFail($id); // Select the required fields from the table. $entries = \Hubzero\Access\Asset::all(); if ($filters['search']) { $entries->whereLike('name', $filters['search'], 1)->orWhereLike('title', $filters['search'], 1)->resetDepth(); } if ($filters['level_start'] > 0) { $entries->where('level', '>=', $filters['level_start']); } if ($filters['level_end'] > 0) { $entries->where('level', '<=', $filters['level_end']); } // Filter the items over the component if set. if ($filters['component']) { $entries->whereEquals('name', $filters['component'], 1)->orWhereLike('name', $filters['component'], 1)->resetDepth(); } $assets = $entries->order($filters['sort'], $filters['sort_Dir'])->paginated()->rows(); $actions = \Components\Members\Helpers\Debug::getActions($filters['component']); $data = $assets->raw(); $assets->clear(); foreach ($data as $key => $asset) { $checks = array(); foreach ($actions as $action) { $name = $action[0]; $level = $action[1]; // Check that we check this action for the level of the asset. if ($action[1] === null || $action[1] >= $asset->get('level')) { // We need to test this action. $checks[$name] = \JAccess::checkGroup($id, $action[0], $asset->get('name')); } else { // We ignore this action. $checks[$name] = 'skip'; } } $asset->set('checks', $checks); $assets->push($asset); } $levels = \Components\Members\Helpers\Debug::getLevelsOptions(); $components = \Components\Members\Helpers\Debug::getComponents(); // Output the HTML $this->view->set('group', $accessgroup)->set('filters', $filters)->set('assets', $assets)->set('actions', $actions)->set('levels', $levels)->set('components', $components)->display(); }
/** * Method to return the JAccessRules object for an asset. The returned object can optionally hold * only the rules explicitly set for the asset or the summation of all inherited rules from * parent assets and explicit rules. * * @param mixed $asset Integer asset id or the name of the asset as a string. * @param boolean $recursive True to return the rules object with inherited rules. * @return object Rules object for the asset. */ public static function getAssetRules($asset, $recursive = false) { // Get the database connection object. /*$db = App::get('db'); // Build the database query to get the rules for the asset. $query = $db->getQuery(true); $query->select($recursive ? 'b.rules' : 'a.rules'); $query->from('#__assets AS a'); //sqlsrv change $query->group($recursive ? 'b.id, b.rules, b.lft' : 'a.id, a.rules, a.lft'); // If the asset identifier is numeric assume it is a primary key, else lookup by name. if (is_numeric($asset)) { $query->where('(a.id = ' . (int) $asset . ')'); } else { $query->where('(a.name = ' . $db->quote($asset) . ')'); } // If we want the rules cascading up to the global asset node we need a self-join. if ($recursive) { $query->leftJoin('#__assets AS b ON b.lft <= a.lft AND b.rgt >= a.rgt'); $query->order('b.lft'); } // Execute the query and load the rules from the result. $db->setQuery($query); $result = $db->loadColumn();*/ // Build the database query to get the rules for the asset. $query = Asset::all()->select($recursive ? 'b.rules' : 'a.rules'); $query->from($query->getTableName(), 'a'); // If the asset identifier is numeric assume it is a primary key, else lookup by name. if (is_numeric($asset)) { $query->whereEquals('a.id', (int) $asset); } else { $query->whereEquals('a.name', $asset); } // If we want the rules cascading up to the global asset node we need a self-join. if ($recursive) { $query->joinRaw($query->getTableName() . ' AS b', 'b.lft <= a.lft AND b.rgt >= a.rgt', 'left'); $query->order('b.lft', 'asc'); } $query->group($recursive ? 'b.id, b.rules, b.lft' : 'a.id, a.rules, a.lft'); $result = $query->rows(); // Get the root even if the asset is not found and in recursive mode if (empty($result)) { $result = Asset::oneOrFail(Asset::getRootId()); $result = array($result); } // Instantiate and return the JAccessRules object for the asset rules. $rules = new Rules(); $rules->mergeCollection($result); return $rules; }