Skip to content

Commit

Permalink
Fix displaying dbt docs as menu item in Astro for Organization Member…
Browse files Browse the repository at this point in the history
… and Workspace Operator
  • Loading branch information
tatiana committed Oct 23, 2024
1 parent 772ab55 commit f2f4120
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

1.7.1a1 (2024-10-23)
--------------------

Bug fixes
* Fix displaying dbt docs as menu item in Astro


1.7.0 (2024-10-04)
------------------

Expand Down
2 changes: 1 addition & 1 deletion cosmos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Contains dags, task groups, and operators.
"""

__version__ = "1.7.0"
__version__ = "1.7.1a1"


from cosmos.airflow.dag import DbtDag
Expand Down
37 changes: 32 additions & 5 deletions cosmos/plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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]

0 comments on commit f2f4120

Please sign in to comment.