From 6ef61c02593f8beb0211329630df148e46197991 Mon Sep 17 00:00:00 2001 From: PApostol Date: Fri, 14 Jan 2022 15:55:41 +0200 Subject: [PATCH 1/5] Allow for Markup in UI title page --- airflow/config_templates/config.yml | 7 +++++++ airflow/config_templates/default_airflow.cfg | 3 +++ airflow/www/views.py | 3 ++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/airflow/config_templates/config.yml b/airflow/config_templates/config.yml index 1b52af6690735..87230b88aadb0 100644 --- a/airflow/config_templates/config.yml +++ b/airflow/config_templates/config.yml @@ -1303,6 +1303,13 @@ type: string example: ~ default: + - name: instance_name_markup + description: | + Whether the custom page title for the DAGs overview page contains any Markup language + version_added: 2.3.1 + 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 diff --git a/airflow/config_templates/default_airflow.cfg b/airflow/config_templates/default_airflow.cfg index c09532aa600a1..3a73d6f025d7b 100644 --- a/airflow/config_templates/default_airflow.cfg +++ b/airflow/config_templates/default_airflow.cfg @@ -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_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 diff --git a/airflow/www/views.py b/airflow/www/views.py index 5d8dbebe5c3f3..ca1b4b9b5a442 100644 --- a/airflow/www/views.py +++ b/airflow/www/views.py @@ -770,6 +770,7 @@ 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_markup = conf.getboolean(section="webserver", key="instance_name_markup", fallback=False) dashboard_alerts = [ fm for fm in settings.DASHBOARD_UIALERTS if fm.should_show(current_app.appbuilder.sm) @@ -815,7 +816,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_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), From d11d44bc9b99b93794a3c4cced69034007d8ed61 Mon Sep 17 00:00:00 2001 From: PApostol Date: Sat, 15 Jan 2022 16:02:44 +0200 Subject: [PATCH 2/5] Add a test --- tests/www/views/test_views_base.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/www/views/test_views_base.py b/tests/www/views/test_views_base.py index f3664b4f09f54..388fd6754e554 100644 --- a/tests/www/views/test_views_base.py +++ b/tests/www/views/test_views_base.py @@ -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"): "Bold Site Title Test", + ("webserver", "instance_name_markup"): "True", + } +) +def test_page_instance_name_with_markup(admin_client): + resp = admin_client.get('home', follow_redirects=True) + check_content_in_response('Bold Site Title Test', resp) From 4bb85113bf7cce9a6768ec5bc8259bc7c67daf77 Mon Sep 17 00:00:00 2001 From: PApostol Date: Sat, 15 Jan 2022 16:05:01 +0200 Subject: [PATCH 3/5] Update docs and version --- airflow/config_templates/config.yml | 2 +- docs/apache-airflow/howto/customize-ui.rst | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/airflow/config_templates/config.yml b/airflow/config_templates/config.yml index 87230b88aadb0..fd8a20f7fcb4b 100644 --- a/airflow/config_templates/config.yml +++ b/airflow/config_templates/config.yml @@ -1306,7 +1306,7 @@ - name: instance_name_markup description: | Whether the custom page title for the DAGs overview page contains any Markup language - version_added: 2.3.1 + version_added: 2.3.0 type: boolean example: ~ default: "False" diff --git a/docs/apache-airflow/howto/customize-ui.rst b/docs/apache-airflow/howto/customize-ui.rst index 179c223417119..b5347f5f3ea4c 100644 --- a/docs/apache-airflow/howto/customize-ui.rst +++ b/docs/apache-airflow/howto/customize-ui.rst @@ -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: @@ -117,6 +119,10 @@ After .. image:: ../img/change-site-title/example_instance_name_configuration.png +.. note:: + + From version 2.2.4 you can include markup in ``instance_name`` variable for further customization. To enable, set ``instance_name_markup`` under the ``[webserver]`` section inside ``airflow.cfg`` to ``True``. + Add custom alert messages on the dashboard ------------------------------------------ From 58e12ec6e4a19f4f4612d46cc7c0d006b6c9fd11 Mon Sep 17 00:00:00 2001 From: PApostol Date: Sat, 15 Jan 2022 16:13:10 +0200 Subject: [PATCH 4/5] Update version in docs --- docs/apache-airflow/howto/customize-ui.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/apache-airflow/howto/customize-ui.rst b/docs/apache-airflow/howto/customize-ui.rst index b5347f5f3ea4c..49235beabbaa8 100644 --- a/docs/apache-airflow/howto/customize-ui.rst +++ b/docs/apache-airflow/howto/customize-ui.rst @@ -121,7 +121,7 @@ After .. note:: - From version 2.2.4 you can include markup in ``instance_name`` variable for further customization. To enable, set ``instance_name_markup`` under the ``[webserver]`` section inside ``airflow.cfg`` to ``True``. + From version 2.3.0 you can include markup in ``instance_name`` variable for further customization. To enable, set ``instance_name_markup`` under the ``[webserver]`` section inside ``airflow.cfg`` to ``True``. Add custom alert messages on the dashboard From 98bd321fc3fb60851541cd538649eb6f75ab8827 Mon Sep 17 00:00:00 2001 From: PApostol Date: Tue, 18 Jan 2022 22:18:04 +0200 Subject: [PATCH 5/5] More descriptive variable names --- airflow/config_templates/config.yml | 2 +- airflow/config_templates/default_airflow.cfg | 2 +- airflow/www/views.py | 6 ++++-- docs/apache-airflow/howto/customize-ui.rst | 2 +- tests/www/views/test_views_base.py | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/airflow/config_templates/config.yml b/airflow/config_templates/config.yml index fd8a20f7fcb4b..00a69eb67bf75 100644 --- a/airflow/config_templates/config.yml +++ b/airflow/config_templates/config.yml @@ -1303,7 +1303,7 @@ type: string example: ~ default: - - name: instance_name_markup + - 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 diff --git a/airflow/config_templates/default_airflow.cfg b/airflow/config_templates/default_airflow.cfg index 3a73d6f025d7b..031ff60b16548 100644 --- a/airflow/config_templates/default_airflow.cfg +++ b/airflow/config_templates/default_airflow.cfg @@ -656,7 +656,7 @@ session_lifetime_minutes = 43200 # instance_name = # Whether the custom page title for the DAGs overview page contains any Markup language -instance_name_markup = False +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 diff --git a/airflow/www/views.py b/airflow/www/views.py index ca1b4b9b5a442..fa7f676c4a692 100644 --- a/airflow/www/views.py +++ b/airflow/www/views.py @@ -770,7 +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_markup = conf.getboolean(section="webserver", key="instance_name_markup", fallback=False) + 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) @@ -816,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=Markup(page_title) if page_title_markup else 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), diff --git a/docs/apache-airflow/howto/customize-ui.rst b/docs/apache-airflow/howto/customize-ui.rst index 49235beabbaa8..f11a874146cfe 100644 --- a/docs/apache-airflow/howto/customize-ui.rst +++ b/docs/apache-airflow/howto/customize-ui.rst @@ -121,7 +121,7 @@ After .. note:: - From version 2.3.0 you can include markup in ``instance_name`` variable for further customization. To enable, set ``instance_name_markup`` under the ``[webserver]`` section inside ``airflow.cfg`` to ``True``. + 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 diff --git a/tests/www/views/test_views_base.py b/tests/www/views/test_views_base.py index 388fd6754e554..00eb7d3f93426 100644 --- a/tests/www/views/test_views_base.py +++ b/tests/www/views/test_views_base.py @@ -395,7 +395,7 @@ def test_page_instance_name_xss_prevention(admin_client): @conf_vars( { ("webserver", "instance_name"): "Bold Site Title Test", - ("webserver", "instance_name_markup"): "True", + ("webserver", "instance_name_has_markup"): "True", } ) def test_page_instance_name_with_markup(admin_client):