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

    I have resource Forum1 in context UserGroup1.
    I need to give to users the permission for posting the topic (a regular resource) under Forum1.
    Forum1 belongs to resource group GroupForum1 (because there may be many forums with different access rules).
    Users belongs to the group Users (there may be several groups).

    I gave to group Users the policy PolicyForum1 in context UserGroup1 with "load,list,view,create,add_children,new_document,publish_document".

    But when I execute the following...

        $data = array(
            'id'          => $id,
            'pagetitle'   => $_POST['pagetitle'],
            'parent'      => $forum,
            'content'     => $_POST['content'],
            'template'    => 20,
            'isfolder'    => 1,
            'context_key' => $ctx,
        );
    
        $response = $modx->runProcessor('resource/'.($id ? 'update' : 'create'), $data);
        if ($response->isError()) return $response->getMessage();
    


    I receive "permission_denied".

    I suspect, it because of the new resource was not created in resource group of it's parent, but in context only.
    So I need to give the same rights to the group Users on the context UserGroup1.
    If I do so, then the resource will be created.

    1. Are this additional rights to the whole context the only way to do this? Or specifying the resource_groups in $data will solve this?

    2. Can anybody give an example of json for resource_groups? I can't find any info about its structure.

    This question has been answered by BobRay. See the first response.

      • 3749
      • 24,544 Posts
      Your users also need new_document_in_root permission if the new document is at the root of the context.

      The users also need a Context Access ACL entry for that context.
        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
        • 47779
        • 13 Posts
        Thanks, Bob!

        Could you explain, how to add a resource to resource group with resource/create processor?

        From the source code it looks like to possible send resource_groups json array. But i can't find the structure anywhere.
        • discuss.answer
          • 3749
          • 24,544 Posts
          I think it's just an array where the left side is the ID of the resource and the right side is the ID of the resource group.

          It's usually easier to do it this way (though it's slightly slower), since you don't need either ID and can use the name of the resource group:

          if ($response->isError()) {
              return $response->getMessage();
          } else {
              $object = $response->getObject();
              $object->joinGroup('ResourceGroupName');
          }


          I'm almost certain that you can also use an array of names instead of 'ResourceGroupNames'.
            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
            • 47779
            • 13 Posts
            If somebody needs, you can send resource_groups like this:

                $data = array(
                    'pagetitle'       => $_POST['pagetitle'],
                    'parent'          => $parent,
                    'content'         => $_POST['content'],
                    'template'        => 20,
                    'isfolder'        => 1,
                    'context_key'     => $ctx,
                    'resource_groups' => json_encode(array(array('access'=>1, 'id'=>7))),
                );
                $response = $modx->runProcessor('resource/create', $data);
                if ($response->isError()) return $response->getMessage();
            


            But still with permission problems. Because method saveResourceGroups (wich uses resource_groups json array) runs after resource save, and rather after checkPolicy method for this saving.

            So i will create resource and then put it into resource group like Bob said.

            Have a good day!