From e5a405bf43119ac927f4bee874c631901f3433aa Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 23 Feb 2019 20:42:14 +0100 Subject: [PATCH] Register applications with Branded name for UI Dropdown --- passbook/oauth_client/source_types/discord.py | 4 ++-- passbook/oauth_client/source_types/facebook.py | 4 ++-- passbook/oauth_client/source_types/github.py | 2 +- passbook/oauth_client/source_types/google.py | 4 ++-- passbook/oauth_client/source_types/manager.py | 8 +++++++- passbook/oauth_client/source_types/twitter.py | 2 +- 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/passbook/oauth_client/source_types/discord.py b/passbook/oauth_client/source_types/discord.py index 4c4477b0d..6052e519e 100644 --- a/passbook/oauth_client/source_types/discord.py +++ b/passbook/oauth_client/source_types/discord.py @@ -13,7 +13,7 @@ from passbook.oauth_client.views.core import OAuthCallback, OAuthRedirect LOGGER = getLogger(__name__) -@MANAGER.source(kind=RequestKind.redirect, name='discord') +@MANAGER.source(kind=RequestKind.redirect, name='Discord') class DiscordOAuthRedirect(OAuthRedirect): """Discord OAuth2 Redirect""" @@ -43,7 +43,7 @@ class DiscordOAuth2Client(OAuth2Client): return response.json() or response.text -@MANAGER.source(kind=RequestKind.callback, name='discord') +@MANAGER.source(kind=RequestKind.callback, name='Discord') class DiscordOAuth2Callback(OAuthCallback): """Discord OAuth2 Callback""" diff --git a/passbook/oauth_client/source_types/facebook.py b/passbook/oauth_client/source_types/facebook.py index 5246f8beb..143d32bc4 100644 --- a/passbook/oauth_client/source_types/facebook.py +++ b/passbook/oauth_client/source_types/facebook.py @@ -7,7 +7,7 @@ from passbook.oauth_client.utils import user_get_or_create from passbook.oauth_client.views.core import OAuthCallback, OAuthRedirect -@MANAGER.source(kind=RequestKind.redirect, name='facebook') +@MANAGER.source(kind=RequestKind.redirect, name='Facebook') class FacebookOAuthRedirect(OAuthRedirect): """Facebook OAuth2 Redirect""" @@ -17,7 +17,7 @@ class FacebookOAuthRedirect(OAuthRedirect): } -@MANAGER.source(kind=RequestKind.callback, name='facebook') +@MANAGER.source(kind=RequestKind.callback, name='Facebook') class FacebookOAuth2Callback(OAuthCallback): """Facebook OAuth2 Callback""" diff --git a/passbook/oauth_client/source_types/github.py b/passbook/oauth_client/source_types/github.py index 6068088e4..38c2bb288 100644 --- a/passbook/oauth_client/source_types/github.py +++ b/passbook/oauth_client/source_types/github.py @@ -7,7 +7,7 @@ from passbook.oauth_client.utils import user_get_or_create from passbook.oauth_client.views.core import OAuthCallback -@MANAGER.source(kind=RequestKind.callback, name='github') +@MANAGER.source(kind=RequestKind.callback, name='GitHub') class GitHubOAuth2Callback(OAuthCallback): """GitHub OAuth2 Callback""" diff --git a/passbook/oauth_client/source_types/google.py b/passbook/oauth_client/source_types/google.py index d15c4e51d..c739c1156 100644 --- a/passbook/oauth_client/source_types/google.py +++ b/passbook/oauth_client/source_types/google.py @@ -6,7 +6,7 @@ from passbook.oauth_client.utils import user_get_or_create from passbook.oauth_client.views.core import OAuthCallback, OAuthRedirect -@MANAGER.source(kind=RequestKind.redirect, name='google') +@MANAGER.source(kind=RequestKind.redirect, name='Google') class GoogleOAuthRedirect(OAuthRedirect): """Google OAuth2 Redirect""" @@ -16,7 +16,7 @@ class GoogleOAuthRedirect(OAuthRedirect): } -@MANAGER.source(kind=RequestKind.callback, name='google') +@MANAGER.source(kind=RequestKind.callback, name='Google') class GoogleOAuth2Callback(OAuthCallback): """Google OAuth2 Callback""" diff --git a/passbook/oauth_client/source_types/manager.py b/passbook/oauth_client/source_types/manager.py index a98d4b283..d34b060e7 100644 --- a/passbook/oauth_client/source_types/manager.py +++ b/passbook/oauth_client/source_types/manager.py @@ -17,17 +17,23 @@ class SourceTypeManager: """Manager to hold all Source types.""" __source_types = {} + __names = [] def source(self, kind, name): """Class decorator to register classes inline.""" def inner_wrapper(cls): if kind not in self.__source_types: self.__source_types[kind] = {} - self.__source_types[kind][name] = cls + self.__source_types[kind][name.lower()] = cls + self.__names.append(name) LOGGER.debug("Registered source '%s' for '%s'", cls.__name__, kind) return cls return inner_wrapper + def get_name_tuple(self): + """Get list of tuples of all registered names""" + return [(x.lower(), x) for x in set(self.__names)] + def find(self, source, kind): """Find fitting Source Type""" if kind in self.__source_types: diff --git a/passbook/oauth_client/source_types/twitter.py b/passbook/oauth_client/source_types/twitter.py index 95bd2bca8..60a7d8b2c 100644 --- a/passbook/oauth_client/source_types/twitter.py +++ b/passbook/oauth_client/source_types/twitter.py @@ -29,7 +29,7 @@ class TwitterOAuthClient(OAuthClient): return response.json() or response.text -@MANAGER.source(kind=RequestKind.callback, name='twitter') +@MANAGER.source(kind=RequestKind.callback, name='Twitter') class TwitterOAuthCallback(OAuthCallback): """Twitter OAuth2 Callback"""