From ebe07d249e119c0ce8dcec3bc4f7123c0f79a4da Mon Sep 17 00:00:00 2001 From: Lacey Williams Henschel Date: Fri, 4 Aug 2023 13:11:06 -0700 Subject: [PATCH] Remove old profile page --- config/urls.py | 14 -------- templates/includes/_header.html | 2 +- templates/users/photo_upload.html | 31 ------------------ users/tests/test_urls.py | 45 -------------------------- users/tests/test_views.py | 26 +++++++-------- users/views.py | 53 ++----------------------------- 6 files changed, 16 insertions(+), 155 deletions(-) delete mode 100644 templates/users/photo_upload.html diff --git a/config/urls.py b/config/urls.py index bedbeb1b..88c7d66d 100755 --- a/config/urls.py +++ b/config/urls.py @@ -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"), diff --git a/templates/includes/_header.html b/templates/includes/_header.html index 5749f604..7f24d2f0 100644 --- a/templates/includes/_header.html +++ b/templates/includes/_header.html @@ -150,7 +150,7 @@ tabindex="-1" style="display: none;" > - My Profile + My Profile Log Out {% endif %} diff --git a/templates/users/photo_upload.html b/templates/users/photo_upload.html deleted file mode 100644 index 0195bd6a..00000000 --- a/templates/users/photo_upload.html +++ /dev/null @@ -1,31 +0,0 @@ -{% extends "users/profile_base.html" %} - -{% block content %} -
-
-
- -
- -

Update Profile Photo

- - {% if user_has_gh_username %} -
- {% csrf_token %} - -
- {% endif %} - -
- {% csrf_token %} -
- {{ form.as_p }} -
-
- -
-
- -
-
-{% endblock content %} diff --git a/users/tests/test_urls.py b/users/tests/test_urls.py index 60e29b35..601b94b8 100644 --- a/users/tests/test_urls.py +++ b/users/tests/test_urls.py @@ -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 diff --git a/users/tests/test_views.py b/users/tests/test_views.py index 8c1da305..6c2da611 100644 --- a/users/tests/test_views.py +++ b/users/tests/test_views.py @@ -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, ) diff --git a/users/views.py b/users/views.py index 1d64b64a..c862ecdf 100644 --- a/users/views.py +++ b/users/views.py @@ -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)