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 24, 2024
1 parent fcf5c05 commit 33c602f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
------------------

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 33c602f

Please sign in to comment.