We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33983 ☆ A M B ☆
    • 181 Posts
    I have a snippet that I created that creates a simple Edit this page link for users. The link goes to the Manager to edit current page.

    I have been simply using this code to see if user can edit:
    $modx->hasPermission('edit_document')


    And if the user as the edit_document permission for the current context this will always return true, even if the current page is in a Resource Group that they do not have access to.

    What I would like to have is a simple API call that is like (boolean) $modx->canEditResource() or something that you can choose the context and that this method calculates all the Resource Group permissions.

    My question is what I am doing wrong? What already exists within the API that will accomplish what I am trying to do? Or do I need to create my own method to calculate the Resource Group perms?

    Thanks for reviewing! Any help is appreciated! Let me know if I need to clarify.
      • 3749
      • 24,544 Posts
      You might consider using NewsPublisher, which will let you put an edit button on the page and let users edit the page in the front end (sometimes it's nice to keep them out of the Manager). NewsPublisher will check the permissions for you and the edit button won't show up if they don't have the proper permissions.

      If you want to use your own snippet, you can do this:

       if ($modx->resource->checkPolicy('save') )


      You could also use 'view' instead of 'save' or any of the permissions in the Resource Policy (there is no 'edit' permission there, so you can't use that).

      $this->resource->checkPolicy('save')


      ------------------------------------------------------------------------------------------
      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
        • 33983 ☆ A M B ☆
        • 181 Posts
        Thanks Bob for the reply. I will look into NewsPublisher when I have some time but since this is an existing snippet I will try your code excerpt right now.