uranusjr commented on code in PR #24079:
URL: https://github.com/apache/airflow/pull/24079#discussion_r903456214
##########
airflow/api_connexion/endpoints/connection_endpoint.py:
##########
@@ -39,10 +39,12 @@
from airflow.security import permissions
from airflow.utils.session import NEW_SESSION, provide_session
from airflow.utils.strings import get_random_string
+from airflow.www.decorators import action_logging
@security.requires_access([(permissions.ACTION_CAN_DELETE,
permissions.RESOURCE_CONNECTION)])
@provide_session
+@action_logging(event=f"connection.{permissions.ACTION_CAN_DELETE.replace('can_','')}")
Review Comment:
Instead of doing this all over the place, we could change `action_logging`
to something like this:
```python
def action_logging(*, event: str = "", permission: str = "") ->
Callable[[T], T]:
if permission.startswith("can_"):
permission = permission[4:]
if permission:
event = f"{event}.{permission}"
...
```
And use it like this
```python
@action_logging(event="connection", permission=permissions.ACTION_CAN_EDIT)
```
Does this sound like a good idea?
----
An alternative approach would be to introduce a helper for this:
```python
def action_event_from_permission(prefix: str, permission: str) -> str:
if permission.startswith("can_"):
permission = permission[4:]
if prefix:
return f"{prefix}.{permission}"
return permission
```
and do
```python
@action_logging(
event=action_event_from_permission(
prefix="connection",
permission=permissions.ACTION_CAN_DELETE,
),
)
```
--
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]