potiuk commented on code in PR #34317:
URL: https://github.com/apache/airflow/pull/34317#discussion_r1355941755
##########
airflow/www/extensions/init_jinja_globals.py:
##########
@@ -69,10 +70,13 @@ def prepare_jinja_globals():
"git_version": git_version,
"k8s_or_k8scelery_executor": IS_K8S_OR_K8SCELERY_EXECUTOR,
"rest_api_enabled": False,
- "auth_manager": get_auth_manager(),
"config_test_connection": conf.get("core", "test_connection",
fallback="Disabled"),
}
+ # Extra global specific to auth manager
+ extra_globals["auth_manager"] = get_auth_manager()
+ extra_globals["DagDetails"] = DagDetails
Review Comment:
It indeed sounds strange to pass authmanager as JINJA global context
(especially that it is only used for checking "can_edit".
I think it could be easily fixed for all those multiple views by injecting
"can_edit" in `baseviews.py` based on whether `dag` is already present in the
arguments (all the views that extend dag_html must have `dag` present).
Smth like:
````python
def render_template(self, template, **kwargs):
"""
Use this method on your own endpoints, will pass the extra_args
to the templates.
:param template: The template relative path
:param kwargs: arguments to be passed to the template
"""
kwargs["base_template"] = self.appbuilder.base_template
kwargs["appbuilder"] = self.appbuilder
# THIS
if "dag" in kwargs:
kwargs["can_edit"] =
get_auth_manager().is_authorized_dag(method="PUT",
details=DagDetails(id=kwargs["dag"].dag_id))
return render_template(
template, **dict(list(kwargs.items()) +
list(self.extra_args.items()))
)
```
Or it could be added in all the views individualy in extra_args
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]