Fix OAuth Client's disconnect view having invalid URL names

This commit is contained in:
Jens Langhammer 2019-03-14 21:19:14 +01:00
parent 29d5962c4c
commit 81ab9092fc
1 changed files with 14 additions and 10 deletions

View File

@ -194,7 +194,9 @@ class OAuthCallback(OAuthClientMixin, View):
messages.success(self.request, _("Successfully linked %(source)s!" % { messages.success(self.request, _("Successfully linked %(source)s!" % {
'source': self.source.name 'source': self.source.name
})) }))
return redirect(reverse('user_settings')) return redirect(reverse('passbook_oauth_client:oauth-client-user', kwargs={
'source_slug': self.source.slug
}))
messages.success(self.request, _("Successfully authenticated with %(source)s!" % { messages.success(self.request, _("Successfully authenticated with %(source)s!" % {
'source': self.source.name 'source': self.source.name
})) }))
@ -207,26 +209,28 @@ class DisconnectView(LoginRequiredMixin, View):
source = None source = None
aas = None aas = None
def dispatch(self, request, source): def dispatch(self, request, source_slug):
self.source = get_object_or_404(OAuthSource, name=source) self.source = get_object_or_404(OAuthSource, slug=source_slug)
self.aas = get_object_or_404(UserOAuthSourceConnection, self.aas = get_object_or_404(UserOAuthSourceConnection,
source=self.source, user=request.user) source=self.source, user=request.user)
return super().dispatch(request, source) return super().dispatch(request, source_slug)
def post(self, request, source): def post(self, request, source_slug):
"""Delete connection object""" """Delete connection object"""
if 'confirmdelete' in request.POST: if 'confirmdelete' in request.POST:
# User confirmed deletion # User confirmed deletion
self.aas.delete() self.aas.delete()
messages.success(request, _('Connection successfully deleted')) messages.success(request, _('Connection successfully deleted'))
return redirect(reverse('user_settings')) return redirect(reverse('passbook_oauth_client:oauth-client-user', kwargs={
return self.get(request, source) 'source_slug': self.source.slug
}))
return self.get(request, source_slug)
def get(self, request, source): def get(self, request, source):
"""Show delete form""" """Show delete form"""
return render(request, 'generic/delete.html', { return render(request, 'generic/delete.html', {
'object': 'OAuth Connection with %s' % self.source.name, 'object': self.source,
'delete_url': reverse('oauth-client-disconnect', kwargs={ 'delete_url': reverse('passbook_oauth_client:oauth-client-disconnect', kwargs={
'source': self.source.name, 'source_slug': self.source.slug,
}) })
}) })