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

    How to restricted list users in manager for a just one users group to a specific user manager.
    I have created a user, but he can view and access to all users, admin and member.
    I just want to give access to member user.

    I have tried many configuration but without success !

    Thank you.

    Michel

      • 3749
      • 24,544 Posts
      I'm afraid there's no easy way to do it. Either a user has permission to view and access users or not.

      The only way I can think of to do it would be a plugin attached to various events that checks the users' groups and permissions and forwards them somewhere if they're not authorized to view what they're heading for. This would work for viewing/editing an individual user when attached to OnUserFormPrerender. I'm not sure it's possible to prevent them from viewing a list of user group members, but at least they wouldn't be able to go the next step to see and modify their data.

      A section of the plugin attached to OnUserFormSave would also be necessary to prevent them from creating new users or changing the permissions and/or group membership of existing users (e.g., making them sudo users or adding them to the Administrator group).

        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
        • 37927
        • 7 Posts
        Ok, I have implemented a solution.
        It consist to create an new param system called "usergroupauth" with value "all".
        After, in an user you will override this param called usergroupauth and you put a list of group id like 1,2,3 for an example or just 3 if you need.

        It's more complicated but not so much, you need to modify prepareQueryBeforeCount method in this file core/model/modx/processors/security/user/getlist.class.php
        with this code :

        public function prepareQueryBeforeCount(xPDOQuery $c) {
                $c->leftJoin('modUserProfile','Profile');
              
        
                $query = $this->getProperty('query','');
                if (!empty($query)) {
                    $c->where(array('modUser.username:LIKE' => '%'.$query.'%'));
                    $c->orCondition(array('Profile.fullname:LIKE' => '%'.$query.'%'));
                    $c->orCondition(array('Profile.email:LIKE' => '%'.$query.'%'));
                    $c->orCondition(array('modUser.id:LIKE' => '%'.$query.'%'));
                }
        
                $userGroup = $this->getProperty('usergroup',0);
        		if (empty($userGroup)){ 
        			$userGroup=$this->modx->getOption('usergroupauth');
        		}
                if (!empty($userGroup) AND $userGroup != 'all') {
        			$groups = explode(',',$userGroup);
                    $c->innerJoin('modUserGroupMember','UserGroupMembers');
        			foreach($groups as $group){
        				$c->orCondition(array(
        					'UserGroupMembers.user_group' => $group
        				));
        			}
        
                }
                return $c;
            }
        


        Disconnect and reconnect this user manager, and the list user will be filtered with this new param defined.
          • 3749
          • 24,544 Posts
          I'm glad you found something that works.

          The point of doing it in a plugin is that it won't be overwritten or need testing every time you upgrade MODX to a new version.
            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
            • 37927
            • 7 Posts
            You think it's possible to override this method in a plugin ?
              • 3749
              • 24,544 Posts
              I don't think so. You'd have to write a plugin connected to a bunch of different events. Some of the things you want might not have an event attached.

              If occurs to me that you could extend the modUser Object and override the getList method. The trouble with this is that there are a few extras that also extend modUser (Discuss is one) and there might be a conflict (or not -- it might work fine).

              http://rtfm.modx.com/revolution/2.x/developing-in-modx/advanced-development/extending-moduser

              Basically, you'd create a new object called myUser that extends modUser and it's only method would be getList, which would contain your code above. Then, you'd change the class_key of all users to 'myUser' and make sure that class_key is set to myUser for all newly created users. That should protect you from any upgrades.

              I would not use extUser as the class_key in case some extra uses that, but otherwise following the tutorial should work fine.

              BTW, I usually recommend ClassExtender for extending modUser, but I don't think it's a good fit for your use case. It doesn't change the class_key (unless you make it), it's designed for adding extra user fields, and it creates a new table in the DB that you don't need.
                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
                • 37927
                • 7 Posts
                Users management is very powerfull in modx, it could be a good improvment to include this feature in next release.
                  • 3749
                  • 24,544 Posts
                  I'm pretty sure it's planned for MODX 3.
                    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