Function which checks if admin user has super-admin role

@param $adminExists
962187
private function checkIfHaveSuperAdminRole($adminExists)
    {
        $hasRole = $adminExists->hasRole('super-admin');

        if( ! $hasRole ) {
            $this->comment("{$this->email} account doesn't have super-admin role!");

            if( $this->confirm('Do you want to add super-admin role? [y|N]') ) {

                DB::beginTransaction();

                try {
                    $adminExists->assignRoleBySlug('super-admin');
                } catch ( \Exception $e ) {
                    DB::rollback();

                    $this->error($e->getMessage());
                    exit;
                }

                $this->info('Super admin role has been added');

                DB::commit();
            }

            exit;
        }
    }
328491
private function checkIfAdminExists()
    {
        $adminExists = HCUsers::where('email', $this->email)->first();

        if( ! is_null($adminExists) ) {

            $this->checkIfHaveSuperAdminRole($adminExists);

            $this->info('Admin account already exists!');

            if( $this->confirm('Do you want to change its password? [y|N]') ) {
                $this->changePassword($adminExists);
            }

            exit;
        }
    }
1207982
public function hasAllRoles(...$roles) {
		foreach ($roles as $role) {
			if (!$this->hasRole($role)) {
				return false;
			}
		}

		return true;
	}
237406
public function hasRoles($roles)
    {
        $roles = is_array($roles) ? $roles : func_get_args();

        foreach ($roles as $role) {
            if ($this->hasRole($role)) {
                return true;
            }
        }

        return false;
    }
240921
protected function hasRole( array $roles )
	{
		if( $this->has( 'security.authorization_checker' ) && $this->get( 'security.token_storage' )->getToken() )
		{
			$checker = $this->get( 'security.authorization_checker' );

			foreach( $roles as $role )
			{
				if( $checker->isGranted( $role ) ) {
					return true;
				}
			}
		}

		return false;
	}
620426
protected function isAll(array $roles)
    {
        foreach ($roles as $role) {
            if (!$this->hasRole($role)) {
                return false;
            }
        }

        return true;
    }
720647
def is_chat_admin(user):
    """"""
    from indico_chat.plugin import ChatPlugin
    return ChatPlugin.settings.acls.contains_user('admins', user)
245787
public boolean isAdministrator(AuthContext ctx) {
        return ctx.getUsername() != null && ctx.getUsername().equals(adminName) &&
                ctx.getPassword() != null && ctx.getPassword().equals(adminPass);
    }
229756
public function hasRole($role)
    {
        $role = strtoupper($role);

        if ($role == 'ROLE_USER') {
            return true;
        }

        if (in_array($role, $this->roles)) {
            return true;
        }

        return false;
    }
220250
final public function hasRequiredRole(UserInterface $user = null, array $roles = [])
    {
        if ($user != null) {
            // Check if user's roles matches required roles
            $userRoles = $user->getRoles();

            foreach ($userRoles as $role) {
                if (\in_array($role, $roles)) {
                    return true;
                }
            }
        }

        return false;
    }
1237079
private function parseAdmins(&$admins)
    {
        if (!empty($admins)) {
            foreach ($admins as &$admin) {
                if (isset($admin['profile'])) {
                    switch ($admin['profile']) {
                        case Security::MANAGER_ID_TOKEN:
                            $admin['class'] = 'warning';
                            break;
                        case Security::ADMIN_ID_TOKEN:
                            $admin['class'] = 'info';
                            break;
                        default:
                        case Security::USER_ID_TOKEN:
                            $admin['class'] = 'primary';
                            break;
                    }
                } else {
                    $admin['class'] = 'primary';
                }
            }
        }
    }
170530
public function configureQuery(AdminInterface $admin, ProxyQueryInterface $query, $context = 'list')
    {
        // Don't filter for admins and for not ACL enabled classes and for command cli
        if (
            !$admin->isAclEnabled()
            || !$this->tokenStorage->getToken()
            || $admin->isGranted(sprintf($admin->getSecurityHandler()->getBaseRole($admin), 'ADMIN'))
        ) {
            return;
        }

        // Retrieve current logged user SecurityIdentity
        $user = $this->tokenStorage->getToken()->getUser();
        $userSecurityIdentity = UserSecurityIdentity::fromAccount($user);

        // Retrieve current logged user roles
        $userRoles = $user->getRoles();

        // Find child roles
        $roles = array();
        foreach ($userRoles as $userRole) {
            $roles[] = ($userRole instanceof RoleInterface) ? $userRole : new Role($userRole);
        }

        $reachableRoles = $this->roleHierarchy->getReachableRoles($roles);

        // Get identity ACL user identifier
        $identifiers[] = sprintf('%s-%s', $userSecurityIdentity->getClass(), $userSecurityIdentity->getUsername());

        // Get identities ACL roles identifiers
        foreach ($reachableRoles as $reachableRole) {
            $role = $reachableRole->getRole();
            if (!in_array($role, $identifiers)) {
                $identifiers[] = $role;
            }
        }

        $identityStmt = $this->databaseConnection->executeQuery(
            'SELECT id FROM acl_security_identities WHERE identifier IN (?)',
            array($identifiers),
            array(Connection::PARAM_STR_ARRAY)
        );

        $identityIds = array();
        foreach ($identityStmt->fetchAll() as $row) {
            $identityIds[] = $row['id'];
        }

        // Get class ACL identifier
        $classType = $admin->getClass();
        $classStmt = $this->databaseConnection->prepare('SELECT id FROM acl_classes WHERE class_type = :classType');
        $classStmt->bindValue('classType', $classType);
        $classStmt->execute();

        $classId = $classStmt->fetchColumn();

        if (!empty($identityIds) && $classId) {
            $entriesStmt = $this->databaseConnection->executeQuery(
                'SELECT DISTINCT object_identifier FROM acl_entries AS ae JOIN acl_object_identities AS aoi ON ae.object_identity_id = aoi.id WHERE ae.class_id = ? AND ae.security_identity_id IN (?) AND (? = ae.mask & ? OR ? = ae.mask & ? OR ? = ae.mask & ? OR ? = ae.mask & ?)',
                array(
                    $classId,
                    $identityIds,
                    MaskBuilder::MASK_VIEW,
                    MaskBuilder::MASK_VIEW,
                    MaskBuilder::MASK_OPERATOR,
                    MaskBuilder::MASK_OPERATOR,
                    MaskBuilder::MASK_MASTER,
                    MaskBuilder::MASK_MASTER,
                    MaskBuilder::MASK_OWNER,
                    MaskBuilder::MASK_OWNER,
                ),
                array(
                    \PDO::PARAM_INT,
                    Connection::PARAM_INT_ARRAY,
                    \PDO::PARAM_INT,
                    \PDO::PARAM_INT,
                    \PDO::PARAM_INT,
                    \PDO::PARAM_INT,
                    \PDO::PARAM_INT,
                    \PDO::PARAM_INT,
                    \PDO::PARAM_INT,
                    \PDO::PARAM_INT,
                )
            );

            $ids = array();
            foreach ($entriesStmt->fetchAll() as $row) {
                $ids[] = $row['object_identifier'];
            }

            if (count($ids)) {
                $query
                    ->andWhere('o IN (:ids)')
                    ->setParameter('ids', $ids)
                ;

                return;
            }
        }

        // Display an empty list
        $query->andWhere('1 = 2');
    }
830299
protected function isAdmin(AccountInterface $account)
    {
        /** @var Model $resource */
        if ($this->isAuthenticated($account) === true) {
            /** @var User $user */
            $user    = $account->user();
            $isAdmin = $user->hasRole(Role::ENUM_ROLE_ADMIN_ID);

            return $isAdmin;
        }

        return false;
    }
742868
def check_is_admin(context):
    """"""
    init()
    credentials = context.to_policy_values()
    target = credentials
    return _ENFORCER.authorize('admin_required', target, credentials)
322445
public function hasRole($role, $user = null)
    {
        $roleName = $role instanceof Role ? $role->getRole() : $role;

        $user = $user ?: $this->getUser();

        if (!($user instanceof UserInterface)) {
            return false;
        }

        if (null === $this->roleHierarchy) {
            return in_array($roleName, $user->getRoles(), true);
        }

        $userRoles = $this->roleHierarchy->getReachableRoles($this->getUserRolesAsObjects($user));
        foreach ($userRoles as $userRole) {
            if ($roleName === $userRole->getRole()) {
                return true;
            }
        }

        return false;
    }
1290577
public function handle($roles)
    {
        if ($this->auth->check()) {
            return $this->auth->user()->hasRole($roles);
        }

        return false;
    }
1287186
public function hasRole(string $role): bool
    {
        return (null !== $this->roles) ? \in_array($role, $this->roles) : false;
    }