Skip to content

Commit

Permalink
Improve theme switching logging and notifications (#3042)
Browse files Browse the repository at this point in the history
* Do not show success notification on theme change (unify behaviour with translate view)
* If theme change fails, show human-friendly error message in the UI
* If theme change fails, log error message on the server
* Migrate old visibility_email values to the new ones
  • Loading branch information
mathjazz authored Dec 5, 2023
1 parent e4e3fce commit a2eb528
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
24 changes: 24 additions & 0 deletions pontoon/base/migrations/0052_rename_logged_in_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 3.2.15 on 2023-12-05 20:02

from django.db import migrations


def rename_logged_in_users(apps, schema_editor):
UserProfile = apps.get_model("base", "UserProfile")
UserProfile.objects.filter(visibility_email="Logged in users").update(
visibility_email="Logged-in users"
)


class Migration(migrations.Migration):

dependencies = [
("base", "0051_localecodehistory"),
]

operations = [
migrations.RunPython(
code=rename_logged_in_users,
reverse_code=migrations.RunPython.noop,
),
]
11 changes: 2 additions & 9 deletions pontoon/base/static/js/theme-switcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,9 @@ $(function () {

// Set the data-theme attribute after successfully changing the theme
$('body').data('theme', theme);

// Notify the user about the theme change after AJAX success
Pontoon.endLoader(`Theme changed to ${theme}.`);
},
error: function (request) {
if (request.responseText === 'error') {
Pontoon.endLoader('Oops, something went wrong.', 'error');
} else {
Pontoon.endLoader(request.responseText, 'error');
}
error: function () {
Pontoon.endLoader('Oops, something went wrong.', 'error');
},
});
});
Expand Down
9 changes: 7 additions & 2 deletions pontoon/contributors/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import logging

from dateutil.relativedelta import relativedelta
from django.contrib import messages
Expand Down Expand Up @@ -26,6 +27,9 @@
from pontoon.uxactionlog.utils import log_ux_action


log = logging.getLogger(__name__)


@login_required(redirect_field_name="", login_url="/403")
def profile(request):
"""Current user profile."""
Expand Down Expand Up @@ -210,9 +214,10 @@ def toggle_theme(request, username):
profile.theme = theme
profile.full_clean()
profile.save()
except ValidationError:
except ValidationError as e:
log.error(f"User profile validation error: {e}")
return JsonResponse(
{"status": False, "message": "Bad Request: Invalid theme"},
{"status": False, "message": "Bad Request: User profile validation failed"},
status=400,
)

Expand Down

0 comments on commit a2eb528

Please sign in to comment.