Form Customization

Show Only Users in the Same Group

gourmet fare

Restrict Users List

Sometimes you want users to be able to see only certain users in the Manage Users lists. There is no setting in MODX for this; if a user can manage users he can manage all of them. Here's a plugin to limit that list to only users of the same group.

m_dimitris asked...

Is it possible when a user with manager access enters the manager to be able to see ONLY the users that belong to the same usergroup in user page?

The Solution:

Bruno17 says...

At least, you can restrict the listing in the grid to users in the primarygroup only of the current user with a plugin.

  if ($modx->context->get('key') == "mgr") {
    switch ($modx->event->name) {
      case 'OnMODXInit':
        $action = $modx->getOption('action', $_REQUEST, '');
        if ($action == 'security/user/getList') {
          $group = $modx->user->getPrimaryGroup();
          $_POST['usergroup'] = $group->get('id');
        }
        break;
    }
  }
  return;
  

What's the Story?

This plugin, with its System Events set to OnMODXInit, will only show the Manager user a list of the users in the same group as his primary group.

You can exclude Sudo users from this restriction by adding a single line:

  if ($modx->context->get('key') == "mgr") {
    if ($modx->user->get('sudo')) { return; }
  ...

This will simply stop the plugin from continuing if the user is a Sudo user.