From f997e67ea2a3ded84a1a37a73745b91ee7decb6b Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 1 Sep 2021 01:09:23 +0200 Subject: [PATCH] patch social-connections into settings --- InvenTree/InvenTree/urls.py | 3 ++- InvenTree/InvenTree/views.py | 17 +++++++++++++++++ .../templates/InvenTree/settings/user.html | 8 ++++---- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/InvenTree/InvenTree/urls.py b/InvenTree/InvenTree/urls.py index d0c0bc076a..de874193b1 100644 --- a/InvenTree/InvenTree/urls.py +++ b/InvenTree/InvenTree/urls.py @@ -37,7 +37,7 @@ from rest_framework.documentation import include_docs_urls from .views import auth_request from .views import IndexView, SearchView, DatabaseStatsView -from .views import SettingsView, EditUserView, SetPasswordView, CustomEmailView +from .views import SettingsView, EditUserView, SetPasswordView, CustomEmailView, CustomConnectionsView from .views import CurrencyRefreshView from .views import AppearanceSelectView, SettingCategorySelectView from .views import DynamicJsView @@ -164,6 +164,7 @@ urlpatterns = [ # Single Sign On / allauth # overrides of urlpatterns url(r'^accounts/email/', CustomEmailView.as_view(), name='account_email'), + url(r'^accounts/social/connections/', CustomConnectionsView.as_view(), name='socialaccount_connections'), url(r'^accounts/', include('allauth.urls')), # included urlpatterns ] diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py index 53ced1e6dc..9951bc992f 100644 --- a/InvenTree/InvenTree/views.py +++ b/InvenTree/InvenTree/views.py @@ -25,8 +25,10 @@ from django.views.generic.base import RedirectView, TemplateView from djmoney.contrib.exchange.models import ExchangeBackend, Rate from allauth.account.forms import AddEmailForm +from allauth.socialaccount.forms import DisconnectForm from allauth.account.models import EmailAddress from allauth.account.views import EmailView +from allauth.socialaccount.views import ConnectionsView from common.settings import currency_code_default, currency_codes @@ -818,6 +820,10 @@ class SettingsView(TemplateView): ctx['add_email_form'] = AddEmailForm ctx["can_add_email"] = EmailAddress.objects.can_add_email(self.request.user) + # Form and context for allauth social-accounts + ctx["request"] = self.request + ctx['social_form'] = DisconnectForm(request=self.request) + return ctx @@ -832,6 +838,17 @@ class CustomEmailView(LoginRequiredMixin, EmailView): return HttpResponseRedirect(self.success_url) +class CustomConnectionsView(LoginRequiredMixin, ConnectionsView): + """ + Override of allauths ConnectionsView to always show the settings but leave the functions allow + """ + success_url = reverse_lazy("settings") + + def get(self, request, *args, **kwargs): + # always redirect to settings + return HttpResponseRedirect(self.success_url) + + class CurrencyRefreshView(RedirectView): """ POST endpoint to refresh / update exchange rates diff --git a/InvenTree/templates/InvenTree/settings/user.html b/InvenTree/templates/InvenTree/settings/user.html index b3b03cf238..7ac64880e0 100644 --- a/InvenTree/templates/InvenTree/settings/user.html +++ b/InvenTree/templates/InvenTree/settings/user.html @@ -102,7 +102,7 @@
- {% if form.accounts %} + {% if social_form.accounts %}

{% blocktrans %}You can sign in to your account using any of the following third party accounts:{% endblocktrans %}

@@ -110,11 +110,11 @@ {% csrf_token %}
- {% if form.non_field_errors %} -
{{ form.non_field_errors }}
+ {% if social_form.non_field_errors %} +
{{ social_form.non_field_errors }}
{% endif %} - {% for base_account in form.accounts %} + {% for base_account in social_form.accounts %} {% with base_account.get_provider_account as account %}