@Given there is a User with name :username with id :id in :parentGroup group

Ensures a user with username ':username' and id ':id' exists as a child of ':parentGroup' user group, can create either one.
187891
public function iHaveUserWithIdInGroup( $username, $id, $parentGroup )
    {
        $user = $this->getUserManager()->ensureUserExists( $username, $parentGroup );
        $this->addValuesToMap( $id, $user->id );
    }
797114
def has_group(user, group_name):
    '''
    
    '''
    if user.groups.filter(name=group_name).exists():
        return True
    return False
594334
def child(data, options = {}, &block)
        return unless data.present? && resolve_condition(options)

        name   = is_name_value?(options[:root]) ? options[:root] : data_name(data)
        object = data_object(data)

        engine_options = @options.slice(:child_root)
        engine_options[:root] = is_collection?(object) && options.fetch(:object_root, @options[:child_root]) # child @users
        engine_options[:object_root_name] = options[:object_root] if is_name_value?(options[:object_root])

        object = { object => name } if data.is_a?(Hash) && object # child :users => :people

        engines << { create_key(name) => object_to_engine(object, engine_options, &block) }
      end
533441
def root
      if parent_ids.present?
        base_class.find(parent_ids.first)
      else
        self.root? ? self : self.parent.root
      end
    end
1150852
def assign_perm(perm, user_or_group, forum=None, has_perm=True):
    
    user, group = get_identity(user_or_group)
    perm = ForumPermission.objects.get(codename=perm)
    if user:
        return UserForumPermission.objects.create(
            forum=forum,
            permission=perm,
            user=user if not user.is_anonymous else None,
            anonymous_user=user.is_anonymous,
            has_perm=has_perm,
        )
    if group:
        return GroupForumPermission.objects.create(
            forum=forum, permission=perm, group=group, has_perm=has_perm,
        )
342118
public IdentityOperationResult createMembership(String userId, String groupId) {
    checkAuthorization(Permissions.CREATE, Resources.GROUP_MEMBERSHIP, groupId);
    UserEntity user = findUserById(userId);
    GroupEntity group = findGroupById(groupId);
    MembershipEntity membership = new MembershipEntity();
    membership.setUser(user);
    membership.setGroup(group);
    getDbEntityManager().insert(membership);
    createDefaultMembershipAuthorizations(userId, groupId);
    return new IdentityOperationResult(null, IdentityOperationResult.OPERATION_CREATE);
  }
114049
def user_in_group(user, group):
    """"""
    if isinstance(group, Group):
        return user_is_superuser(user) or group in user.groups.all()
    elif isinstance(group, six.string_types):
        return user_is_superuser(user) or user.groups.filter(name=group).exists()
    raise TypeError("'group' argument must be a string or a Group instance")
436844
def create_group(self, group_name, path='/'):
        
        params = {'GroupName' : group_name,
                  'Path' : path}
        return self.get_response('CreateGroup', params)
626187
public function iHaveUserGroupWithIdInGroup( $name, $id, $parentGroup )
    {
        $userGroup = $this->getUserGroupManager()->ensureUserGroupExists( $name, $parentGroup );
        $this->addValuesToMap( $id, $userGroup->id );
    }
120120
def add_user_to_group(self, user_name, group_name):
        

        res = self._make_ocs_request(
            'POST',
            self.OCS_SERVICE_CLOUD,
            'users/' + user_name + '/groups',
            data={'groupid': group_name}
        )

        if res.status_code == 200:
            tree = ET.fromstring(res.content)
            self._check_ocs_status(tree, [100])
            return True

        raise HTTPResponseError(res)
852903
public function assertUserGroupWithNameExistsInGroup( $name, $parentGroup )
    {
        Assertion::assertTrue(
            $this->getUserGroupManager()->checkUserGroupExistenceByName( $name, $parentGroup ),
            "Couldn't find UserGroup with name '$name' in parent group '$parentGroup'."
        );
    }
502208
public function checkUserExistenceByEmail( $email, $parentGroupName = null )
    {
        /** @var \eZ\Publish\API\Repository\Repository $repository */
        $repository = $this->getRepository();
        $userService = $repository->getUserService();

        $existingUsers = $userService->loadUsersByEmail( $email );
        if ( count( $existingUsers ) == 0 )
        {
            return false;
        }

        if ( $parentGroupName )
        {
            foreach ( $existingUsers as $user )
            {
                $userGroups = $userService->loadUserGroupsOfUser( $user );
                foreach ( $userGroups as $userGroup )
                {
                    if ( $userGroup->getFieldValue( 'name' ) == $parentGroupName )
                        return true;
                }
            }
        }

        return false;
    }
914697
public Group getOrCreateGroup(JackrabbitSession session, UserManager userManager,
                                  String path)
            throws RepositoryException {
        String[] pathAndName = pathAndName(path);
        Group group = (Group) userManager.getAuthorizable(pathAndName[1]);
        LOG.debug("group.check: " + pathAndName[1] + " - " + group);
        if (group == null) {
            LOG.info("group.create: " + pathAndName[1]);
            group = userManager.createGroup(new NamePrincipal(pathAndName[1]), pathAndName[0]);
        }
        return group;
    }
16871
public function assertUserGroupWithNameDoesntExistInGroup( $name, $parentGroup )
    {
        Assertion::assertFalse(
            $this->getUserGroupManager()->checkUserGroupExistenceByName( $name, $parentGroup ),
            "UserGroup with name '$name' was found in parent group '$parentGroup'."
        );
    }
931611
def create(username, groups = '', opts = {})
      payload = {
        :account => {
          :username => username,
          :comment  => '',
          :groups   => groups,
          :password => password_opts.merge(opts.fetch(:password, {}))
        }
      }
      @server.commands.get(post(payload)['command']['id'])
    end
1293309
@RequestMapping(
            value = "/v4-3/pags/{parentGroupName}.json",
            produces = MediaType.APPLICATION_JSON_VALUE,
            method = RequestMethod.POST)
    public @ResponseBody String createPagsGroup(
            HttpServletRequest request,
            HttpServletResponse res,
            @PathVariable("parentGroupName") String parentGroupName,
            @RequestBody String json) {

        res.setContentType(MediaType.APPLICATION_JSON_VALUE);

        /*
         * This step is necessary;  the incoming URLs will sometimes have '+'
         * characters for spaces, and the @PathVariable magic doesn't convert them.
         */
        String name;
        try {
            name = URLDecoder.decode(parentGroupName, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            res.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            return "{ 'error': '" + e.getMessage() + "' }";
        }

        IPersonAttributesGroupDefinition inpt;
        try {
            inpt = objectMapper.readValue(json, PersonAttributesGroupDefinitionImpl.class);
        } catch (Exception e) {
            res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            return "{ 'error': '" + e.getMessage() + "' }"; // should be escaped
        }

        // Obtain a real reference to the parent group
        EntityIdentifier[] eids =
                GroupService.searchForGroups(
                        name, IGroupConstants.SearchMethod.DISCRETE, IPerson.class);
        if (eids.length == 0) {
            res.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            return "{ 'error': 'Parent group does not exist: " + name + "' }";
        }
        IEntityGroup parentGroup =
                (IEntityGroup) GroupService.getGroupMember(eids[0]); // Names must be unique

        IPerson person = personManager.getPerson(request);
        IPersonAttributesGroupDefinition rslt;
        try {
            // A little weird that we need to do both;
            // need some PAGS DAO/Service refactoring
            rslt =
                    pagsService.createPagsDefinition(
                            person, parentGroup, inpt.getName(), inpt.getDescription());
            // NOTE:  We are also obligated to establish the backlink
            // testGroupDef --> groupDef;  arguably this backlink serves
            // little purpose and could be removed.
            for (IPersonAttributesGroupTestGroupDefinition testGroupDef : inpt.getTestGroups()) {
                // NOTE:  The deserializer handles testDef --> testGroupDef
                testGroupDef.setGroup(rslt);
            }
            rslt.setTestGroups(inpt.getTestGroups());
            rslt.setMembers(inpt.getMembers());
            pagsService.updatePagsDefinition(person, rslt);
        } catch (RuntimeAuthorizationException rae) {
            res.setStatus(HttpServletResponse.SC_FORBIDDEN);
            return "{ 'error': 'not authorized' }";
        } catch (IllegalArgumentException iae) {
            res.setStatus(HttpServletResponse.SC_CONFLICT);
            return "{ 'error': '" + iae.getMessage() + "' }";
        } catch (Exception e) {
            e.printStackTrace();
            res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            return "{ 'error': '" + e.getMessage() + "' }";
        }
        return respondPagsGroupJson(res, rslt, person, HttpServletResponse.SC_CREATED);
    }
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