Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Get available backends names

Mira Szewczyk496727b5ac1c
diff --git a/saleor/site/models.py b/saleor/site/models.py
index 0e6ec9caa4..d75b5b9bb4 100644
--- a/saleor/site/models.py
+++ b/saleor/site/models.py
@@ -26,6 +26,9 @@ class SiteSettings(models.Model):
def __str__(self):
return self.name
+ def available_backends(self):
+ return self.authorizationkey_set.values_list('name', flat=True)
+
@python_2_unicode_compatible
class AuthorizationKey(models.Model):
diff --git a/templates/account/partials/login_form.html b/templates/account/partials/login_form.html
index 575928b843..9202867248 100644
--- a/templates/account/partials/login_form.html
+++ b/templates/account/partials/login_form.html
@@ -20,18 +20,20 @@
{% trans "Forgot password?" context "Login form secondary link" %}
</a>
<hr>
+ {% with available_backends=settings.available_backends %}
<div class="row">
<div class="col-sm-6">
- {% if 'facebook' in backends.backends %}
+ {% if 'facebook' in backends.backends and 'facebook' in available_backends %}
<a class="social-btn facebook" href="{% url 'social:begin' 'facebook' %}"><img src="{% static 'images/facebook_icon.svg' %}" />{% trans 'Facebook' %}</a>
{% endif %}
</div>
<div class="col-sm-6">
- {% if 'google-oauth2' in backends.backends %}
+ {% if 'google-oauth2' in backends.backends and 'google-oauth2' in available_backends %}
<a class="social-btn google" href="{% url 'social:begin' 'google-oauth2' %}"><img src="{% static 'images/google_icon.svg' %}" />{% trans 'Google' %}</a>
{% endif %}
</div>
</div>
+ {% endwith %}
</div>
</div>
</form>
diff --git a/tests/test_site_settings.py b/tests/test_site_settings.py
index ec17e97a78..6383264236 100644
--- a/tests/test_site_settings.py
+++ b/tests/test_site_settings.py
@@ -80,3 +80,15 @@ def test_one_authorization_key_for_backend_and_settings(
@pytest.mark.django_db
def test_authorization_key_key_and_secret(authorization_key):
assert authorization_key.key_and_secret() == ('Key', 'Password')
+
+
+def test_settings_available_backends_empty(site_settings):
+ assert site_settings.available_backends().count() == 0
+
+
+def test_settings_available_backends(site_settings, authorization_key):
+ backend_name = authorization_key.name
+ available_backends = site_settings.available_backends()
+ assert backend_name in available_backends