Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI page title to allow for Markup #20888

Merged
merged 5 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions airflow/config_templates/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,13 @@
type: string
example: ~
default:
- name: instance_name_has_markup
description: |
Whether the custom page title for the DAGs overview page contains any Markup language
version_added: 2.3.0
type: boolean
example: ~
default: "False"
- name: auto_refresh_interval
description: |
How frequently, in seconds, the DAG data will auto-refresh in graph or tree view
Expand Down
3 changes: 3 additions & 0 deletions airflow/config_templates/default_airflow.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,9 @@ session_lifetime_minutes = 43200
# Sets a custom page title for the DAGs overview page and site title for all pages
# instance_name =

# Whether the custom page title for the DAGs overview page contains any Markup language
instance_name_has_markup = False

# How frequently, in seconds, the DAG data will auto-refresh in graph or tree view
# when auto-refresh is turned on
auto_refresh_interval = 3
Expand Down
5 changes: 4 additions & 1 deletion airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,9 @@ def index(self):
state_color_mapping["null"] = state_color_mapping.pop(None)

page_title = conf.get(section="webserver", key="instance_name", fallback="DAGs")
page_title_has_markup = conf.getboolean(
section="webserver", key="instance_name_has_markup", fallback=False
)

dashboard_alerts = [
fm for fm in settings.DASHBOARD_UIALERTS if fm.should_show(current_app.appbuilder.sm)
Expand Down Expand Up @@ -815,7 +818,7 @@ def _iter_parsed_moved_data_table_names():
migration_moved_data_alerts=sorted(set(_iter_parsed_moved_data_table_names())),
current_page=current_page,
search_query=arg_search_query if arg_search_query else '',
page_title=page_title,
page_title=Markup(page_title) if page_title_has_markup else page_title,
page_size=dags_per_page,
num_of_pages=num_of_pages,
num_dag_from=min(start + 1, num_of_all_dags),
Expand Down
8 changes: 7 additions & 1 deletion docs/apache-airflow/howto/customize-ui.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ Customizing DAG UI Header and Airflow Page Titles
Airflow now allows you to customize the DAG home page header and page title. This will help
distinguish between various installations of Airflow or simply amend the page text.

Note: the custom title will be applied to both the page header and the page title.
.. note::

The custom title will be applied to both the page header and the page title.

To make this change, simply:

Expand Down Expand Up @@ -117,6 +119,10 @@ After

.. image:: ../img/change-site-title/example_instance_name_configuration.png

.. note::

From version 2.3.0 you can include markup in ``instance_name`` variable for further customization. To enable, set ``instance_name_has_markup`` under the ``[webserver]`` section inside ``airflow.cfg`` to ``True``.


Add custom alert messages on the dashboard
------------------------------------------
Expand Down
11 changes: 11 additions & 0 deletions tests/www/views/test_views_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,14 @@ def test_page_instance_name_xss_prevention(admin_client):
escaped_xss_string = "<script>alert('Give me your credit card number')</script>"
check_content_in_response(escaped_xss_string, resp)
check_content_not_in_response(xss_string, resp)


@conf_vars(
{
("webserver", "instance_name"): "<b>Bold Site Title Test</b>",
("webserver", "instance_name_has_markup"): "True",
}
)
def test_page_instance_name_with_markup(admin_client):
resp = admin_client.get('home', follow_redirects=True)
check_content_in_response('<b>Bold Site Title Test</b>', resp)