mirror of
https://github.com/postgres/pgweb.git
synced 2025-08-13 13:12:42 +00:00
Don't crash on concurrent consent given
If a user gave consent to sharing community auth data in two parallel sessions, one of them would crash with a unique violation. To avoid that, use the django function for get_or_create(), and just throw away the results if it turned out to be a get.
This commit is contained in:
@ -543,7 +543,9 @@ def communityauth_consent(request, siteid):
|
||||
if request.method == 'POST':
|
||||
form = CommunityAuthConsentForm(org.orgname, data=request.POST)
|
||||
if form.is_valid():
|
||||
CommunityAuthConsent(user=request.user, org=org, consentgiven=datetime.now()).save()
|
||||
CommunityAuthConsent.objects.get_or_create(user=request.user, org=org,
|
||||
defaults={'consentgiven':datetime.now()},
|
||||
)
|
||||
return HttpResponseRedirect(form.cleaned_data['next'])
|
||||
else:
|
||||
form = CommunityAuthConsentForm(org.orgname, initial={'next': request.GET['next']})
|
||||
|
Reference in New Issue
Block a user