uranusjr commented on code in PR #28781: URL: https://github.com/apache/airflow/pull/28781#discussion_r1064255602
########## airflow/www/utils.py: ########## @@ -820,10 +822,24 @@ def __init__( self.html = html self.message = Markup(message) if html else message - def should_show(self, securitymanager) -> bool: - """Determine if the user should see the message based on their role membership""" + def should_show(self, securitymanager: SecurityManager) -> bool: + """Determine if the user should see the message. + + The decision is based on the user's role. If ``AUTH_ROLE_PUBLIC`` is + set in ``webserver_config.py``, An anonymous user would have the + ``AUTH_ROLE_PUBLIC`` role. + """ if self.roles: - user_roles = {r.name for r in securitymanager.current_user.roles} + current_user = securitymanager.current_user + if current_user: + user_roles = {r.name for r in securitymanager.current_user.roles} + elif current_user is None and "AUTH_ROLE_PUBLIC" in securitymanager.appbuilder.get_app.config: + # If the current_user is anonymous, assign AUTH_ROLE_PUBLIC role (if it exists) to them + user_roles = {securitymanager.appbuilder.get_app.config["AUTH_ROLE_PUBLIC"]} + else: + # Unable to obtain user role - default to not showing + return False Review Comment: ```suggestion if current_user is not None: user_roles = {r.name for r in securitymanager.current_user.roles} elif "AUTH_ROLE_PUBLIC" in securitymanager.appbuilder.get_app.config: # If the current_user is anonymous, assign AUTH_ROLE_PUBLIC role (if it exists) to them user_roles = {securitymanager.appbuilder.get_app.config["AUTH_ROLE_PUBLIC"]} else: # Unable to obtain user role - default to not showing return False ``` -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org