Check if a role or permission is attach to the user in a same team.

@param  mixed  $rolePermission
@param  \Illuminate\Database\Eloquent\Model  $team
@return boolean
976646
public static function isInSameTeam($rolePermission, $team)
    {
        if (
            !Config::get('laratrust.use_teams')
            || (!Config::get('laratrust.teams_strict_check') && is_null($team))
        ) {
            return true;
        }

        $teamForeignKey = static::teamForeignKey();

        return $rolePermission['pivot'][$teamForeignKey] == $team;
    }
642464
public function hasRole($role)
    {
        if (!$this->roles->where('token', $role)->isEmpty()) {
            return true;
        }

        foreach ($this->groups as $group) {
            if (!$group->roles->where('token', $role)->isEmpty()) {
                return true;
            }
        }

        return false;
    }
100407
public function hasPermission($permissionName) {
		foreach ($this->role->sharedPermissionList as $permission) {
			if ($permission->name == $permissionName) {
				return true;
			}
		}

		return false;
	}
925377
public function registerManagersToTeam(Team $team, array $users)
    {
        $teamManagerRole = $team->getTeamManagerRole();

        if (!is_null($teamManagerRole) && 0 < count($users)) {
            $this->om->startFlushSuite();

            $team->setTeamManager($users[0]);

            foreach ($users as $user) {
                $this->roleManager->associateRole($user, $teamManagerRole);
            }
            $this->om->persist($team);
            $this->om->endFlushSuite();
        }
    }
274034
public function hasRole($id, $role)
    {
        if (!$user = $this->getUser($id)) {
            return false;
        }

        return in_array($role, $user['roles']);
    }
58451
public function assignRoles($groups, $bypassPermissionCheck = false)
    {
        // allow permission bypass only in the local environment
        if(config('app.env') == 'production' && $bypassPermissionCheck) {
            $bypassPermissionCheck = false;
        }

        // check if a user has permissions to access this link
        if(!$bypassPermissionCheck) {
            if (!self::hasAccess('user', 'update') && !self::hasAccess('user', 'create')) {
                return false;
            }
        }

        // First delete all previous relations
        RoleRelation::where('userID', $this->userID)->delete();

        $roles = [];

        // in case int is given
        if(is_numeric($groups)) {
            $groups = [$groups];
        }

        foreach ($groups as $groupID){
            $roles[] = [
              'userID' => $this->userID,
              'groupID' => (isset($groupID['groupID']) ? $groupID['groupID'] : $groupID)
            ];
        }

        if(RoleRelation::insert($roles)) {
            return true;
        }
        return false;
    }
91548
protected function checkRoleResource($role, $resource)
    {
        $resource = $this->checkResource($resource);
        $role = $this->checkRole($role);
        $roleId = ($role->getRoleId() == null) ? StorageInterface::ALL_ROLES : $role->getRoleId();
        $resrcId = ($resource->getResourceId() == null) ? StorageInterface::ALL_RESOURCES : $resource->getResourceId();
        if (!isset($this->permission[$roleId][self::NODE_RESOURCES][$resrcId][self::NODE_PERMISSION])) {
            $this->permission[$roleId][self::NODE_RESOURCES][$resrcId][self::NODE_PERMISSION] = [];
        }

        return $this;
    }
317986
public function hasMemberOnTeam($teamId)
    {
        /** @noinspection PhpUndefinedMethodInspection */
        $membersOnTeam = $this->members->filter(function ($member) use ($teamId) {
            return ($member->team_id === $teamId) && ($member->status !== "Invited");
        });
        /** @noinspection PhpUndefinedMethodInspection */
        return $membersOnTeam->count() > 0;
    }
1290240
public function hasRole($role)
    {
        $roles = $this->roles;
        foreach ($roles as $role_obj)
            if ($this->checkRole($role, $role_obj))
                return true;

        return false;
    }
409507
public function isCustomRole(Model $Model, $action = 'create') {
		foreach (array_keys($this->settings[$Model->alias]) as $role) {
			$method = "is" . Inflector::classify($role);
			if (
				!in_array($role, array('owner', 'groups', 'collaborators', 'perms'))
				&& $this->settings[$Model->alias][$role]['allow']
				&& $this->settings[$Model->alias][$role][$action]
				&& $this->{$method}($Model)
			) {
				return true;
			}
		}
		return false;
	}
846644
protected function checkPermission($permission = 'manage', $role = 'admin')
    {
        if ($this->auth->guest()) {
            return 401;
        }

        if ($this->auth->user()->can($permission) || $this->auth->user()->hasRole($role)) {
            return true;
        }

        return 403;
    }
1001855
public function userTeamIndexAction(Team $team, User $currentUser)
    {
        $workspace = $team->getWorkspace();
        $this->checkToolAccess($workspace);
        $isTeamMember = $this->isTeamMember($team, $currentUser);
        $isTeamManager = $this->isTeamManager($team, $currentUser);

        if (!$isTeamMember && !$isTeamManager) {

            throw new AccessDeniedException();
        }
        $users = $team->getUsers();
        $params = $this->teamManager->getParametersByWorkspace($workspace);

        return array(
            'workspace' => $workspace,
            'currentUser' => $currentUser,
            'users' => $users,
            'team' => $team,
            'params' => $params,
            'isTeamMember' => $isTeamMember,
            'isTeamManager' => $isTeamManager
        );
    }
8465
function hasPermission($Role, $Permission)
	{
		$Res = Jf::sql ( "
					SELECT COUNT(*) AS Result
					FROM {$this->tablePrefix()}rolepermissions AS TRel
					JOIN {$this->tablePrefix()}permissions AS TP ON ( TP.ID= TRel.PermissionID)
					JOIN {$this->tablePrefix()}roles AS TR ON ( TR.ID = TRel.RoleID)
					WHERE TR.Lft BETWEEN
					(SELECT Lft FROM {$this->tablePrefix()}roles WHERE ID=?)
					AND
					(SELECT Rght FROM {$this->tablePrefix()}roles WHERE ID=?)
					/* the above section means any row that is a descendants of our role (if descendant roles have some permission, then our role has it two) */
					AND TP.ID IN (
					SELECT parent.ID
					FROM {$this->tablePrefix()}permissions AS node,
					{$this->tablePrefix()}permissions AS parent
					WHERE node.Lft BETWEEN parent.Lft AND parent.Rght
					AND ( node.ID=? )
					ORDER BY parent.Lft
					);
					/*
					the above section returns all the parents of (the path to) our permission, so if one of our role or its descendants
					has an assignment to any of them, we're good.
					*/
					", $Role, $Role, $Permission );
		return $Res [0] ['Result'] >= 1;
	}
357922
public function hasPrivilege($privilege, $role = null)
    {
        if (is_null($role)) $role = $this->session->user_role;
        return (! $this->acl) || $this->acl->isAllowed($role, null, $privilege);
    }
1277602
public function hasRole($roleName, $includeGroup = true)
    {
        $roles = $this->getEntityRoles($includeGroup);
        $roleNames = array_map(function (Role $role) {
            return $role->getName();
        }, $roles);

        return in_array($roleName, $roleNames);
    }
955454
public function roleHasPermission($permission, $force = false)
    {
        if (! is_null($this->getUser())) {
            return $this->getUser()->roleHasPermission($permission, $force);
        }

        return false;
    }
701750
public boolean hasPermission(final Team team, String permissionName) {
        final Query query = pm.newQuery(Permission.class, "name == :permissionName && teams.contains(:team)");
        query.setResult("count(id)");
        return (Long) query.execute(permissionName, team) > 0;
    }