Skip to content

Commit

Permalink
New dashboard: notification to point users there (#11161)
Browse files Browse the repository at this point in the history
* New dashboard: notification to point users there

We can add the notifications to all the users by running the following code:

```python
from readthedocs.core.notifications import MESSAGE_BETA_DASHBOARD_AVAILABLE

for user in User.objects.all():
    Notification.objects.add(
      message_id=MESSAGE_BETA_DASHBOARD_AVAILABLE,
      attached_to=user,
      dismissable=True,
    )
```

This will show a one-time dismissable notification to these users.
In the future (weeks, months) if we can show them another notification like this
one as a reminder, we can run the same code again.

Related readthedocs/ext-theme#183

* Update readthedocs/core/notifications.py

Co-authored-by: Anthony <[email protected]>

* Change the content of the notification based on old/new dashboard

* Test fixed

* Update readthedocs/core/notifications.py

Co-authored-by: Anthony <[email protected]>

---------

Co-authored-by: Anthony <[email protected]>
  • Loading branch information
humitos and agjohnson authored Feb 29, 2024
1 parent 03c03fa commit 695667e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions readthedocs/core/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def readthedocs_processor(request):
"USE_ORGANIZATIONS": settings.RTD_ALLOW_ORGANIZATIONS,
"SUPPORT_EMAIL": settings.SUPPORT_EMAIL,
"PUBLIC_API_URL": settings.PUBLIC_API_URL,
"RTD_EXT_THEME_ENABLED": settings.RTD_EXT_THEME_ENABLED,
}
return exports

Expand Down
22 changes: 21 additions & 1 deletion readthedocs/core/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

from django.utils.translation import gettext_lazy as _

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

MESSAGE_EMAIL_VALIDATION_PENDING = "core:email:validation-pending"
MESSAGE_BETA_DASHBOARD_AVAILABLE = "core:dashboard:beta-available"
messages = [
Message(
id=MESSAGE_EMAIL_VALIDATION_PENDING,
Expand All @@ -22,6 +23,25 @@
),
type=WARNING,
),
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://beta.{{ PRODUCTION_DOMAIN }}/">Give it a try</a> and send us feedback.
{% endif %}
"""
).strip(),
),
type=INFO,
),
]


Expand Down
2 changes: 1 addition & 1 deletion readthedocs/core/static-src/core/js/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Dismiss a notification
module.exports.handle_notification_dismiss = function () {
$(document).ready(function () {
$('ul.notifications li.notification > a').click(function (ev) {
$('ul.notifications li.notification > a.notification-action').click(function (ev) {
var url = $(this).attr('href');
var dismiss_url = $(this).parent().attr('data-dismiss-url');
var csrf_token = $(this).parent().attr('data-csrf-token');
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/core/static/core/js/site.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 @@ -55,6 +55,7 @@ class TestNotification(EmailNotification):
"PRODUCTION_DOMAIN": "readthedocs.org",
"PUBLIC_DOMAIN": mock.ANY,
"PUBLIC_API_URL": mock.ANY,
"RTD_EXT_THEME_ENABLED": mock.ANY,
"SITE_ROOT": mock.ANY,
"SUPPORT_EMAIL": "[email protected]",
"TEMPLATE_ROOT": mock.ANY,
Expand Down

0 comments on commit 695667e

Please sign in to comment.