Add a user to a group

Output:

    an empty dictionary
514112
def cli(ctx, group, user):
    
    return ctx.gi.users.add_to_group(group, user)
1254062
def output_list(self, category):
        """"""
        print('{} users:'.format(category))
        for user in getattr(self.sub, category):
            print('  {}'.format(user))
40038
def _UpdateUserGroups(self, user, groups):
    
    groups = ','.join(groups)
    self.logger.debug('Updating user %s with groups %s.', user, groups)
    command = self.usermod_cmd.format(user=user, groups=groups)
    try:
      subprocess.check_call(command.split(' '))
    except subprocess.CalledProcessError as e:
      self.logger.warning('Could not update user %s. %s.', user, str(e))
      return False
    else:
      self.logger.debug('Updated user account %s.', user)
      return True
259077
def AddUser(self, uid, username, active):
    '''
    '''
    user_path = '/org/freedesktop/login1/user/%i' % uid
    if user_path in mockobject.objects:
        raise dbus.exceptions.DBusException('User %i already exists' % uid,
                                            name=MOCK_IFACE + '.UserExists')

    self.AddObject(user_path,
                   'org.freedesktop.login1.User',
                   {
                       'Sessions': dbus.Array([], signature='(so)'),
                       'IdleHint': False,
                       'DefaultControlGroup': 'systemd:/user/' + username,
                       'Name': username,
                       'RuntimePath': '/run/user/%i' % uid,
                       'Service': '',
                       'State': (active and 'active' or 'online'),
                       'Display': ('', dbus.ObjectPath('/')),
                       'UID': dbus.UInt32(uid),
                       'GID': dbus.UInt32(uid),
                       'IdleSinceHint': dbus.UInt64(0),
                       'IdleSinceHintMonotonic': dbus.UInt64(0),
                       'Timestamp': dbus.UInt64(42),
                       'TimestampMonotonic': dbus.UInt64(42),
                   },
                   [
                       ('Kill', 's', '', ''),
                       ('Terminate', '', '', ''),
                   ])

    return user_path
495248
def add_users(self, category):
        """"""
        mapping = {'banned': 'ban', 'contributor': 'make_contributor',
                   'moderator': 'make_moderator'}

        if category not in mapping:
            print('{!r} is not a valid option for --add'.format(category))
            return
        func = getattr(self.sub, mapping[category])
        print('Enter user names (any separation should suffice):')
        data = sys.stdin.read().strip()
        for name in re.split('[^A-Za-z0-9_]+', data):
            func(name)
            print('Added {!r} to {}'.format(name, category))
990776
function addGroup(group, options) {
  options = _.opts(options, {gid: null});
  if (!runningAsRoot()) return;
  if (!group) throw new Error('You must provide a group');
  if (groupExists(group)) {
    return;
  }

  if (isPlatform('linux')) {
    _addGroupLinux(group, options);
  } else if (isPlatform('osx')) {
    _addGroupOsx(group, options);
  } else if (isPlatform('windows')) {
    throw new Error(`Don't know how to add group ${group} on Windows`);
  } else {
    throw new Error(`Don't know how to add group ${group} in current platform`);
  }
}
533326
def add_user(username='',password='',group='', site_user=False):
    
    if group: group = '-g %s'% group
    if not site_user:
        run('echo %s:%s > /tmp/users.txt'% (username,password))
    if not site_user:
        sudo('useradd -m -s /bin/bash %s %s'% (group,username))
        sudo('chpasswd < /tmp/users.txt')
        sudo('rm -rf /tmp/users.txt')
    else:
        sudo('useradd -M -d /var/www -s /bin/bash %s'% username)
        sudo('usermod -a -G www-data %s'% username)
1048228
def add_member(self, user):
        
        user = Transform.to_user(user)
        data = {
            'id': user
        }
        extra = {
            'resource': self.__class__.__name__,
            'query': {
                'id': self.id,
                'data': data,
            }
        }
        logger.info('Adding team member using id', extra=extra)
        response = self._api.post(
            url=self._URL['members_query'].format(id=self.id), data=data)
        member_data = response.json()
        return TeamMember(api=self._api, **member_data)
401086
def usergroups_create(self, *, name: str, **kwargs) -> SlackResponse:
        
        self._validate_xoxp_token()
        kwargs.update({"name": name})
        return self.api_call("usergroups.create", json=kwargs)
1241109
def adduser(app, username, password):
    """"""
    with app.app_context():
        create_user(username=username, password=password)
        click.echo('user created!')
688180
def add(name,
        uid=None,
        gid=None,
        groups=None,
        home=None,
        shell=None,
        unique=True,
        fullname='',
        roomnumber='',
        workphone='',
        homephone='',
        createhome=True,
        **kwargs):
    '''
    
    '''
    if salt.utils.data.is_true(kwargs.pop('system', False)):
        log.warning('solaris_user module does not support the \'system\' '
                    'argument')
    if kwargs:
        log.warning('Invalid kwargs passed to user.add')

    if isinstance(groups, six.string_types):
        groups = groups.split(',')
    cmd = ['useradd']
    if shell:
        cmd.extend(['-s', shell])
    if uid:
        cmd.extend(['-u', uid])
    if gid:
        cmd.extend(['-g', gid])
    if groups:
        cmd.extend(['-G', ','.join(groups)])
    if createhome:
        cmd.append('-m')
    if home is not None:
        cmd.extend(['-d', home])
    if not unique:
        cmd.append('-o')
    cmd.append(name)

    if __salt__['cmd.retcode'](cmd, python_shell=False) != 0:
        return False
    else:
        # At this point, the user was successfully created, so return true
        # regardless of the outcome of the below functions. If there is a
        # problem wth changing any of the user's info below, it will be raised
        # in a future highstate call. If anyone has a better idea on how to do
        # this, feel free to change it, but I didn't think it was a good idea
        # to return False when the user was successfully created since A) the
        # user does exist, and B) running useradd again would result in a
        # nonzero exit status and be interpreted as a False result.
        if fullname:
            chfullname(name, fullname)
        if roomnumber:
            chroomnumber(name, roomnumber)
        if workphone:
            chworkphone(name, workphone)
        if homephone:
            chhomephone(name, homephone)
        return True
74072
def add(name, gid=None, system=False, root=None):
    '''
    
    '''
    cmd = 'mkgroup '
    if system and root is not None:
        cmd += '-a '

    if gid:
        cmd += 'id={0} '.format(gid)

    cmd += name

    ret = __salt__['cmd.run_all'](cmd, python_shell=False)

    return not ret['retcode']
1048023
def push(self, my_dict, key, element):
        '''  '''
        group_info = my_dict.setdefault(key, [])
        if isinstance(group_info, dict):
            host_list = group_info.setdefault('hosts', [])
            host_list.append(element)
        else:
            group_info.append(element)
88869
def add_user(self, attrs):
        
        username = attrs[self.key]
        if username in self.users:
            raise UserAlreadyExists(username, self.backend_name)
        self.users[username] = attrs
        self.users[username]['groups'] = set([])
362022
def add_to_groups(self, username, groups):
        
        self._check_fix_users(username)
        current_groups = self.users[username]['groups']
        new_groups = current_groups | set(groups)
        self.users[username]['groups'] = new_groups
189475
def add_group(network_id, group,**kwargs):
    

    user_id = kwargs.get('user_id')
    try:
        net_i = db.DBSession.query(Network).filter(Network.id == network_id).one()
        net_i.check_write_permission(user_id=user_id)
    except NoResultFound:
        raise ResourceNotFoundError("Network %s not found"%(network_id))

    res_grp_i = net_i.add_group(group.name, group.description, group.status)

    hdb.add_resource_attributes(res_grp_i, group.attributes)

    db.DBSession.flush()
    if group.types is not None and len(group.types) > 0:
        res_types = []
        res_attrs = []
        res_scenarios = {}
        for typesummary in group.types:
            ra, rt, rs = template.set_resource_type(res_grp_i,
                                        typesummary.id,
                                         **kwargs)
            res_types.append(rt)
            res_attrs.extend(ra)
            res_scenarios.update(rs)#rs is a dict
        if len(res_types) > 0:
            db.DBSession.bulk_insert_mappings(ResourceType, res_types)
        if len(res_attrs) > 0:
            db.DBSession.bulk_insert_mappings(ResourceAttr, res_attrs)

            new_res_attrs = db.DBSession.query(ResourceAttr).order_by(ResourceAttr.id.desc()).limit(len(res_attrs)).all()
            all_rs = []
            for ra in new_res_attrs:
                ra_id = ra.id
                if ra.attr_id in res_scenarios:
                    rs_list = res_scenarios[ra.attr_id]
                    for rs in rs_list:
                        rs_list[rs]['resource_attr_id'] = ra_id
                        all_rs.append(rs_list[rs])

            if len(all_rs) > 0:
                db.DBSession.bulk_insert_mappings(ResourceScenario, all_rs)


    db.DBSession.refresh(res_grp_i)

    return res_grp_i
425127
def add_user_to_group(self, username, groupname, raise_on_error=False):
        
        data = {
                'name': groupname,
        }
        response = self._post(self.rest_url + "/user/group/direct",
                              params={"username": username,},
                              data=json.dumps(data))

        if response.status_code == 201:
            return True

        if raise_on_error:
            raise RuntimeError(response.json()['message'])

        return False