class_docstr: A filter to allow searching for related roles of a resource.
  
  Use in the api by adding something like:
  related_field_filters = {
    "roles": RelatedFieldFilter("name", FilterRelatedRoles),
  }
class_docstr_tok: ["A","filter","to","allow","searching","for","related","roles","of","a","resource",".","Use","in","the","api","by","adding","something","like",":","related_field_filters","=","{","``","roles","''",":","RelatedFieldFilter","(","``","name","''",",","FilterRelatedRoles",")",",","}"]
code: def apply(self, query: Query, value: Optional[Any]) -> Query:
      role_model = security_manager.role_model
      if value:
          return query.filter(
              role_model.name.ilike(f"%{value}%"),
          )
      return query
  
imports: from typing import Any, Optional
  from flask import g
  from flask_appbuilder.security.sqla.models import Role
  from flask_babel import lazy_gettext
  from sqlalchemy import and_, or_
  from sqlalchemy.orm.query import Query
  from superset import db, is_feature_enabled, security_manager
  from superset.connectors.sqla.models import SqlaTable
  from superset.models.core import Database
  from superset.models.dashboard import Dashboard, is_uuid
  from superset.models.embedded_dashboard import EmbeddedDashboard
  from superset.models.slice import Slice
  from superset.security.guest_token import GuestTokenResourceType, GuestUser
  from superset.utils.core import get_user_id
  from superset.utils.filters import get_dataset_access_filters
  from superset.views.base import BaseFilter
  from superset.views.base_api import BaseFavoriteFilter, BaseTagFilter
label_desc: Use image node_id 1 for calling the FilterRelatedRoles obj's underlying member method code with example usage: obj.apply(query, value) and returns: query, query