We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31902
    • 342 Posts
    Maybe it's too obvious for me to see, but is there a way to set permissions so that all resources can be edited by an editor, but:

    1. Creation and deletion is limited to only one container in the tree.
    2. No creation and deletion allowed on any resource outside that container.
    3. All resources in the tree can be edited.

    In this case, there is a container that feeds a blog (based on Sean's blog tutorial located here: http://rtfm.modx.com/display/revolution20/Creating+a+Blog+in+MODx+Revolution) with blog article resources. I want the editor to be able to create/delete/edit the resources within that blog container. However, I don't want the editor to be able to create or delete any other resource that already exists in the tree, but outside that blog container, yet still be able to edit them.

    I searched all around but didn't find (or at least identify from what I did see) the right solution.

    Can anyone chime in here? Thanks in advance.

    Running:
    MODx 2.2.6-pl

      • 3749
      • 24,544 Posts
      I think this would work, though it's somewhat complicated.

      Here's the short version of what you want (the context in all cases is 'mgr'):


      1. An Editor User Group which the Editor is a member of (and so are you)

      2. *All* resources on the site in the same Resource Group (let's call it AllDocs)

      3. A Policy based on the Resource Policy Template (let's call it NoCreate) with the 'create' and 'delete' permissions unchecked (and probably 'duplicate' as well)

      4. A Resource Group Access ACL entry connecting the AllDocs Resource Group to the Administrator User Group (which the Editor is *not* a member of) with a Policy of Resource

      5. A Resource Group Access ACL entry connecting the AllDocs Resource Group to the Editor User Group with a Policy of NoCreate

      6. A Resource Group containing only the Resources in the blog container (let's call it 'CreateOk')


      7. A Resource Group Access ACL entry connecting the CreateOk Resource Group to the Editor User Group with a Policy of Resource


      You can use the DefaultResourceGroup plugin to automatically put all new docs in the AllDocs group.

      My only question would be whether this would allow the Editor to create new docs under the Blog container. I think so, but I'm not sure. I think you would also need a plugin to assign new resources under the blog container to the 'CreateOK' Resource Group. It should be very simple and there may be an extra that does this already. If there are no other folders under the blog container, this would do it (connected to OnDocFormSave):

      <?php
      $blogContainerId = 12;  // change 12 to the ID of the blog container
      
      if ($resource->get('parent') == $blogConainerId) {
          $resource->joinGroup('CreateOk');
      }

        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
        • 31902
        • 342 Posts
        Quote from: BobRay at Mar 05, 2013, 09:26 PM
        ...

        My only question would be whether this would allow the Editor to create new docs under the Blog container. I think so, but I'm not sure. I think you would also need a plugin to assign new resources under the blog container to the 'CreateOK' Resource Group. It should be very simple and there may be an extra that does this already. If there are no other folders under the blog container, this would do it (connected to OnDocFormSave):

        <!--?php
        $blogContainerId = 12;  // change 12 to the ID of the blog container
        
        if ($resource--->get('parent') == $blogConainerId) {
            $resource->joinGroup('CreateOk');
        }


        Thanks for responding, Bob. Forgive my ignorance, but how/where would I add the preceding code? I assume I create a snippet out of it but where would I add it? Within the template that the blog container is using?
          • 3749
          • 24,544 Posts
          No, not a snippet. It would be a plugin, with selected on the System Events tab.
            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
            • 31902
            • 342 Posts
            Thanks, Bob. I need to come up to speed on creating plugins, I guess. Until then, I got through step 7 but what it does is hide the resources within AllDocs Resource Group from the editor and only shows the resources within the CreateOk Resource Group. And, unfortunately, it still allows creating/deleting of resources there.

            I'm sure I'm misunderstanding your instructions and I'll go through it again. Thanks for your patience.
              • 3749
              • 24,544 Posts
              Step 5 should let the Editors see and edit anything in the AllDocs group, unless you got the permissions backwards in the NoCreate Policy. It should have everything checked except delete and create and should be based on the Resource Policy Template.

              Creating plugins is almost exactly like creating snippets, you just paste the code and save, but before saving, you need to click on the System Events tab and put a checkmark next to any System Events the plugin should respond to (in this case OnDocFormSave).

              A snippet's code will execute whenever a snippet tag for it is encountered. A plugin is a little different. Its code will execute whenever any of the checked System Events fires. As MODX goes about its business, it periodically fires (technically, 'invokes') various System Events. At that point the code of any plugins attached to that System Event are executed.

              For example, whenever you click on "Save" in the Create/Edit Resource panel, MODX saves the resource, then invokes the OnDocFormSave event. That's when the code of your plugin will execute.
                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