From b0fa302718867db296ba46d1232396e3d7bba4f7 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 18 Dec 2018 13:24:58 +0100 Subject: [PATCH] core: add is_link and get_url property to base Source --- passbook/core/models.py | 10 ++++++++++ passbook/ldap/models.py | 4 ++++ passbook/oauth_client/models.py | 10 ++++++++++ 3 files changed, 24 insertions(+) diff --git a/passbook/core/models.py b/passbook/core/models.py index df6deec01..6c8733eaa 100644 --- a/passbook/core/models.py +++ b/passbook/core/models.py @@ -82,6 +82,16 @@ class Source(RuleModel): objects = InheritanceManager() + @property + def is_link(self): + """Return true if Source should get a link on the login page""" + return False + + @property + def get_url(self): + """Return URL used for logging in""" + raise NotImplementedError + def __str__(self): return self.name diff --git a/passbook/ldap/models.py b/passbook/ldap/models.py index decd969ac..bad25e50f 100644 --- a/passbook/ldap/models.py +++ b/passbook/ldap/models.py @@ -28,6 +28,10 @@ class LDAPSource(Source): form = 'passbook.ldap.forms.LDAPSourceForm' + @property + def get_url(self): + raise NotImplementedError() + class Meta: verbose_name = _('LDAP Source') diff --git a/passbook/oauth_client/models.py b/passbook/oauth_client/models.py index c53097e63..434523786 100644 --- a/passbook/oauth_client/models.py +++ b/passbook/oauth_client/models.py @@ -1,6 +1,7 @@ """OAuth Client models""" from django.db import models +from django.urls import reverse_lazy from django.utils.translation import gettext as _ from passbook.core.models import Source, UserSourceConnection @@ -20,6 +21,15 @@ class OAuthSource(Source): form = 'passbook.oauth_client.forms.GitHubOAuthSourceForm' + @property + def is_link(self): + return True + + @property + def get_url(self): + return reverse_lazy('passbook_oauth_client:oauth-client-login', + kwargs={'source_slug': self.slug}) + class Meta: verbose_name = _('Generic OAuth Source')