astahlman commented on a change in pull request #4642: [WIP] [AIRFLOW-2694] 
Declare permissions in DAG definition
URL: https://github.com/apache/airflow/pull/4642#discussion_r253678075
 
 

 ##########
 File path: airflow/models/__init__.py
 ##########
 @@ -4244,6 +4254,63 @@ def _test_cycle_helper(self, visit_map, task_id):
 
         visit_map[task_id] = DagBag.CYCLE_DONE
 
+    def _set_dag_permissions(self, access_control):
+        """Grant permissions on this DAG's ViewModel to the given role(s).
+
+        :param access_control: a dict where each key is a rolename and
+            each value is a set() of permission names (e.g.,
+            {'can_dag_read'}
+        :type access_control: dict
+
+        """
+        sm = cached_appbuilder().sm
 
 Review comment:
   @feng-tao Yeah, I had the same thought - I really don't like doing this in 
the `__init__` method.
   
   I see that we are already doing some permission handling in the `/refresh` 
endpoint - maybe this would be a natural place to invoke 
`dag.set_dag_permissions()`?
   
   
https://github.com/apache/airflow/blob/81f7c475a92b40320a683fc0bf81b62c47052238/airflow/www/views.py#L1682
   
   We could have similar logic in the `sync_perm` CLI command: for each DAG in 
the DagBag, call `dag.set_dag_permissions()`
   
   
https://github.com/apache/airflow/blob/81f7c475a92b40320a683fc0bf81b62c47052238/airflow/bin/cli.py#L1634

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to