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

    Is there a simple way to deliver different content for the same resource based on the user group?
    To illustrate:
    There are 3 different permission levels:
    - Anonymous
    - Member
    - Owner

    So the resource should be available to all of them, but should host slightly different content for each user group. For example there is a video url on every resource and based on the user group the user belongs to a different video url should be displayed.

    Distinguishing between anonymous and member is easy, but how do I add an extra level without blocking access for anonymous users?
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Use chunks (or even other resources for easier editing and management) for the different content, then use a snippet to check the user's group and return the chunk/resource content for each group.

      See http://modxcookbook.com/security/users/get-user-group.html
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 19599
        • 33 Posts
        Ok I get that part. Where I'm stuck is how to allow a user to become an owner of a resource.

        The mechanics are like this:
        - As an anonymous user I see the anonymous content (that is clear)
        - As a member I see the member content (clear so far)
        - As an owner I see member content on all resources I don't own (subscribed to) on all owned resource I see the owned content

        So my question is how can I allow users to be member and owner on different resources at the same time?

        What I gathered is that this should be possible with resource groups. So each user would have it's own user group and when subscribing to a resource that user group the users' resource group is assigned to that resource. How ever so far I did not manage to assign a resource group without blocking all other users from that resource.
          • 3749
          • 24,544 Posts
          You can create a user group for each client (and create the page and group, and put the user in the group automatically, in a plugin attached to OnUserActivate)

          Another way to go, which I find easier and faster, is to put the user ID of the "owner" in the 'createdon' field of the page (or have the user actually create the page using NewsPublisher - which sets it automatically).

          Once that's done, your snippet can do this to see if the user "owns" the page:

          $output = '';
          if ($modx->user->get('id') === $modx->resource->get('createdon') {
             $output .= $modx->getChunk('OwnerChunk');
          }
          return $output;


          If the "Owner" content is specific to the page, you can put it in a TV called 'OwnerStuff' and do this:

             $output .= $modx->resource->getTVValue('OwnerStuff');
            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
            • 19599
            • 33 Posts
            Hi Bob,

            Thanks for your reply.
            There can be multiple owner/subscribers. A resource is like a product you can subscribe to for money.

            Using a TV is actually an interesting idea. So adding a TV called owner or subscribers and then add the user Ids of the owners in there, could be an easy way to do this.

            But I implemented it this way now:
            - All user go into a Member user group
            - Each user has a resource group that is named like the username
            - Anonymous gets "load only" rights for the users' resource group so does the Member user group
            - When a user subscribes to a resource, that resource is added to the users' resource group
            - When I load a specific resource, I simply check if the resource belongs to a user group that is named like the logged-in user.

            It's a little bit more overhead, but that way it's easily manageable for an editor. (Just add/remove resources in the resource group admin interface)

              • 3749
              • 24,544 Posts
              That sounds like the best solution if you have multiple "owners" for a page.
                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