• 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

R

ragtek

Guest
#1
Hi,
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)
PHP:
        $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?
 

Member 3639

Active member
#2
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?
 

Brogan

XenForo moderator
Staff member
#4
Have you looked in library\XenForo\NodeHandler\Abstract.php?

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

PHP:
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,
        array $renderedChildren, $level
    );
 

Member 3639

Active member
#5
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.
 

Member 3639

Active member
#6
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.
 

Lawrence

Well-known member
#7
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 :)

PHP:
    /**
     * 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 (!$nodes)
        {
            return array();
        }
        if (!is_array($nodePermissions))
        {
            $nodePermissions = $this->getNodePermissionsForPermissionCombination();
        }
        $nodeHandlers = $this->getNodeHandlersForNodeTypes(
            $this->getUniqueNodeTypeIdsFromNodeList($nodes)
        );
        return $this->getViewableNodesFromNodeList($nodes, $nodeHandlers, $nodePermissions);
    }
 

Member 3639

Active member
#8
Looks like that is the exact function, how would one properly call it?

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

Shadab

Well-known member
#9
Try:
PHP:
$nodeModel = XenForo_Model::create('XenForo_Model_Node');
$nodes = $nodeModel->getViewableNodeList();
Pass in the appropriate node permissions if required.