We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42802
    • 96 Posts
    Sebastian Zahn | ingroove.uy Reply #1, 12 years, 9 months ago
    Hi!
    I need to create settings for some users ( manager language, default media source,etc ) and i see that they only can be applied for each user instead of a usergroup, for example, i create a usergroup with specific permissions of what the clients ( site administrators ) can see and do in the manager, and all the client users will be assigned to this usergroup, but the user settings must be created for each user, and if the client want to add a user he must creat all the settings himself ( complicated task for a client ), or DUPLICATE an existant user.

    I think Modx is organized in a very efficient and clever way, so I think there must be a simpler way to do this, for example, settings on usergroups.

    Any ideas? Thanks! Sebastián.
    Sorry for my bad English smiley

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

    • discuss.answer
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      That's definitely a "to-do" item. Unfortunately for now it's just not available.
        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
        • 42802
        • 96 Posts
        Sebastian Zahn | ingroove.uy Reply #3, 12 years, 9 months ago
        Thanks for your answer Susan!

        Quote from: sottwell at Dec 10, 2013, 09:28 AM
        That's definitely a "to-do" item. Unfortunately for now it's just not available.
          • 42802
          • 96 Posts
          Sebastian Zahn | ingroove.uy Reply #4, 12 years, 9 months ago
          I think this task and the fact that client site admins can see the main administrator account ( can´t discriminate between the administrator accounts and other level accounts ) are things "to-do" in the user section of this excellent framework.

          Quote from: sottwell at Dec 10, 2013, 09:28 AM
          That's definitely a "to-do" item. Unfortunately for now it's just not available.
            • 3749
            • 24,544 Posts
            It could be done very easily with a plugin attached to OnUserAddToGroup *if* MODX invoked that event when a user joined a group. Unfortunately, I don't think it does.

            I thought a utility snippet to do it would be fairly simple, but it's a little trickier than I thought. Here it is (untested):

            <?php
            /* UserSettings snippet */
            /* Create user settings for a particular user group */
            
            $groupName = 'MyGroup';
            $namespace = 'user_setting';
            
            /* Set the right-hand side of the 'key' and 'value' fields. */
            /* Those are the only parts of the array that are used */
            $settings = array(
                'setting1' => array(
                    'key'   => 'key_1',
                    'value' => 'value_1',
                ),
                'setting2' => array(
                    'key'   => 'key_2',
                    'value' => 'value_2',
                ),
                /* etc. */
            );
            
            $namespace = $modx->getObject('modNamspace', array('name' => $namespace));
            if (!$namespace) {
                $namespace = $modx->newObject('modNamespace');
                $namespace->set('name', $namespace);
                $namespace->set('path','{core_path}components/usersetting/');
                $namespace->set('assets_path', '');
                $namespace->save();
            }
            
            $userGroup = $modx->getObject('modUserGroup', array('name' => $groupName));
            
            if ($userGroup) {
                $ugms = $userGroup->getMany('UserGroupMembers');
                foreach ($ugms as $userGroupMember) {
                    $id = $userGroupMember->get('member');
                    foreach ($settings as $setting) {
                        $newSetting = $modx->newObject('modUserSetting');
                        $newSetting->set('key', $setting['key']);
                        $newSetting->set('value', $setting['value']);
                        $newSetting->set('namespace', $namespace);
                        $newSetting->save();
                    }
                }
            }
            


            The settings won't have descriptions and the "name" shown in the grid will be the same as the key. Solving that would involve creating several directories and then creating and writing to a lexicon file. This would make a nice CMP if someone had time to create it.

            BTW, it is possible to restrict which users a user can see and modify in the Manager by user group, but it's not pretty. I recently did it for someone and it involved duplicating about a dozen user management JS and PHP files and modifying them all. wink

              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