From: Radek Czajka Date: Thu, 29 Jun 2023 12:55:26 +0000 (+0200) Subject: Allow wl disconnect. X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/618d42c8ba5972668624987393b244cfb2fabfba?ds=sidebyside Allow wl disconnect. --- diff --git a/src/apiclient/urls.py b/src/apiclient/urls.py index f0613804..53178636 100644 --- a/src/apiclient/urls.py +++ b/src/apiclient/urls.py @@ -10,4 +10,5 @@ urlpatterns = [ path('oauth_callback/', views.oauth_callback, name='apiclient_oauth_callback'), path('oauth-beta/', views.oauth, kwargs={'beta': True}, name='apiclient_beta_oauth'), path('oauth_callback-beta/', views.oauth_callback, kwargs={'beta': True}, name='apiclient_beta_callback'), + path('disconnect', views.disconnect, name='apiclient_disconnect'), ] diff --git a/src/apiclient/views.py b/src/apiclient/views.py index 666ef481..b2f3aac2 100644 --- a/src/apiclient/views.py +++ b/src/apiclient/views.py @@ -6,6 +6,7 @@ from urllib.parse import parse_qsl from django.contrib.auth.decorators import login_required from django.urls import reverse from django.http import HttpResponseRedirect, HttpResponse +from django.views.decorators.http import require_POST import oauth2 from apiclient.models import OAuthConnection @@ -61,3 +62,10 @@ def oauth_callback(request, beta=False): conn.save() return HttpResponseRedirect('/') + + +@login_required +@require_POST +def disconnect(request): + request.user.oauthconnection_set.filter(beta=False).delete() + return HttpResponseRedirect(reverse('documents_user')) diff --git a/src/documents/templates/documents/my_page.html b/src/documents/templates/documents/my_page.html index 6828706a..68c458e3 100644 --- a/src/documents/templates/documents/my_page.html +++ b/src/documents/templates/documents/my_page.html @@ -22,7 +22,28 @@ {% endblock leftcolumn %} {% block rightcolumn %} -
+ {% if wllogin %} +
+
+

Konto WL

+
+
+

+ Podłączone konto na Wolnych Lekturach: + {{ wllogin }} +

+
+ {% csrf_token %} + +
+
+ +
+ {% endif %} + +

{% trans "Your last edited documents" %}

diff --git a/src/documents/views.py b/src/documents/views.py index 39320d5e..a930b8dc 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -23,7 +23,7 @@ from django.utils.translation import gettext_lazy as _ from django.views.decorators.http import require_POST from django_cas_ng.decorators import user_passes_test -from apiclient import NotAuthorizedError +from apiclient import api_call, NotAuthorizedError from . import forms from . import helpers from .helpers import active_tab @@ -65,9 +65,17 @@ def my(request): key=lambda x: x[1]['time'], reverse=True) for k, v in last_books: v['time'] = datetime.fromtimestamp(v['time']) + try: + resp = api_call(request.user, 'username/') + except NotAuthorizedError: + wllogin = None + else: + wllogin = resp['username'] + return render(request, 'documents/my_page.html', { 'last_books': last_books, "logout_to": '/', + "wllogin": wllogin, })