mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-05-15 12:29:29 -05:00
Fixhancement: better handle removed social apps in profile (#9876)
This commit is contained in:
parent
a61f5ac64c
commit
73f0f1212d
@ -136,6 +136,36 @@ class TestApiProfile(DirectoriesMixin, APITestCase):
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_profile_w_social_removed_app(self):
|
||||||
|
"""
|
||||||
|
GIVEN:
|
||||||
|
- Configured user and setup social account
|
||||||
|
- Social app has been removed
|
||||||
|
WHEN:
|
||||||
|
- API call is made to get profile
|
||||||
|
THEN:
|
||||||
|
- Profile is returned with "Unknown App" as name
|
||||||
|
"""
|
||||||
|
self.setupSocialAccount()
|
||||||
|
|
||||||
|
# Remove the social app
|
||||||
|
SocialApp.objects.get(provider_id="keycloak-test").delete()
|
||||||
|
|
||||||
|
response = self.client.get(self.ENDPOINT)
|
||||||
|
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
response.data["social_accounts"],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"provider": "keycloak-test",
|
||||||
|
"name": "Unknown App",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def test_update_profile(self):
|
def test_update_profile(self):
|
||||||
"""
|
"""
|
||||||
GIVEN:
|
GIVEN:
|
||||||
|
@ -4,6 +4,7 @@ from allauth.mfa.adapter import get_adapter as get_mfa_adapter
|
|||||||
from allauth.mfa.models import Authenticator
|
from allauth.mfa.models import Authenticator
|
||||||
from allauth.mfa.totp.internal.auth import TOTP
|
from allauth.mfa.totp.internal.auth import TOTP
|
||||||
from allauth.socialaccount.models import SocialAccount
|
from allauth.socialaccount.models import SocialAccount
|
||||||
|
from allauth.socialaccount.models import SocialApp
|
||||||
from django.contrib.auth.models import Group
|
from django.contrib.auth.models import Group
|
||||||
from django.contrib.auth.models import Permission
|
from django.contrib.auth.models import Permission
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
@ -146,8 +147,11 @@ class SocialAccountSerializer(serializers.ModelSerializer):
|
|||||||
"name",
|
"name",
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_name(self, obj) -> str:
|
def get_name(self, obj: SocialAccount) -> str:
|
||||||
return obj.get_provider_account().to_str()
|
try:
|
||||||
|
return obj.get_provider_account().to_str()
|
||||||
|
except SocialApp.DoesNotExist:
|
||||||
|
return "Unknown App"
|
||||||
|
|
||||||
|
|
||||||
class ProfileSerializer(serializers.ModelSerializer):
|
class ProfileSerializer(serializers.ModelSerializer):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user