vincbeck commented on code in PR #77673:
URL: https://github.com/apache/airflow/pull/77673#discussion_r4720798708
##########
providers/fab/src/airflow/providers/fab/auth_manager/security_manager/override.py:
##########
@@ -1067,10 +1067,27 @@ def sync_perm_for_dag(
is a set() of action names (e.g., `{'DAG Runs': {'can_create'},
'DAGs': {'can_read'}}`)
:return:
"""
- for resource_name, resource_values in
self.RESOURCE_DETAILS_MAP.items():
- dag_resource_name = permissions.resource_name(dag_id,
resource_name)
- for dag_action_name in resource_values["actions"]:
- self.create_permission(dag_action_name, dag_resource_name)
+ expected = {
+ (action_name, permissions.resource_name(dag_id, resource_type))
+ for resource_type, resource_values in
self.RESOURCE_DETAILS_MAP.items()
+ for action_name in resource_values["actions"]
+ }
+ existing = set(
+ self.session.execute(
Review Comment:
nit: this is very close to `get_all_permissions`, any chance to factorize?
For example by giving `get_all_permissions` optional action and resource name
filters.
##########
providers/fab/tests/unit/fab/auth_manager/test_security.py:
##########
@@ -697,6 +697,29 @@ def
test_sync_perm_for_dag_creates_permissions_on_resources(security_manager):
assert security_manager.get_permission(permissions.ACTION_CAN_EDIT,
prefixed_test_dag_id) is not None
[email protected](
+ ("missing_permissions", "expected_query_count"),
+ [
+ pytest.param(set(), 1, id="all-exist"),
+ pytest.param({(permissions.ACTION_CAN_EDIT, "DAG:TEST_DAG_RESYNC")},
7, id="one-missing"),
Review Comment:
nit: 7 depends on how many queries `create_permission` runs internally, so
any change there will break this test. For `one-missing`, checking that the
permission exists afterwards (which you already do) is enough I think.
--
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]