Repository: zulip/zulip

Issue:
Wrong Organization Logo in Automatic color scheme
I have two separate Organization Logos configured for day mode and night mode. When I select in my settings color scheme "automatic", on page load always the organization logo for day mode is selected although the rest of the page is in night mode. When I go to settings and select day mode or night mode, the logo is changed to the correct one. When I change color scheme back to "automatic", also the correct logo is shown, until the page is reloaded with CMD+R (in browser or macOS app) or when restarting the macOS app.

This bug occurs in the macOS app, as well as all tested browsers: Safari, Brave (Chromium), Firefox, Google Chrome. All browsers are updated to their latest stable release version.


Discussion:
Hello @zulip/server-settings members, this issue was labeled with the "area: settings (admin/org)", "area: settings UI" labels, so you may want to check it out!

<!-- areaLabelAddition -->
@Lumrenion thanks for the report!

@sahil839 can you reproduce this?  It seems like a very plausible bug, and probably has an easy fix.
Yes I can reproduce. The bug here is that we pass the url directly from backend considering only day and night mode, and for we can check the browser's color scheme in the frontend only, so I think the correct fix is to decide the correct logo url in frontend. 
@zulipbot claim

Resolving patch:
diff --git a/zerver/views/home.py b/zerver/views/home.py
--- a/zerver/views/home.py
+++ b/zerver/views/home.py
@@ -1,6 +1,6 @@
 import logging
 import secrets
-from typing import Any, Dict, List, Optional, Tuple
+from typing import List, Optional, Tuple
 
 from django.conf import settings
 from django.http import HttpRequest, HttpResponse, HttpResponseRedirect
@@ -99,17 +99,6 @@ def update_last_reminder(user_profile: Optional[UserProfile]) -> None:
         user_profile.save(update_fields=["last_reminder"])
 
 
-def compute_navbar_logo_url(page_params: Dict[str, Any]) -> str:
-    if (
-        page_params["color_scheme"] == 2
-        and page_params["realm_night_logo_source"] != Realm.LOGO_DEFAULT
-    ):
-        navbar_logo_url = page_params["realm_night_logo_url"]
-    else:
-        navbar_logo_url = page_params["realm_logo_url"]
-    return navbar_logo_url
-
-
 def home(request: HttpRequest) -> HttpResponse:
     if not settings.ROOT_DOMAIN_LANDING_PAGE:
         return home_real(request)
@@ -209,8 +198,6 @@ def home_real(request: HttpRequest) -> HttpResponse:
 
     user_permission_info = get_user_permission_info(user_profile)
 
-    navbar_logo_url = compute_navbar_logo_url(page_params)
-
     response = render(
         request,
         "zerver/app/index.html",
@@ -225,7 +212,6 @@ def home_real(request: HttpRequest) -> HttpResponse:
             "is_admin": user_permission_info.is_realm_admin,
             "is_guest": user_permission_info.is_guest,
             "color_scheme": user_permission_info.color_scheme,
-            "navbar_logo_url": navbar_logo_url,
             "embedded": narrow_stream is not None,
             "max_file_upload_size_mib": settings.MAX_FILE_UPLOAD_SIZE,
         },


Test patch:
diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.py
--- a/zerver/tests/test_home.py
+++ b/zerver/tests/test_home.py
@@ -11,14 +11,8 @@
 from django.utils.timezone import now as timezone_now
 
 from corporate.models import Customer, CustomerPlan
-from zerver.lib.actions import (
-    change_user_is_active,
-    do_change_logo_source,
-    do_change_plan_type,
-    do_create_user,
-)
+from zerver.lib.actions import change_user_is_active, do_change_plan_type, do_create_user
 from zerver.lib.compatibility import LAST_SERVER_UPGRADE_TIME, is_outdated_server
-from zerver.lib.events import add_realm_logo_fields
 from zerver.lib.home import (
     get_billing_info,
     get_furthest_read_time,
@@ -39,7 +33,6 @@
     get_system_bot,
     get_user,
 )
-from zerver.views.home import compute_navbar_logo_url
 from zerver.worker.queue_processors import UserActivityWorker
 
 logger_string = "zulip.soft_deactivation"
@@ -860,73 +853,6 @@ def test_desktop_home(self) -> None:
         path = urllib.parse.urlparse(result["Location"]).path
         self.assertEqual(path, "/")
 
-    def test_compute_navbar_logo_url(self) -> None:
-        user_profile = self.example_user("hamlet")
-
-        page_params = {"color_scheme": user_profile.COLOR_SCHEME_NIGHT}
-        add_realm_logo_fields(page_params, user_profile.realm)
-        self.assertEqual(
-            compute_navbar_logo_url(page_params), "/static/images/logo/zulip-org-logo.svg?version=0"
-        )
-
-        page_params = {"color_scheme": user_profile.COLOR_SCHEME_LIGHT}
-        add_realm_logo_fields(page_params, user_profile.realm)
-        self.assertEqual(
-            compute_navbar_logo_url(page_params), "/static/images/logo/zulip-org-logo.svg?version=0"
-        )
-
-        do_change_logo_source(
-            user_profile.realm, Realm.LOGO_UPLOADED, night=False, acting_user=user_profile
-        )
-        page_params = {"color_scheme": user_profile.COLOR_SCHEME_NIGHT}
-        add_realm_logo_fields(page_params, user_profile.realm)
-        self.assertEqual(
-            compute_navbar_logo_url(page_params),
-            f"/user_avatars/{user_profile.realm_id}/realm/logo.png?version=2",
-        )
-
-        page_params = {"color_scheme": user_profile.COLOR_SCHEME_LIGHT}
-        add_realm_logo_fields(page_params, user_profile.realm)
-        self.assertEqual(
-            compute_navbar_logo_url(page_params),
-            f"/user_avatars/{user_profile.realm_id}/realm/logo.png?version=2",
-        )
-
-        do_change_logo_source(
-            user_profile.realm, Realm.LOGO_UPLOADED, night=True, acting_user=user_profile
-        )
-        page_params = {"color_scheme": user_profile.COLOR_SCHEME_NIGHT}
-        add_realm_logo_fields(page_params, user_profile.realm)
-        self.assertEqual(
-            compute_navbar_logo_url(page_params),
-            f"/user_avatars/{user_profile.realm_id}/realm/night_logo.png?version=2",
-        )
-
-        page_params = {"color_scheme": user_profile.COLOR_SCHEME_LIGHT}
-        add_realm_logo_fields(page_params, user_profile.realm)
-        self.assertEqual(
-            compute_navbar_logo_url(page_params),
-            f"/user_avatars/{user_profile.realm_id}/realm/logo.png?version=2",
-        )
-
-        # This configuration isn't super supported in the UI and is a
-        # weird choice, but we have a test for it anyway.
-        do_change_logo_source(
-            user_profile.realm, Realm.LOGO_DEFAULT, night=False, acting_user=user_profile
-        )
-        page_params = {"color_scheme": user_profile.COLOR_SCHEME_NIGHT}
-        add_realm_logo_fields(page_params, user_profile.realm)
-        self.assertEqual(
-            compute_navbar_logo_url(page_params),
-            f"/user_avatars/{user_profile.realm_id}/realm/night_logo.png?version=2",
-        )
-
-        page_params = {"color_scheme": user_profile.COLOR_SCHEME_LIGHT}
-        add_realm_logo_fields(page_params, user_profile.realm)
-        self.assertEqual(
-            compute_navbar_logo_url(page_params), "/static/images/logo/zulip-org-logo.svg?version=0"
-        )
-
     @override_settings(SERVER_UPGRADE_NAG_DEADLINE_DAYS=365)
     def test_is_outdated_server(self) -> None:
         # Check when server_upgrade_nag_deadline > last_server_upgrade_time