Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion airflow/security/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ class ResourceDetails(TypedDict):
# Keeping DAG_ACTIONS to keep the compatibility with outdated versions of FAB provider
DAG_ACTIONS = {ACTION_CAN_READ, ACTION_CAN_EDIT, ACTION_CAN_DELETE}


RESOURCE_DETAILS_MAP = {
RESOURCE_DAG: ResourceDetails(
actions={ACTION_CAN_READ, ACTION_CAN_EDIT, ACTION_CAN_DELETE}, prefix=RESOURCE_DAG_PREFIX
Expand All @@ -105,3 +104,20 @@ def resource_name(root_dag_id: str, resource: str) -> str:
if root_dag_id.startswith(tuple(PREFIX_RESOURCES_MAP.keys())):
return root_dag_id
return f"{RESOURCE_DETAILS_MAP[resource]['prefix']}{root_dag_id}"


def resource_name_for_dag(root_dag_id: str) -> str:
"""
Return the resource name for a DAG id.

Note that since a sub-DAG should follow the permission of its
parent DAG, you should pass ``DagModel.root_dag_id`` to this function,
for a subdag. A normal dag should pass the ``DagModel.dag_id``.

Note: This function is kept for backwards compatibility.
"""
if root_dag_id == RESOURCE_DAG:
return root_dag_id
if root_dag_id.startswith(RESOURCE_DAG_PREFIX):
return root_dag_id
return f"{RESOURCE_DAG_PREFIX}{root_dag_id}"