mirror of
https://github.com/boostorg/website-v2.git
synced 2026-01-19 04:42:17 +00:00
Remove old profile page
This commit is contained in:
@@ -53,9 +53,6 @@ from support.views import SupportView
|
||||
from users.views import (
|
||||
CurrentUserAPIView,
|
||||
CurrentUserProfileView,
|
||||
NewCurrentUserProfileView,
|
||||
ProfilePhotoGitHubUpdateView,
|
||||
ProfilePhotoUploadView,
|
||||
ProfilePreferencesView,
|
||||
ProfileView,
|
||||
UserViewSet,
|
||||
@@ -76,22 +73,11 @@ urlpatterns = (
|
||||
path("homepage-beta/", HomepageBetaView.as_view(), name="home-beta"),
|
||||
path("admin/", admin.site.urls),
|
||||
path("accounts/", include("allauth.urls")),
|
||||
path(
|
||||
"users/me/update-github-photo/",
|
||||
ProfilePhotoGitHubUpdateView.as_view(),
|
||||
name="profile-photo-github",
|
||||
),
|
||||
path("users/me/photo/", ProfilePhotoUploadView.as_view(), name="profile-photo"),
|
||||
path(
|
||||
"users/me/preferences/",
|
||||
ProfilePreferencesView.as_view(),
|
||||
name="profile-preferences",
|
||||
),
|
||||
path(
|
||||
"users/me/new/",
|
||||
NewCurrentUserProfileView.as_view(),
|
||||
name="profile-account-new",
|
||||
),
|
||||
path("users/me/", CurrentUserProfileView.as_view(), name="profile-account"),
|
||||
# Temp route to prove antora header
|
||||
path("testheader/", antora_header_view, name="antora-header"),
|
||||
|
||||
@@ -150,7 +150,7 @@
|
||||
tabindex="-1"
|
||||
style="display: none;"
|
||||
>
|
||||
<a href="{% url 'profile-account-new' %}" class="block py-2 text-xs font-medium dark:text-white text-charcoal dark:hover:text-orange hover:text-orange">My Profile</a>
|
||||
<a href="{% url 'profile-account' %}" class="block py-2 text-xs font-medium dark:text-white text-charcoal dark:hover:text-orange hover:text-orange">My Profile</a>
|
||||
<a href="{% url 'account_logout' %}" class="block py-2 text-xs font-medium dark:text-white text-charcoal dark:hover:text-orange hover:text-orange">Log Out</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
{% extends "users/profile_base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<div class="content-section">
|
||||
<div class="mt-6">
|
||||
<img class="w-32 h-32 rounded-full md:h-auto" src="{{ user.profile.image.url }}">
|
||||
</div>
|
||||
|
||||
<h3>Update Profile Photo</h3>
|
||||
|
||||
{% if user_has_gh_username %}
|
||||
<form method="POST" action="{% url 'profile-photo-github' %}">
|
||||
{% csrf_token %}
|
||||
<button class="py-2 px-3 text-sm uppercase rounded border border-orange text-orange" type="submit">Use My GitHub Photo</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
<form method="POST" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
<fieldset>
|
||||
{{ form.as_p }}
|
||||
</fieldset>
|
||||
<div class="mb-4">
|
||||
<button class="py-2 px-3 text-sm uppercase rounded border border-orange text-orange" type="submit">Update</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
@@ -1,8 +1,4 @@
|
||||
import tempfile
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
from django.test import override_settings
|
||||
|
||||
|
||||
User = get_user_model()
|
||||
@@ -74,44 +70,3 @@ def test_signup_post(tp, db):
|
||||
)
|
||||
tp.response_302(res)
|
||||
assert User.objects.filter(email="testerson@example.com").exists()
|
||||
|
||||
|
||||
def test_profile_photo_auth(tp, db):
|
||||
"""
|
||||
POST /users/me/photo/
|
||||
|
||||
Canary test that the photo upload page is protected.
|
||||
"""
|
||||
res = tp.post("profile-photo")
|
||||
tp.response_302(res)
|
||||
assert "/accounts/login" in res.url
|
||||
|
||||
|
||||
@override_settings(MEDIA_ROOT=tempfile.gettempdir())
|
||||
def test_profile_photo_update_success(tp, user, client):
|
||||
"""
|
||||
POST /users/me/photo
|
||||
|
||||
Confirm that user can update their profile photo
|
||||
"""
|
||||
old_image = user.image
|
||||
client.force_login(user)
|
||||
image = SimpleUploadedFile(
|
||||
"/image/fpo/user.png", b"file_content", content_type="image/png"
|
||||
)
|
||||
res = tp.post("profile-photo", data={"image": image})
|
||||
tp.response_302(res)
|
||||
assert "/users/me/" in res.url
|
||||
user.refresh_from_db()
|
||||
assert user.image != old_image
|
||||
|
||||
|
||||
def test_profile_photo_github_auth(tp, db):
|
||||
"""
|
||||
POST /users/me/update-github-photo/
|
||||
|
||||
Canary test that the github photo update page is protected.
|
||||
"""
|
||||
res = tp.post("profile-photo-github")
|
||||
tp.response_302(res)
|
||||
assert "/accounts/login" in res.url
|
||||
|
||||
@@ -67,23 +67,23 @@ def test_preferences_post_clears_options(
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_new_current_user_profile_not_authenticated(tp, user):
|
||||
tp.assertLoginRequired("profile-account-new")
|
||||
tp.assertLoginRequired("profile-account")
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_new_current_user_profile_view_get(user, tp):
|
||||
def test_current_user_profile_view_get(user, tp):
|
||||
with tp.login(user):
|
||||
response = tp.assertGoodView(tp.reverse("profile-account-new"), verbose=True)
|
||||
response = tp.assertGoodView(tp.reverse("profile-account"), verbose=True)
|
||||
assert isinstance(response.context["change_password_form"], ChangePasswordForm)
|
||||
assert isinstance(response.context["profile_photo_form"], UserProfilePhotoForm)
|
||||
assert isinstance(response.context["profile_preferences_form"], PreferencesForm)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_new_current_user_profile_view_post_valid_password(user, tp):
|
||||
def test_current_user_profile_view_post_valid_password(user, tp):
|
||||
with tp.login(user):
|
||||
response = tp.post(
|
||||
tp.reverse("profile-account-new"),
|
||||
tp.reverse("profile-account"),
|
||||
data={
|
||||
"email": user.email,
|
||||
"oldpassword": "password",
|
||||
@@ -98,11 +98,11 @@ def test_new_current_user_profile_view_post_valid_password(user, tp):
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_new_current_user_profile_view_post_invalid_password(user, tp):
|
||||
def test_current_user_profile_view_post_invalid_password(user, tp):
|
||||
old_password = "password"
|
||||
with tp.login(user):
|
||||
response = tp.post(
|
||||
tp.reverse("profile-account-new"),
|
||||
tp.reverse("profile-account"),
|
||||
data={
|
||||
"email": user.email,
|
||||
"oldpassword": "not the right password",
|
||||
@@ -117,13 +117,13 @@ def test_new_current_user_profile_view_post_invalid_password(user, tp):
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_new_current_user_profile_view_update_name(user, tp):
|
||||
def test_current_user_profile_view_update_name(user, tp):
|
||||
new_first_name = "Tester"
|
||||
new_last_name = "Testerson"
|
||||
|
||||
with tp.login(user):
|
||||
response = tp.post(
|
||||
tp.reverse("profile-account-new"),
|
||||
tp.reverse("profile-account"),
|
||||
data={
|
||||
"email": user.email,
|
||||
"first_name": new_first_name,
|
||||
@@ -139,7 +139,7 @@ def test_new_current_user_profile_view_update_name(user, tp):
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_new_current_user_profile_view_post_valid_photo(user, tp):
|
||||
def test_current_user_profile_view_post_valid_photo(user, tp):
|
||||
"""Test that a user can upload a new profile picture."""
|
||||
# Create a temporary image file for testing
|
||||
with tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) as temp_image:
|
||||
@@ -154,7 +154,7 @@ def test_new_current_user_profile_view_post_valid_photo(user, tp):
|
||||
|
||||
with tp.login(user):
|
||||
response = tp.post(
|
||||
tp.reverse("profile-account-new"),
|
||||
tp.reverse("profile-account"),
|
||||
data={
|
||||
"image": uploaded_file,
|
||||
},
|
||||
@@ -170,7 +170,7 @@ def test_new_current_user_profile_view_post_valid_photo(user, tp):
|
||||
@pytest.mark.django_db
|
||||
@pytest.mark.parametrize("user_type", ["user", "moderator_user"])
|
||||
@pytest.mark.parametrize("form_field", PreferencesForm.Meta.fields)
|
||||
def test_new_current_user_profile_view_post_valid_preferences(
|
||||
def test_current_user_profile_view_post_valid_preferences(
|
||||
user_type, form_field, tp, request, assert_messages
|
||||
):
|
||||
user = request.getfixturevalue(user_type)
|
||||
@@ -183,7 +183,7 @@ def test_new_current_user_profile_view_post_valid_preferences(
|
||||
|
||||
with tp.login(user):
|
||||
response = tp.post(
|
||||
tp.reverse("profile-account-new"),
|
||||
tp.reverse("profile-account"),
|
||||
data={**new_preferences, "update_preferences": "Update Preeferences"},
|
||||
follow=True,
|
||||
)
|
||||
|
||||
@@ -4,7 +4,6 @@ from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.urls import reverse_lazy
|
||||
from django.views.generic import DetailView, UpdateView
|
||||
from django.views.generic.edit import FormView
|
||||
from django.views.generic.base import TemplateView
|
||||
|
||||
from allauth.account.forms import ChangePasswordForm
|
||||
@@ -71,54 +70,6 @@ class ProfileView(DetailView):
|
||||
return context
|
||||
|
||||
|
||||
class CurrentUserProfileView(LoginRequiredMixin, ProfileView):
|
||||
def get_object(self):
|
||||
return self.request.user
|
||||
|
||||
|
||||
class ProfilePhotoUploadView(LoginRequiredMixin, FormView):
|
||||
"""Allows a user to change their profile photo"""
|
||||
|
||||
template_name = "users/photo_upload.html"
|
||||
form_class = UserProfilePhotoForm
|
||||
success_url = reverse_lazy("profile-account")
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
user = self.request.user
|
||||
context["user_has_gh_username"] = bool(user.github_username)
|
||||
return context
|
||||
|
||||
def get_success_url(self, **kwargs):
|
||||
return reverse_lazy("profile-account")
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
form = self.form_class(request.POST, request.FILES, instance=self.request.user)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
messages.success(request, "Your profile photo has been updated")
|
||||
return super().form_valid(form)
|
||||
else:
|
||||
return super().form_invalid()
|
||||
|
||||
|
||||
class ProfilePhotoGitHubUpdateView(LoginRequiredMixin, UpdateView):
|
||||
"""Allow a user to sync their profile photo to their current GitHub photo."""
|
||||
|
||||
http_method_names = ["post"]
|
||||
|
||||
def get_object(self, queryset=None):
|
||||
return self.request.user
|
||||
|
||||
def get_success_url(self, **kwargs):
|
||||
return reverse_lazy("profile-user", args=[self.request.user.pk])
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
user = self.get_object()
|
||||
tasks.update_user_github_photo.delay(user.pk)
|
||||
return HttpResponseRedirect(self.get_success_url())
|
||||
|
||||
|
||||
class ProfilePreferencesView(LoginRequiredMixin, SuccessMessageMixin, UpdateView):
|
||||
form_class = PreferencesForm
|
||||
template_name = "users/profile_preferences.html"
|
||||
@@ -129,10 +80,10 @@ class ProfilePreferencesView(LoginRequiredMixin, SuccessMessageMixin, UpdateView
|
||||
return self.request.user.preferences
|
||||
|
||||
|
||||
class NewCurrentUserProfileView(LoginRequiredMixin, SuccessMessageMixin, TemplateView):
|
||||
class CurrentUserProfileView(LoginRequiredMixin, SuccessMessageMixin, TemplateView):
|
||||
template_name = "users/profile_new.html"
|
||||
success_message = "Your profile was successfully updated."
|
||||
success_url = reverse_lazy("profile-account-new")
|
||||
success_url = reverse_lazy("profile-account")
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
Reference in New Issue
Block a user