Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pontoon/base/models/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def serialize(self, project_contact):
"author": self.author.name_or_email,
"username": self.author.username,
"user_banner": self.author.banner(locale, project_contact),
"user_gravatar_url_small": self.author.gravatar_url(88),
"user_gravatar_url_small": self.author.avatar_url(88),
"created_at": self.timestamp.strftime("%b %d, %Y %H:%M"),
"date_iso": self.timestamp.isoformat(),
"content": self.content,
Expand Down
2 changes: 1 addition & 1 deletion pontoon/base/models/translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def authors(self):
"email": user.email,
"display_name": user.name_or_email,
"id": user.id,
"gravatar_url": user.gravatar_url(88),
"gravatar_url": user.avatar_url(88),
"translation_count": user.translations_count,
"role": user.user_role,
}
Expand Down
18 changes: 12 additions & 6 deletions pontoon/base/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ def user_profile_url(self):
)


def user_gravatar_url(self, size):
def user_avatar_url(self, size):
fxa_account = self.socialaccount_set.filter(provider="fxa").first()
if fxa_account:
fxa_avatar = fxa_account.extra_data.get("avatar")
if fxa_avatar:
return fxa_avatar

email = md5(self.email.lower().encode("utf-8")).hexdigest()
data = {
"s": str(size),
Expand All @@ -40,8 +46,8 @@ def user_gravatar_url(self, size):


@property
def user_gravatar_url_small(self):
return user_gravatar_url(self, 88)
def user_avatar_url_small(self):
return user_avatar_url(self, 88)


@property
Expand Down Expand Up @@ -512,7 +518,7 @@ def user_serialize(self):
"""Serialize Project contact"""

return {
"avatar": self.gravatar_url_small,
"avatar": self.avatar_url_small,
"name": self.name_or_email,
"url": self.profile_url,
}
Expand All @@ -533,8 +539,8 @@ def latest_action(self):


User.add_to_class("profile_url", user_profile_url)
User.add_to_class("gravatar_url", user_gravatar_url)
User.add_to_class("gravatar_url_small", user_gravatar_url_small)
User.add_to_class("avatar_url", user_avatar_url)
User.add_to_class("avatar_url_small", user_avatar_url_small)
User.add_to_class("name_or_email", user_name_or_email)
User.add_to_class("contact_email", user_contact_email)
User.add_to_class("display_name", user_display_name)
Expand Down
2 changes: 1 addition & 1 deletion pontoon/base/templates/allauth/layouts/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
{% if user.is_authenticated %}
<img
class="rounded"
src="{{ request.user.gravatar_url_small }}"
src="{{ request.user.avatar_url_small }}"
width="44"
height="44"
/>
Expand Down
2 changes: 1 addition & 1 deletion pontoon/base/templates/widgets/latest_activity.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% set action = latest_activity.type + ' by' %}
{% set user = latest_activity.user.name_or_email %}
{% set link = url('pontoon.contributors.contributor.username', latest_activity.user.username) %}
{% set avatar = latest_activity.user.gravatar_url(88) %}
{% set avatar = latest_activity.user.avatar_url(88) %}
{% else %}
{% set action = 'imported' %}
{% set user = '' %}
Expand Down
4 changes: 2 additions & 2 deletions pontoon/base/templates/widgets/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% if user.is_authenticated %}
<img
class="rounded"
src="{{ user.gravatar_url(88) }}"
src="{{ user.avatar_url(88) }}"
width="44"
height="44"
/>
Expand All @@ -21,7 +21,7 @@
>
<img
class="rounded"
src="{{ user.gravatar_url(176) }}"
src="{{ user.avatar_url(176) }}"
width="88"
height="88"
/>
Expand Down
4 changes: 2 additions & 2 deletions pontoon/base/tests/models/test_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_serialize_comments(comment_a, team_comment_a):
"user_banner": comment_a.author.banner(
comment_a.translation.locale, project.contact
),
"user_gravatar_url_small": comment_a.author.gravatar_url(88),
"user_gravatar_url_small": comment_a.author.avatar_url(88),
"created_at": comment_a.timestamp.strftime("%b %d, %Y %H:%M"),
"date_iso": comment_a.timestamp.isoformat(),
"content": comment_a.content,
Expand All @@ -27,7 +27,7 @@ def test_serialize_comments(comment_a, team_comment_a):
"user_banner": team_comment_a.author.banner(
team_comment_a.locale, project.contact
),
"user_gravatar_url_small": team_comment_a.author.gravatar_url(88),
"user_gravatar_url_small": team_comment_a.author.avatar_url(88),
"created_at": team_comment_a.timestamp.strftime("%b %d, %Y %H:%M"),
"date_iso": team_comment_a.timestamp.isoformat(),
"content": team_comment_a.content,
Expand Down
30 changes: 30 additions & 0 deletions pontoon/base/tests/models/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest

from allauth.socialaccount.models import SocialAccount
from notifications.models import Notification
from notifications.signals import notify

Expand Down Expand Up @@ -199,3 +200,32 @@ def test_serialized_notifications_new_string_without_created_time(user_a, projec
assert notification["actor"]["url"] == (
f"/projects/{project_a.slug}/all-resources/?status=missing,pretranslated"
)


@pytest.mark.django_db
def test_gravatar_url_returns_fxa_avatar_when_linked(user_a):
SocialAccount.objects.create(
user=user_a,
provider="fxa",
uid="1234",
extra_data={"avatar": "https://profile.accounts.firefox.com/v1/avatar/abc"},
)
assert user_a.avatar_url(88) == "https://profile.accounts.firefox.com/v1/avatar/abc"


@pytest.mark.django_db
def test_gravatar_url_falls_back_to_gravatar_when_no_fxa(user_a):
url = user_a.avatar_url(88)
assert "gravatar.com/avatar/" in url


@pytest.mark.django_db
def test_gravatar_url_falls_back_to_gravatar_when_fxa_has_no_avatar(user_a):
SocialAccount.objects.create(
user=user_a,
provider="fxa",
uid="1234",
extra_data={},
)
url = user_a.avatar_url(88)
assert "gravatar.com/avatar/" in url
8 changes: 4 additions & 4 deletions pontoon/base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ def get_translation_history(request):
"user": u.name_or_email,
"uid": u.id,
"username": u.username,
"user_gravatar_url_small": u.gravatar_url(88),
"user_gravatar_url_small": u.avatar_url(88),
"user_banner": u.banner(locale, project_contact),
"date": t.date,
"approved_user": User.display_name_or_blank(t.approved_user),
Expand Down Expand Up @@ -834,7 +834,7 @@ def get_users(request):
for u in users:
payload.append(
{
"gravatar": u.gravatar_url(44),
"gravatar": u.avatar_url(44),
"name": u.name_or_email,
"url": u.profile_url,
"username": u.profile.username,
Expand Down Expand Up @@ -1051,8 +1051,8 @@ def user_data(request):
"tour_status": user.profile.tour_status,
"has_dismissed_addon_promotion": user.profile.has_dismissed_addon_promotion,
"logout_url": logout_url,
"gravatar_url_small": user.gravatar_url(88),
"gravatar_url_big": user.gravatar_url(176),
"gravatar_url_small": user.avatar_url(88),
"gravatar_url_big": user.avatar_url(176),
"notifications": user.serialized_notifications,
"theme": user.profile.theme,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ <h1>
>
<img
class="rounded"
src="{{ top_contributor.gravatar_url(252) }}"
src="{{ top_contributor.avatar_url(252) }}"
height="126"
width="126"
/>
Expand Down
2 changes: 1 addition & 1 deletion pontoon/contributors/templates/contributors/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
{% endif %}
<img
class="rounded"
src="{{ contributor.gravatar_url(512) }}"
src="{{ contributor.avatar_url(512) }}"
width="256"
height="256"
/>
Expand Down
2 changes: 1 addition & 1 deletion pontoon/contributors/templates/contributors/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<div class="desc">Update profile picture</div>
<img
class="rounded"
src="{{ user.gravatar_url(400) }}"
src="{{ user.avatar_url(400) }}"
width="200"
height="200"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
>
<img
class="rounded"
src="{{ contributor.gravatar_url(88) }}"
src="{{ contributor.avatar_url(88) }}"
width="44"
height="44"
/>
Expand Down
2 changes: 1 addition & 1 deletion pontoon/messaging/templates/messaging/includes/sent.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
rel="noopener noreferrer"
>
<img
src="{{ message.sender.gravatar_url(88) }}"
src="{{ message.sender.avatar_url(88) }}"
height="44"
width="44"
class="rounded"
Expand Down
2 changes: 1 addition & 1 deletion pontoon/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,7 @@ def account_username(user):
FXA_SECRET_KEY = os.environ.get("FXA_SECRET_KEY")
FXA_OAUTH_ENDPOINT = os.environ.get("FXA_OAUTH_ENDPOINT", "")
FXA_PROFILE_ENDPOINT = os.environ.get("FXA_PROFILE_ENDPOINT", "")
FXA_SCOPE = ["profile:uid", "profile:display_name", "profile:email"]
FXA_SCOPE = ["profile:uid", "profile:display_name", "profile:email", "profile:avatar"]

# Github
GITHUB_CLIENT_ID = os.environ.get("GITHUB_CLIENT_ID")
Expand Down