amoghrajesh commented on code in PR #68833: URL: https://github.com/apache/airflow/pull/68833#discussion_r3635490259
########## airflow-core/src/airflow/api_fastapi/core_api/services/public/event_logs.py: ########## @@ -0,0 +1,52 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +from sqlalchemy import inspect +from sqlalchemy.orm.attributes import set_committed_value + +from airflow.api_fastapi.auth.managers.models.base_user import BaseUser +from airflow.api_fastapi.core_api.datamodels.event_logs import EventLogResponse +from airflow.models import Log + + +def _resolve_owner_display_name(event_log: Log, user: BaseUser | None) -> str | None: + if event_log.owner_display_name: + return event_log.owner_display_name + if not event_log.owner: + return None + if user is not None and event_log.owner == user.get_name(): + return user.get_name() Review Comment: Isn't this dead code? When the condition is true, `user.get_name()` and `event_log.owner`are the same string, so this branch returns exactly what the final return `event_log.owner` would return anyway. ########## airflow-core/src/airflow/ui/src/pages/Events/Events.tsx: ########## @@ -72,6 +72,15 @@ const eventsColumn = ( skeletonWidth: 10, }, }, + { + accessorKey: "owner_display_name", + cell: ({ row: { original } }) => original.owner_display_name?.replace(/ -$/u, ""), Review Comment: This strips a trailing `-` from the display value, but nothing in the resolved value (stored owner_display_name, or the raw owner fallback) can ever produce that suffix. ########## airflow-core/src/airflow/api_fastapi/logging/decorators.py: ########## @@ -98,7 +98,7 @@ async def log_action( user_display = "" else: user_name = user.get_name() - user_display = user.get_name() + user_display = user_name Review Comment: Is this related? Seems like a no-op actually. ########## airflow-core/src/airflow/api_fastapi/core_api/services/public/event_logs.py: ########## @@ -0,0 +1,52 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +from sqlalchemy import inspect +from sqlalchemy.orm.attributes import set_committed_value + +from airflow.api_fastapi.auth.managers.models.base_user import BaseUser +from airflow.api_fastapi.core_api.datamodels.event_logs import EventLogResponse +from airflow.models import Log + + +def _resolve_owner_display_name(event_log: Log, user: BaseUser | None) -> str | None: Review Comment: This function runs when someone views the audit log, not when the _action_ happened. Right now that is fine because it does not try to resolve first or last name or email like the PR description promises. But if that logic gets added here later, the name shown for an old log entry could change depending on who is looking at it today which defeats the purpose of an audit log. That kind of resolution should happen once, when the action is logged, and be stored permanently not recomputed each time someone views it. Check how `owner_display_name` is handled today -- 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]
