From 35620cc6e63173cc85c43bfec976bdb78ecfdac7 Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Mon, 29 Jul 2024 16:12:21 -0500 Subject: [PATCH] Social accounts: Add filter to check if a social account can be disconnected --- .../core/templatetags/readthedocs/__init__.py | 0 .../readthedocs/socialaccounts.py | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 readthedocs/core/templatetags/readthedocs/__init__.py create mode 100644 readthedocs/core/templatetags/readthedocs/socialaccounts.py diff --git a/readthedocs/core/templatetags/readthedocs/__init__.py b/readthedocs/core/templatetags/readthedocs/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/readthedocs/core/templatetags/readthedocs/socialaccounts.py b/readthedocs/core/templatetags/readthedocs/socialaccounts.py new file mode 100644 index 00000000000..253fba59e84 --- /dev/null +++ b/readthedocs/core/templatetags/readthedocs/socialaccounts.py @@ -0,0 +1,19 @@ +from allauth.socialaccount.adapter import get_adapter +from django import forms, template + +register = template.Library() + + +@register.filter +def can_be_disconnected(account): + """ + Check if a social account can be disconnected. + + This is used to disable the disconnect button for certain social accounts. + """ + adapter = get_adapter() + try: + adapter.validate_disconnect(account=account, accounts=[]) + return True + except forms.ValidationError: + return False