From 33c602fcddd7aba9cff08f57222c3ffb572edbc2 Mon Sep 17 00:00:00 2001 From: Tatiana Al-Chueyr Date: Wed, 23 Oct 2024 18:54:46 +0100 Subject: [PATCH] Fix displaying dbt docs as menu item in Astro for Organization Member and Workspace Operator --- CHANGELOG.rst | 4 +++- cosmos/plugin/__init__.py | 37 ++++++++++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 360859776..ae7656420 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,12 +4,14 @@ Changelog 1.7.1a1 (2024-10-24) -------------------- +Bug fixes +* Fix displaying dbt docs as menu item in Astro + Others * Fix release to PyPI after rst directive disabled by @tatiana in #1281 - 1.7.0 (2024-10-04) ------------------ diff --git a/cosmos/plugin/__init__.py b/cosmos/plugin/__init__.py index ff4d8e817..ede0e6f75 100644 --- a/cosmos/plugin/__init__.py +++ b/cosmos/plugin/__init__.py @@ -2,6 +2,7 @@ from typing import Any, Dict, Optional, Tuple from urllib.parse import urlsplit +from airflow.configuration import conf from airflow.plugins_manager import AirflowPlugin from airflow.security import permissions from airflow.www.auth import has_access @@ -200,14 +201,24 @@ def create_blueprint( return super().create_blueprint(appbuilder, endpoint=endpoint, static_folder=self.static_folder) # type: ignore[no-any-return] @expose("/dbt_docs") # type: ignore[misc] - @has_access([(permissions.ACTION_CAN_READ, permissions.RESOURCE_WEBSITE)]) + @has_access( + [ + (permissions.ACTION_CAN_ACCESS_MENU, "Custom Menu"), + (permissions.ACTION_CAN_READ, permissions.RESOURCE_WEBSITE), + ] + ) def dbt_docs(self) -> str: if dbt_docs_dir is None: return self.render_template("dbt_docs_not_set_up.html") # type: ignore[no-any-return,no-untyped-call] return self.render_template("dbt_docs.html") # type: ignore[no-any-return,no-untyped-call] @expose("/dbt_docs_index.html") # type: ignore[misc] - @has_access([(permissions.ACTION_CAN_READ, permissions.RESOURCE_WEBSITE)]) + @has_access( + [ + (permissions.ACTION_CAN_ACCESS_MENU, "Custom Menu"), + (permissions.ACTION_CAN_READ, permissions.RESOURCE_WEBSITE), + ] + ) def dbt_docs_index(self) -> Tuple[str, int, Dict[str, Any]]: if dbt_docs_dir is None: abort(404) @@ -222,7 +233,12 @@ def dbt_docs_index(self) -> Tuple[str, int, Dict[str, Any]]: return html, 200, {"Content-Security-Policy": "frame-ancestors 'self'"} @expose("/catalog.json") # type: ignore[misc] - @has_access([(permissions.ACTION_CAN_READ, permissions.RESOURCE_WEBSITE)]) + @has_access( + [ + (permissions.ACTION_CAN_ACCESS_MENU, "Custom Menu"), + (permissions.ACTION_CAN_READ, permissions.RESOURCE_WEBSITE), + ] + ) def catalog(self) -> Tuple[str, int, Dict[str, Any]]: if dbt_docs_dir is None: abort(404) @@ -234,7 +250,12 @@ def catalog(self) -> Tuple[str, int, Dict[str, Any]]: return data, 200, {"Content-Type": "application/json"} @expose("/manifest.json") # type: ignore[misc] - @has_access([(permissions.ACTION_CAN_READ, permissions.RESOURCE_WEBSITE)]) + @has_access( + [ + (permissions.ACTION_CAN_ACCESS_MENU, "Custom Menu"), + (permissions.ACTION_CAN_READ, permissions.RESOURCE_WEBSITE), + ] + ) def manifest(self) -> Tuple[str, int, Dict[str, Any]]: if dbt_docs_dir is None: abort(404) @@ -251,4 +272,10 @@ def manifest(self) -> Tuple[str, int, Dict[str, Any]]: class CosmosPlugin(AirflowPlugin): name = "cosmos" - appbuilder_views = [{"name": "dbt Docs", "category": "Browse", "view": dbt_docs_view}] + item = { + "name": "dbt Docs", + "category": "Browse", + "view": dbt_docs_view, + "href": conf.get("webserver", "base_url") + "/dbt_docs", + } + appbuilder_views = [item]