From f84e2e9a8ed0626a1073e2436e6bf3aa3d723472 Mon Sep 17 00:00:00 2001 From: freya Date: Thu, 7 Dec 2023 00:34:37 +0000 Subject: [PATCH] Username change (#64) * make user able to update their username * update to lodestone scraper to let it run on 3.8 * added user details form to edit the username * version bump --- backend/api/lodestone_scraper.py | 3 +- backend/api/serializers/settings.py | 3 +- backend/api/tests/test_user.py | 6 ++- backend/api/views/user.py | 4 ++ backend/backend/settings_live.py | 2 +- frontend/.env | 2 +- frontend/src/components/modals/changelog.vue | 5 ++ .../src/components/settings/user_details.vue | 44 +++++++++++++++++ frontend/src/main.ts | 2 +- frontend/src/views/settings.vue | 48 ++++++++++++++++--- 10 files changed, 106 insertions(+), 13 deletions(-) create mode 100644 frontend/src/components/settings/user_details.vue diff --git a/backend/api/lodestone_scraper.py b/backend/api/lodestone_scraper.py index 52c8cf9f..0a98a78b 100644 --- a/backend/api/lodestone_scraper.py +++ b/backend/api/lodestone_scraper.py @@ -1,6 +1,7 @@ # stdlib import logging import re +from typing import Optional # lib import requests from bs4 import BeautifulSoup @@ -46,7 +47,7 @@ def get_instance(cls) -> 'LodestoneScraper': cls._instance = instance return instance - def check_token(self, character_id: str, token: str) -> str | None: + def check_token(self, character_id: str, token: str) -> Optional[str]: """ Check the given character for the specified token being present in their bio. Return an error string to pass back to the FE if not found, or None if it was. diff --git a/backend/api/serializers/settings.py b/backend/api/serializers/settings.py index 20bab2e0..b754935f 100644 --- a/backend/api/serializers/settings.py +++ b/backend/api/serializers/settings.py @@ -16,10 +16,11 @@ class SettingsSerializer(serializers.ModelSerializer): + username = serializers.CharField(max_length=150) class Meta: model = Settings - fields = ['loot_manager_version', 'notifications', 'theme'] + fields = ['loot_manager_version', 'notifications', 'theme', 'username'] def validate_notifications(self, notifications: Dict[str, bool]) -> Dict[str, bool]: """ diff --git a/backend/api/tests/test_user.py b/backend/api/tests/test_user.py index 19e1b00c..7cb1bb56 100644 --- a/backend/api/tests/test_user.py +++ b/backend/api/tests/test_user.py @@ -48,16 +48,17 @@ def test_update(self): user = self._get_user() self.client.force_authenticate(user) - data = {'theme': 'blue', 'notifications': {'verify_fail': False}, 'loot_manager_version': 'fight'} + data = {'theme': 'blue', 'notifications': {'verify_fail': False}, 'loot_manager_version': 'fight', 'username': 'abcde'} response = self.client.put(url, data) self.assertEqual(response.status_code, status.HTTP_201_CREATED, response) user.refresh_from_db() self.assertEqual(user.settings.loot_manager_version, 'fight') self.assertEqual(user.settings.theme, 'blue') self.assertFalse(user.settings.notifications['verify_fail']) + self.assertEqual(user.get_full_name(), data['username']) # Run it again to hit the other block - data = {'theme': 'purple', 'notifications': {'verify_success': True}} + data = {'theme': 'purple', 'notifications': {'verify_success': True}, 'username': 'abcde'} response = self.client.put(url, data) self.assertEqual(response.status_code, status.HTTP_201_CREATED) user.refresh_from_db() @@ -78,6 +79,7 @@ def test_update_400(self): data = {'theme': 'abcde', 'notifications': {'abcde': 'abcde'}, 'loot_manager_version': 'abcde'} response = self.client.put(url, data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual(response.json()['username'], ['This field is required.']) self.assertEqual(response.json()['notifications'], ['"abcde" is not a valid choice.']) self.assertEqual(response.json()['loot_manager_version'], ['"abcde" is not a valid choice.']) diff --git a/backend/api/views/user.py b/backend/api/views/user.py index d4ff614f..ecc6f907 100644 --- a/backend/api/views/user.py +++ b/backend/api/views/user.py @@ -51,6 +51,10 @@ def put(self, request) -> Response: obj.loot_manager_version = serializer.validated_data.get('loot_manager_version', obj.loot_manager_version) obj.save() + # Update the username + request.user.first_name = serializer.validated_data.get('username', request.user.first_name) + request.user.save() + # Send websocket packet for updates self._send_to_user(request.user, {'type': 'settings'}) diff --git a/backend/backend/settings_live.py b/backend/backend/settings_live.py index ce1fe52d..5218af2f 100644 --- a/backend/backend/settings_live.py +++ b/backend/backend/settings_live.py @@ -184,7 +184,7 @@ def sampler(context): # If you wish to associate users to errors (assuming you are using # django.contrib.auth) you may enable sending PII data. send_default_pii=True, - release='savageaim@20231205', + release='savageaim@20231207', ) # Channels diff --git a/frontend/.env b/frontend/.env index 009d6eea..151f65db 100644 --- a/frontend/.env +++ b/frontend/.env @@ -1 +1 @@ -VUE_APP_VERSION="20231205" +VUE_APP_VERSION="20231207" diff --git a/frontend/src/components/modals/changelog.vue b/frontend/src/components/modals/changelog.vue index 5bc43667..c86fc71c 100644 --- a/frontend/src/components/modals/changelog.vue +++ b/frontend/src/components/modals/changelog.vue @@ -12,6 +12,11 @@

{{ version }}

+
expand_more Settings Updates expand_more
+

+ Usernames are now editable on the User Settings page! +

+

expand_more Major Fixes expand_more

diff --git a/frontend/src/components/settings/user_details.vue b/frontend/src/components/settings/user_details.vue new file mode 100644 index 00000000..579dc359 --- /dev/null +++ b/frontend/src/components/settings/user_details.vue @@ -0,0 +1,44 @@ + + + diff --git a/frontend/src/main.ts b/frontend/src/main.ts index e06c853b..29095c55 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -28,7 +28,7 @@ Sentry.init({ Vue, dsn: 'https://06f41b525a40497a848fb726f6d03244@o242258.ingest.sentry.io/6180221', logErrors: true, - release: 'savageaim@20231205', + release: 'savageaim@20231207', integrations: [ new Sentry.BrowserTracing({ routingInstrumentation: Sentry.vueRouterInstrumentation(router), diff --git a/frontend/src/views/settings.vue b/frontend/src/views/settings.vue index f03714ab..a85ce3d2 100644 --- a/frontend/src/views/settings.vue +++ b/frontend/src/views/settings.vue @@ -5,11 +5,16 @@