Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove get_readable_dag, get_editable_dag, and get_accessible_dags. #19961

Merged
merged 1 commit into from
Dec 6, 2021
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
33 changes: 10 additions & 23 deletions airflow/www/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,32 +281,20 @@ def current_user_has_permissions(self) -> bool:
return True
return False

def get_readable_dags(self, user):
"""Gets the DAGs readable by authenticated user."""
return self.get_accessible_dags([permissions.ACTION_CAN_READ], user)

def get_editable_dags(self, user):
"""Gets the DAGs editable by authenticated user."""
return self.get_accessible_dags([permissions.ACTION_CAN_EDIT], user)

def get_readable_dag_ids(self, user) -> Set[str]:
"""Gets the DAG IDs readable by authenticated user."""
return {dag.dag_id for dag in self.get_readable_dags(user)}
return self.get_accessible_dag_ids(user, [permissions.ACTION_CAN_READ])

def get_editable_dag_ids(self, user) -> Set[str]:
"""Gets the DAG IDs editable by authenticated user."""
return {dag.dag_id for dag in self.get_editable_dags(user)}

def get_accessible_dag_ids(self, user) -> Set[str]:
"""Gets the DAG IDs editable or readable by authenticated user."""
accessible_dags = self.get_accessible_dags(
[permissions.ACTION_CAN_EDIT, permissions.ACTION_CAN_READ], user
)
return {dag.dag_id for dag in accessible_dags}
return self.get_accessible_dag_ids(user, [permissions.ACTION_CAN_EDIT])

@provide_session
def get_accessible_dags(self, user_actions, user, session=None):
def get_accessible_dag_ids(self, user, user_actions=None, session=None) -> Set[str]:
"""Generic function to get readable or writable DAGs for user."""
if not user_actions:
user_actions = [permissions.ACTION_CAN_EDIT, permissions.ACTION_CAN_READ]

if user.is_anonymous:
roles = self.get_user_roles(user)
else:
Expand All @@ -331,14 +319,13 @@ def get_accessible_dags(self, user_actions, user, session=None):

resource = permission.resource.name
if resource == permissions.RESOURCE_DAG:
return session.query(DagModel)
return {dag.dag_id for dag in session.query(DagModel.dag_id)}

if resource.startswith(permissions.RESOURCE_DAG_PREFIX):
resources.add(resource[len(permissions.RESOURCE_DAG_PREFIX) :])
else:
resources.add(resource)

return session.query(DagModel).filter(DagModel.dag_id.in_(resources))
return {dag.dag_id for dag in session.query(DagModel.dag_id).filter(DagModel.dag_id.in_(resources))}

def can_access_some_dags(self, action: str, dag_id: Optional[str] = None) -> bool:
"""Checks if user has read or write access to some dags."""
Expand All @@ -347,8 +334,8 @@ def can_access_some_dags(self, action: str, dag_id: Optional[str] = None) -> boo

user = g.user
if action == permissions.ACTION_CAN_READ:
return any(self.get_readable_dags(user))
return any(self.get_editable_dags(user))
return any(self.get_readable_dag_ids(user))
return any(self.get_editable_dag_ids(user))

def can_read_dag(self, dag_id, user=None) -> bool:
"""Determines whether a user has DAG read access."""
Expand Down