docstr: Dynamic Filters need to be applied to the Query before we filter
  databases with anything else. This way you can show/hide databases using
  Feature Flags for example in conjuction with the regular role filtering.
  If not, if an user has access to all Databases it would skip this dynamic
  filtering.
docstr_tok: ["Dynamic","Filters","need","to","be","applied","to","the","Query","before","we","filter","databases","with","anything","else",".","This","way","you","can","show\/hide","databases","using","Feature","Flags","for","example","in","conjuction","with","the","regular","role","filtering",".","If","not",",","if","an","user","has","access","to","all","Databases","it","would","skip","this","dynamic","filtering","."]
code: def apply(self, query: Query, value: Any) -> Query:
      """
      Dynamic Filters need to be applied to the Query before we filter
      databases with anything else. This way you can show/hide databases using
      Feature Flags for example in conjuction with the regular role filtering.
      If not, if an user has access to all Databases it would skip this dynamic
      filtering.
      """
  
      if dynamic_filters := current_app.config[
          "EXTRA_DYNAMIC_QUERY_FILTERS"
      ]:
          if dynamic_databases_filter := dynamic_filters.get(
              "databases"
          ):
              query = dynamic_databases_filter(query)
  
      # We can proceed with default filtering now
      if security_manager.can_access_all_databases():
          return query
      database_perms = security_manager.user_view_menu_names(
          "database_access"
      )
      schema_access_databases = can_access_databases("schema_access")
  
      datasource_access_databases = can_access_databases(
          "datasource_access"
      )
  
      return query.filter(
          or_(
              self.model.perm.in_(database_perms),
              self.model.database_name.in_(
                  [
                      *schema_access_databases,
                      *datasource_access_databases,
                  ]
              ),
          )
      )
  
file_path: superset/superset/databases/filters.py
imports: from typing import Any
  from flask import current_app, g
  from flask_babel import lazy_gettext
  from sqlalchemy import or_
  from sqlalchemy.orm import Query
  from sqlalchemy.sql.expression import cast
  from sqlalchemy.sql.sqltypes import JSON
  from superset import app, security_manager
  from superset.models.core import Database
  from superset.views.base import BaseFilter
label_desc: Use image node_id 1 for calling the DatabaseFilter obj's underlying member method code with example usage: obj.apply(query, value) and returns: query, query