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

    I have users setup for specific tree_root_id is there a way to pull this setting via the modx api, I tried the following already but with no luck;

    $profile = $modx->user->getOne('Profile');
    $fields = $profile->get('extended');
    return $profile->get('tree_root_id');
    


    It doesn't seem to be in extended or using $profile->get(), google didn't show anything either. Any help would be appreciated.
      • 3749
      • 24,544 Posts
      It would not be there unless you put it there.

      If you create it as a User Setting, though (on the Settings tab when you update a User), it will not be in the Profile. It is available like this:

      $treeRootId = $modx->getOption('tree_root_id');


      The User Setting will override the System Setting, but only if the user is logged in.


      More important, tree_root_id is deprecated and ignored in current versions of MODX, though you are free to create it as a User Setting or an Extended Field in the Profile and use it however you like.

      I would probably use a different name, however, in case some add-on developer decides to use that one. There are some examples using tree_root_id in my book (written before it was deprecated) that may give people ideas.


      ------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using.
      MODX info for everyone: http://bobsguides.com/modx.html
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 38970
        • 59 Posts
        Thanks bob for the quick response, since tree_root_id is depreciated is there a better way to restrict a user from only editing certain resources ?
          • 3749
          • 24,544 Posts
          Yes, using the MODX security permissions system, but TBH, I miss the tree_root_id setting, though it wasn't really secure because the user could still type the Manager URL for resources and edit them.

          If you hide a parent resource from users, they won't be able to see the parent or any of its children in the tree.

          http://bobsguides.com/revolution-permissions.html


          ------------------------------------------------------------------------------------------
          PLEASE, PLEASE specify the version of MODX you are using.
          MODX info for everyone: http://bobsguides.com/modx.html
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 38970
            • 59 Posts
            Hey Bob,

            I found the tree_root_id on your doc's smiley but I was un aware that using that option they could just enter a new id and edit that section. What method is the best to restrict a user to that particular resource id or even a few different ones.

              • 3749
              • 24,544 Posts
              There's quite a bit of information on that here: http://bobsguides.com/.

              Look under MODX -> MODX Security Permissions

              The basic process is to put all resources on the site in a Resource Group and protect that Resource Group by connecting it to the Administrator User Group (which the user is not a member of), with a Resource Group Access ACL entry. That will hide the resources from everyone but members of that group.

              Then, do basically the same thing with the Resources the user *should* be able to see but connect them to a User Group the User is a member of. That will allow the user access to those Resources.



              ------------------------------------------------------------------------------------------
              PLEASE, PLEASE specify the version of MODX you are using.
              MODX info for everyone: http://bobsguides.com/modx.html
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 38970
                • 59 Posts
                Hello Bob,

                I am going to have a couple hundred users accessing the back end of this site, is there a better way then creating a resource group for each user. Each user is only going to be able to access 1 or 2 resources.
                  • 3749
                  • 24,544 Posts
                  At present, there's no way that I know of.

                  It would be possible to create a plugin that would create the User Group and Resource Group (both named after the user) and the ACL entry that connects the two whenever a new user is added. It could also create a resource or two and add them the resource group.

                  Creating the plugin is on my ToDo list, but it's pretty far down. wink

                  The DefaultResourceGroup plugin will add all new resources to the Resource Group for all resources on the site.


                  ------------------------------------------------------------------------------------------
                  PLEASE, PLEASE specify the version of MODX you are using.
                  MODX info for everyone: http://bobsguides.com/modx.html
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 38970
                    • 59 Posts
                    Bob is there a plugin hook I could use so when a user loads a manager resource to edit i could checked their root_id and deny access based on that rather then just hiding it.

                    For example using tree_root_id would hide it visually from them but they could goto say id=36 if I could hook into the page load and run a php/snippet to check to see if that id is in their tree_root_id i could give them a 404 or whatnot.
                      • 3749
                      • 24,544 Posts
                      Yes, a plugin tied to OnDocFormPrerender could forward the user somewhere if they're not allowed to edit the resource.

                      The plugin would look something like this:


                      <?php
                      
                      /* allows access only to the tree_root_id resource and its children */
                      
                      $tr = $modx->getOption('tree_root_id');
                      $children = $modx->getChildIds(($tr);
                      /* add the tree_root_id resource the array -- remove if they shouldn't access the parent */
                      $children[] = $tr;
                      
                      if ( ! in_array($modx->resource->get('id'), $children)) {
                      
                         $modx->sendRedirect('http://yoursite.com/manager');
                      }
                      



                      That should send them back to the dashboard if they're not authorized to edit the requested page. You can send them somewhere else by pasting in another URL.

                      Note that is the user does not have the tree_root_id setting, the tree_root_id System Setting will be used and they'll typically have access to all resources. There's really no way to prevent this.

                      Also, if you let them edit the parent (tree_root_id) resource, they could potentially change it's parent and gain access to other resources.



                      ------------------------------------------------------------------------------------------
                      PLEASE, PLEASE specify the version of MODX you are using.
                      MODX info for everyone: http://bobsguides.com/modx.html



                      [ed. note: BobRay last edited this post 14 years, 3 months ago.]
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting