1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Node Permissions of current user

Discussion in 'XenForo Development Discussions' started by ragtek, Dec 5, 2010.

  1. ragtek

    ragtek Guest

    i hadn't seen any add-on which checks the permissions :(

    ATM I'm reading ALL threads and then sort them out with the search model (like it's happening with the what's new page)
            $results $searchModel->getViewableSearchResults($results);
    $results $searchModel->getSearchResultsForDisplay($results);
    that's IMHO extremly ugly because it's much overhead and i don't know how many elements i'll get back, so it's imposible to use this with pagination.

    i've searched the code and i saw that i could maybe use the getNodePermissionsForPermissionCombination method but i hadn't time to check this.

    Anybody knows how to get a "string" containing all the node Ids which the current user is allowed to see?
  2. Member 3639

    Member 3639 Active Member

    Hi all currently trying to add correct permissions to two resources i've done the rss and lastest posts.

    I wish to add proper permissions to them based on their group.

    What i am wandering is how would i generate a list of node_ids the current visitor can view?
  3. ragtek

    ragtek Guest

  4. Brogan

    Brogan XenForo Moderator Staff Member

    Have you looked in library\XenForo\NodeHandler\Abstract.php?

    That seems to be the relevant code; here's a snippet.

    abstract class XenForo_NodeHandler_Abstract
         * Determines if the specified node is viewable with the given permissions.
         * @param array $node Node info
         * @param array $nodePermissions Permissions for this node
         * @return boolean
    abstract public function isNodeViewable(array $node, array $nodePermissions);
    // TODO: be able to pass in $viewingUser

         * Renders the specified node for display in a node tree.
         * Note that if using a template, it is preferable to not explicitly
         * render the template here, but to return the object instead.
         * @param XenForo_View $view View object doing the rendering
         * @param array $node Information about this node
         * @param array $permissions Pemissions for this node
         * @param array $renderedChildren List of rendered children, [node id] => rendered output
         * @param integer $level The level this node should be rendered at, relative to how it's to be displayed.
         * @return string|XenForo_Template_Abstract
    abstract public function renderNodeForTree(XenForo_View $view, array $node, array $permissions,
  5. Member 3639

    Member 3639 Active Member

    Thanks for linking me mate.

    It is a real dirty way to do it, I'm surprised there isn't a stored list on the node_id's somewhere, i mean there must be.
  6. Member 3639

    Member 3639 Active Member

    Hmmm still pretty confusing though.

    As it seems that is one at a time.

    We would need to grab all the node_ids and run each one through it by the looks of it.
  7. Lawrence

    Lawrence Well-Known Member

    Liam, I just did a quick look of XenForo/Model/Node.php and came across this function that may do what you are looking for, or at least help you get started :)

         * Get a list of all nodes that are viewable.
         * @param array|null $nodePermissions List of node permissions,  [node id] => permissions; if null, get's current visitor's  permissions
         * @param boolean Get nodes in list mode (respect display_in_list option for each node)
         * @return array List of viewable nodes: [node id] => info, ordered by lft
    public function getViewableNodeList(array $nodePermissions null$listView false)
    $nodes $this->getAllNodes(false$listView);
            if (!
                return array();
            if (!
    $nodePermissions $this->getNodePermissionsForPermissionCombination();
    $nodeHandlers $this->getNodeHandlersForNodeTypes(
    ragtek likes this.
  8. Member 3639

    Member 3639 Active Member

    Looks like that is the exact function, how would one properly call it?

    I have called in the xen libs like so:
    $startTime microtime(true); 
    $xenforoRoot '/home/prxainf1/public_html/gamingonlinux.info/chill'
    XenForo_Autoloader::getInstance()->setupAutoloader($xenforoRoot '/library');
    Plus other bits but they are helper classes and stuff for post parsing so not relevant.
  9. Shadab

    Shadab Well-Known Member

    $nodeModel XenForo_Model::create('XenForo_Model_Node');
    $nodes $nodeModel->getViewableNodeList();
    Pass in the appropriate node permissions if required.

Share This Page