Skip to content

Commit

Permalink
Fix site-wide new dashboard notification (#11543)
Browse files Browse the repository at this point in the history
  • Loading branch information
agjohnson authored Nov 12, 2024
1 parent 8f9e363 commit 7bceb65
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 40 deletions.
24 changes: 3 additions & 21 deletions readthedocs/builds/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,27 +192,9 @@ def get_context_data(self, **kwargs):

build = self.get_object()

# Temporary notification to point to the same page on the new dashboard
#
# To support readthedocs.com, we have to point to the login view. We
# can't point directly to the build view on the new dashboard as this
# will give the users a 404 because they aren't logged in.
#
# On community, we _don't want this_ as this requires the user to have
# a login to view the new dashboard.
url_domain = settings.PRODUCTION_DOMAIN
if url_domain.startswith("app."):
url_domain = url_domain[4:]
else:
url_domain = f"app.{url_domain}"
url_build = build.get_absolute_url()
# Point to the login view with the build as ?next. We are expecting
# users to have accounts to view this.
if settings.RTD_ALLOW_ORGANIZATIONS:
url_build = reverse("account_login") + f"?next={url_build}"
context["url_switch_dashboard"] = f"https://{url_domain}{url_build}"

context["notifications"] = build.notifications.all()
# We consume these notifications through the API in the new dashboard
if not settings.RTD_EXT_THEME_ENABLED:
context["notifications"] = build.notifications.all()
if not build.notifications.filter(
message_id=BuildAppError.GENERIC_WITH_BUILD_ID
).exists():
Expand Down
3 changes: 3 additions & 0 deletions readthedocs/core/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ def readthedocs_processor(request):
If you need to add something that depends on the request,
create a new context processor.
"""

exports = {
"PUBLIC_DOMAIN": settings.PUBLIC_DOMAIN,
"PRODUCTION_DOMAIN": settings.PRODUCTION_DOMAIN,
# TODO this can be removed with RTD_EXT_THEME_ENABLED
"SWITCH_PRODUCTION_DOMAIN": settings.SWITCH_PRODUCTION_DOMAIN,
"GLOBAL_ANALYTICS_CODE": settings.GLOBAL_ANALYTICS_CODE,
"DASHBOARD_ANALYTICS_CODE": settings.DASHBOARD_ANALYTICS_CODE,
"SITE_ROOT": settings.SITE_ROOT + "/",
Expand Down
50 changes: 32 additions & 18 deletions readthedocs/core/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

from django.utils.translation import gettext_lazy as _

from readthedocs.notifications.constants import INFO, WARNING
from readthedocs.notifications.constants import TIP, WARNING
from readthedocs.notifications.messages import Message, registry

MESSAGE_EMAIL_VALIDATION_PENDING = "core:email:validation-pending"
MESSAGE_BETA_DASHBOARD_AVAILABLE = "core:dashboard:beta-available"
MESSAGE_NEW_DASHBOARD = "core:dashboard:new"
messages = [
Message(
id=MESSAGE_EMAIL_VALIDATION_PENDING,
Expand All @@ -23,24 +23,38 @@
),
type=WARNING,
),
# This message looks quite odd because we need to show different content in
# the notification depending on which instance the user is on -- if the user
# is on our legacy dashboard, we don't want a notification "Welcome to our
# new dashboard!".
#
# Localization is avoided because the body has template logic inside and we
# don't want to push that to our translations sources.
Message(
id=MESSAGE_BETA_DASHBOARD_AVAILABLE,
header=_("New beta dashboard"),
body=_(
textwrap.dedent(
"""
{% if RTD_EXT_THEME_ENABLED %}
This dashboard is currently in beta,
you can <a href="https://{{ PRODUCTION_DOMAIN }}">return to the legacy dashboard</a> if you encounter any problems.
Feel free to <a href="https://{{ PRODUCTION_DOMAIN }}/support/">report any feedback</a> you may have.
{% else %}
Our new <strong>beta dashboard</strong> is now available for testing.
<a href="https://app.{{ PRODUCTION_DOMAIN }}/">Give it a try</a> and send us feedback.
{% endif %}
id=MESSAGE_NEW_DASHBOARD,
header=textwrap.dedent(
"""
).strip(),
),
type=INFO,
{% if RTD_EXT_THEME_ENABLED %}
Welcome to our new dashboard!
{% else %}
Our new dashboard is ready!
{% endif %}
"""
).strip(),
body=textwrap.dedent(
"""
{% if RTD_EXT_THEME_ENABLED %}
We are beginning to direct users to our new dashboard as we work to retire our legacy dashboard.
{% else %}
You are currently using our legacy dashboard, which will be retired on <time datetime="2025-03-11">March 11th, 2025</time>.
You should <a href="//{{ SWITCH_PRODUCTION_DOMAIN }}{% url "account_login" %}">switch to our new dashboard</a> before then.
{% endif %}
For more information on this change and what to expect,
<a href="https://about.readthedocs.com/blog/2024/11/rollout-of-our-new-dashboard/">read our blog post</a>.
"""
).strip(),
type=TIP,
icon_classes="fad fa-sparkles",
),
]

Expand Down
11 changes: 10 additions & 1 deletion readthedocs/projects/views/private.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,16 @@ def get_context_data(self, **kwargs):
template_name = None
projects = AdminPermission.projects(user=self.request.user, admin=True)
n_projects = projects.count()
if n_projects == 0 or (

# TODO remove this with RTD_EXT_THEME_ENABLED
# This is going to try hard to show the new dashboard announcement.
# We can't yet back down to another announcement as we don't have
# the ability to evaluate local storage. Until we add the ability to
# dynamically change the announcement, this is going to be the only
# announcement shown.
if True: # pylint: disable=using-constant-test
template_name = "new-dashboard.html"
elif n_projects == 0 or (
n_projects < 3 and (timezone.now() - projects.first().pub_date).days < 7
):
template_name = "example-projects.html"
Expand Down
1 change: 1 addition & 0 deletions readthedocs/rtd_tests/tests/test_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class TestNotification(EmailNotification):
"DO_NOT_TRACK_ENABLED": mock.ANY,
"GLOBAL_ANALYTICS_CODE": mock.ANY,
"PRODUCTION_DOMAIN": "readthedocs.org",
"SWITCH_PRODUCTION_DOMAIN": "app.readthedocs.org",
"PUBLIC_DOMAIN": mock.ANY,
"PUBLIC_API_URL": mock.ANY,
"RTD_EXT_THEME_ENABLED": mock.ANY,
Expand Down
6 changes: 6 additions & 0 deletions readthedocs/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ def SHOW_DEBUG_TOOLBAR(self):
RTD_INTERSPHINX_URL = "https://{}".format(PRODUCTION_DOMAIN)
RTD_EXTERNAL_VERSION_DOMAIN = "external-builds.readthedocs.io"

@property
def SWITCH_PRODUCTION_DOMAIN(self):
if self.RTD_EXT_THEME_ENABLED:
return self.PRODUCTION_DOMAIN.removeprefix("app.")
return f"app.{self.PRODUCTION_DOMAIN}"

# Doc Builder Backends
MKDOCS_BACKEND = "readthedocs.doc_builder.backends.mkdocs"
SPHINX_BACKEND = "readthedocs.doc_builder.backends.sphinx"
Expand Down

0 comments on commit 7bceb65

Please sign in to comment.