Skip to content

Commit 61b9f19

Browse files
authored
Social accounts: Add filter to check if a social account can be disconnected (#11503)
1 parent c99de36 commit 61b9f19

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

readthedocs/core/templatetags/readthedocs/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from allauth.socialaccount.adapter import get_adapter
2+
from django import forms, template
3+
4+
register = template.Library()
5+
6+
7+
@register.filter
8+
def can_be_disconnected(account):
9+
"""
10+
Check if a social account can be disconnected.
11+
12+
This is used to disable the disconnect button for certain social accounts.
13+
"""
14+
adapter = get_adapter()
15+
try:
16+
adapter.validate_disconnect(account=account, accounts=[])
17+
return True
18+
except forms.ValidationError:
19+
return False

0 commit comments

Comments
 (0)