Skip to content

Commit 5b9815e

Browse files
committed
Filter social auths only for 'github-app' instead of using .first()
Fixes KIWI-TCMS-P5, https://kiwitcms.sentry.io/issues/5501934208/?project=277775 To reproduce the original bug: 1) Login via Google OAuth - uid is recorded as the email address 2) Login via GitHhub App integration - uid is an integer 3) Try editing the GitHub App via PLUGINS -> GitHub Integration -> Settings The first social_auth record will be picked up and will lead to a ValueError b/c the query expects an integer, not a string! With this commit the code will search for record where provider='github-app' because this is what it needs!
1 parent 660945d commit 5b9815e

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

tcms_github_app/admin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019-2020 Alexander Todorov <[email protected]>
1+
# Copyright (c) 2019-2024 Alexander Todorov <[email protected]>
22
#
33
# Licensed under GNU Affero General Public License v3 or later (AGPLv3+)
44
# https://www.gnu.org/licenses/agpl-3.0.html
@@ -107,7 +107,7 @@ def has_change_permission(self, request, obj=None):
107107
if not obj:
108108
return False
109109

110-
social_user = request.user.social_auth.first()
110+
social_user = request.user.social_auth.filter(provider='github-app').first()
111111
if not social_user:
112112
return False
113113

tcms_github_app/middleware.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019-2022 Alexander Todorov <[email protected]>
1+
# Copyright (c) 2019-2024 Alexander Todorov <[email protected]>
22
#
33
# Licensed under GNU Affero General Public License v3 or later (AGPLv3+)
44
# https://www.gnu.org/licenses/agpl-3.0.html
@@ -30,8 +30,8 @@ def __call__(self, request):
3030
return self.get_response(request)
3131

3232
app_inst = None
33-
social_user = request.user.social_auth.first()
34-
if social_user and social_user.uid.isdigit():
33+
social_user = request.user.social_auth.filter(provider='github-app').first()
34+
if social_user:
3535
app_inst = AppInstallation.objects.filter(
3636
sender=social_user.uid,
3737
tenant_pk=None

tcms_github_app/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def find_installations(request):
121121
# if there are more than 1 (usually on public) then try to find the installation
122122
# performed by the current user, e.g. on their own account
123123
if installations.count() > 1:
124-
social_user = request.user.social_auth.first()
124+
social_user = request.user.social_auth.filter(provider='github-app').first()
125125
if social_user:
126126
installations = installations.filter(sender=social_user.uid)
127127

tcms_github_app/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019-2021 Alexander Todorov <[email protected]>
1+
# Copyright (c) 2019-2024 Alexander Todorov <[email protected]>
22
#
33
# Licensed under GNU Affero General Public License v3 or later (AGPLv3+)
44
# https://www.gnu.org/licenses/agpl-3.0.html
@@ -41,7 +41,7 @@ class ApplicationEdit(View): # pylint: disable=missing-permission-required
4141
a ``@permission_required`` decorator here!
4242
"""
4343
def get(self, request, *args, **kwargs):
44-
social_user = request.user.social_auth.first()
44+
social_user = request.user.social_auth.filter(provider='github-app').first()
4545
if not social_user:
4646
github_url = reverse('social:begin', args=['github-app'])
4747
messages.add_message(

0 commit comments

Comments
 (0)