We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28708
    • 14 Posts
    Hello,

    I’m trying to figure out how to list some documents on the front end according to user group permissions.

    I have a very basic test page that lists all the resources with a certain parent using something like the following:
    $docArray = $modx->getCollection('modResource',array(
        'parent' => 4
    ));
    foreach ($docArray as $doc){
        $titles[] = $doc->get('pagetitle');
    }
    // output titles as html list
    

    This all works as expected until I configure resource group access, at which point I get a little confused.

    The next steps I’ve taken:

    • Add one of the resources, we’ll call it "Product A.1", to a resource group, say "Product Set A"
    • Add web user to a user group "Customers"
    • Next I update the "Customers" resource group access to include "Product Set A" with a minimum role of "Member", an access policy of "Resource" and a context of "Web"

    Now when I go back to the front end, login and hit the test page, the resource "Product A.1" is no longer on the list even though, AFAIK, the current has all the necessary permissions.

    I’m guessing that the getCollection method maybe doesn’t handle group permissions by default and that my code will have to handle this, but I have no idea where to start. I’ve read through the documentation and have been perusing the API as well, but I’m pretty much a n00b so it’s a bit daunting. Any help/code examples would be greatly appreciated!






      • 32699 ☆ A M B ☆
      • 427 Posts
      I am thinking this is what contexts are used for.

      You may also want to user MemberCheck in the package manager
        Get your copy of MODX Revolution Building the Web Your Way http://www.sanitypress.com/books/modx-revolution-building-the-web-your-way.html

        Check out my MODX || xPDO resources here: http://www.shawnwilkerson.com
        • 28708
        • 14 Posts
        Thanks for the reply wshawn,

        I am attempting to place control over the resources, so I think I want to stick with resource ACLs vs context ACLs, although I could use both.

        I have looked at the MemberCheck class and it was somewhat helpful in that it pointed out the isMemberOfWebGroup() method, but that doesn’t quite get me what I need. I can use it to verify that the user is a member of the user group, but it doesn’t help me list the user group’s related resource group objects.
          • 28708
          • 14 Posts
          Thanks to opengeek for this one. Everything was actually working as I expected, but as of this writing, policy changes require the sessions to be flushed in order to take effect since permissions are stored in the session. This may happen automatically in future releases.