Verify Group membership

@param   mixed   group identifier to check for membership
@param   string  group driver id or null to check all
@param   array   user identifier to check in form array(driver_id, user_id)
@return  bool
178818
public function member($group, $driver = null, $user = null)
	{
		$user = $user ?: $this->get_user_id();

		if ($driver === null)
		{
			foreach (\Auth::group(true) as $g)
			{
				if ($g->member($group, $user))
				{
					return true;
				}
			}

			return false;
		}

		return \Auth::group($driver)->member($group, $user);
	}
797114
def has_group(user, group_name):
    '''
    
    '''
    if user.groups.filter(name=group_name).exists():
        return True
    return False
1007032
public function assertUserWithNameDoesntExistInGroup( $username, $parentGroup )
    {
        Assertion::assertFalse(
            $this->getUserManager()->checkUserExistenceByUsername( $username, $parentGroup ),
            "User with name '$username' was found in parent group '$parentGroup'."
        );
    }
1119936
def check_membership(self, groups):
        '''  '''
        if not groups or groups == ['']:
            return True
        if self.request.user.is_superuser:
            return True
        user_groups = self.request.user.groups.values_list("name", flat=True)
        return set(groups).intersection(set(user_groups))
618314
protected function checkUserGroup()
    {
        $isValid = true;

        $payPalPayment = $this->getPayment();
        $groups = $payPalPayment->getGroups();

        if ($groups && $groups->count() > 0) {
            $isValid = $this->isUserAssignedToGroup($groups);
        }

        return $isValid;
    }
1065703
protected function verifyGroupRequirements()
    {
        if (isset($this->requiredFieldsGroups)) {
            $fields = $this->requiredFieldsGroups->getArrayCopy();

            $emptyFlag = false;
            $groupsFormatted = [];

            foreach ($fields as $group => $groupFields) {
                $groupsFormatted[] = sprintf(
                    '%s (%s)',
                    ucfirst($group),
                    implode(', ', $groupFields)
                );

                foreach ($groupFields as $field) {
                    if (!empty($this->$field)) {
                        $emptyFlag = true;
                    }
                }
            }

            if (!$emptyFlag) {
                throw new \Genesis\Exceptions\ErrorParameter(
                    sprintf(
                        'One of the following group/s of field/s must be filled in: %s%s',
                        PHP_EOL,
                        implode(
                            PHP_EOL,
                            $groupsFormatted
                        )
                    ),
                    true
                );
            }
        }
    }
199524
function groupMembershipMiddleware(groups) {
		if (typeof groups === 'string') {
			groups = [groups];
		}
		return function hasGroupMembership(req, res, next) {
			if (req.locals.user) {
				const userGroups = req.locals.user.groups || [];
				for (let group of groups) {
					if (userGroups.indexOf(group) !== -1) {
						debug(`User has the '${group}' Group.`);
						return next();
					}
				}
			}
			debug(`User is not a member of one of [${groups.join(',')}] Group(s).`);
			next(new restifyErrors.ForbiddenError('No execute permissions on endpoint'));
		}
	}
481614
public function get_name($group = null)
	{
		// if no group is given
		if ($group === null)
		{
			// try get the the group assigned to the logged-in user
			if ( ! $login = \Auth::instance() or ! is_array($groups = $login->get_groups()))
			{
				return false;
			}
			$group = isset($groups[0][1]) ? $groups[0][1] : null;
		}

		// if it's a group id, find the corresponding object
		elseif (is_numeric($group) and isset(static::$_valid_groups[$group]))
		{
			$group = static::$_valid_groups[$group];
		}

		// if the group was found, return the name
		if ($group instanceOf Model\Auth_Group)
		{
			return $group->name;
		}
		else
		{
			// no group found, so no name either
			return null;
		}
	}
385030
public function matchGroup($user){
        if($this->groups == '*'){
            return true;
        }
        return empty($this->groups) || in_array($user->identity->getGroup(), $this->groups, true);
    }
475919
public function ensureUserGroupExists( $name, $parentGroupName = null )
    {
        if ( $parentGroupName )
        {
            // find parent group name
            $searchResults = $this->searchUserGroups( $parentGroupName );
            if ( !empty( $searchResults ) )
            {
                $parentGroup = $this->loadUserGroup( $searchResults[0]->valueObject->contentInfo->id );
                $parentGroupLocationId = $searchResults[0]->valueObject->contentInfo->mainLocationId;
            }
            else
            {
                // parent group not found, create it
                $parentGroup = $this->createUserGroup( $parentGroupName );
                $parentGroupLocationId = $parentGroup->getVersionInfo()->getContentInfo()->mainLocationId;
            }
        }
        else
        {
            $parentGroup = null;
            $parentGroupLocationId = null;
        }

        $searchResults = $this->searchUserGroups( $name, $parentGroupLocationId );

        if ( !empty( $searchResults ) )
        {
            // found existing child group, return it
            return $this->loadUserGroup( $searchResults[0]->valueObject->contentInfo->id );
        }
        // else, did not find existing group - create one with given name.
        return $this->createUserGroup( $name, $parentGroup );
    }
818552
public function inGroup($alias)
    {
        if ($this->isGuest) {
            return false;
        }
        
        $identity = $this->identity;
        
        if (!$identity instanceof GroupUserIdentityInterface) {
            throw new InvalidConfigException('The $identityClass must be instance of luya\web\GroupUserIdentityInterface.');
        }
        
        
        $groups = (array) $alias;
        foreach ($groups as $groupAlias) {
            if (in_array($groupAlias, $identity->authGroups())) {
                return true;
            }
        }
        
        return false;
    }
1119851
public function countAuthenticationMetaByUserGroup($id_group = NULL, $id_authentication = NULL)
    {
        $this->connection();
        $db = DB::table('authentication_meta');
        if (!empty($id_group)) {
            $db->where('id_group', self::OPERATOR_EQUAL_TO, $id_group);
        }
        if (!empty($id_authentication)) {
            $db->where('id_authentication', self::OPERATOR_EQUAL_TO, $id_authentication);
        }
        $result = $db->count('id');

        return $result;
    }
548515
public function member($group_id, $user = null)
	{
		// if it's not a group id, fetch it from the object
		if ( ! is_numeric($group_id))
		{
			$group_id = $group_id->id;
		}

		// do we know this group?
		if (isset(static::$_valid_groups[$group_id]))
		{
			// if no user is given
			if ($user === null)
			{
				// get the groups of the logged-in user
				$groups = \Auth::instance()->get_groups();
			}
			else
			{
				// get the groups if the given user instance
				$groups = \Auth::instance($user[0])->get_groups();
			}

			// if no group info could be retrieved, the user can't be a member
			if ( ! $groups)
			{
				return false;
			}

			// check for membership
			foreach($groups as $group)
			{
				if ($group[0] === $this->id and $group_id === (int) $group[1]->id)
				{
					return true;
				}
			}
		}

		return false;
	}
107961
public function can_access_group(stdClass $user, int $groupid) : bool {
        if ($this->can_access_all_groups($user)) {
            // This user has access to all groups.
            return true;
        }

        // This is a group discussion for a forum in separate groups mode.
        // Check if the user is a member.
        // This is the most expensive check.
        return groups_is_member($groupid, $user->id);
    }
1363200
public function addGroup($group)
    {
        if (is_string($group)) {
            // If the group is a string, we'll assume the dev is passing
            // in a DN string of the group. We'll try to locate it.
            $group = $this->query->newInstance()->findByDn($group);
        }

        if ($group instanceof Group) {
            // If the group is Group model instance, we can
            // add the current models DN to the group.
            return $group->addMember($this->getDn());
        }

        return false;
    }
1311073
public function userHasGroup($groupName, DeterminableUserInterface $user)
    {
        $userHasGroup = false;
        if (true === in_array($groupName, $user->getGroups())) {
            $userHasGroup = true;
        }
        return $userHasGroup;
    }
189188
public function getGroupData($key, $id = 0)
    {
        // Get Group id
        if (!$id) {
            $id = $this->getUserData('group_id');
        } else {
            $id = abs((int)$id);
        }

        // Check or init cache
        if (!isset(self::$cached_group_data[$id])) {
            $group = new AdminUserGroup($id);
            self::$cached_group_data[$id] = $group->getAsArray();
        }

        return isset(self::$cached_group_data[$id][$key]) ? self::$cached_group_data[$id][$key] : NULL;
    }