|
30 | 30 | from flask_appbuilder.security.views import AuthOAuthView
|
31 | 31 | from flask_appbuilder import expose
|
32 | 32 | from flask import flash, get_flashed_messages
|
| 33 | +from flask_babel import get_locale |
33 | 34 | from werkzeug.wrappers import Response as WerkzeugResponse
|
34 | 35 |
|
35 | 36 | from superset.security import SupersetSecurityManager
|
|
39 | 40 |
|
40 | 41 | logger = logging.getLogger()
|
41 | 42 |
|
42 |
| - |
43 | 43 | def get_env_variable(var_name: str, default: Optional[str] = None) -> str:
|
44 | 44 | """Get the environment variable or raise exception."""
|
45 | 45 | try:
|
@@ -121,15 +121,49 @@ class CeleryConfig(object):
|
121 | 121 | # Custom config for biocultural monitoring deployments by CMI
|
122 | 122 | AUTH0_DOMAIN = get_env_variable("AUTH0_DOMAIN")
|
123 | 123 |
|
| 124 | +# Define translations |
| 125 | +translations = { |
| 126 | + "Welcome! Please sign up or log in by pressing 'Sign in with auth0' to access the application": { |
| 127 | + "pt_BR": "Bem-vindo! Por favor, inscreva-se ou faça login pressionando 'Sign in with auth0' para acessar o aplicativo.", |
| 128 | + "en": "Welcome! Please sign up or log in by pressing 'Sign in with auth0' to access the application", |
| 129 | + "nl": "Welkom! Meld u aan of log in door op 'Sign in with auth0' te drukken om toegang te krijgen tot de applicatie.", |
| 130 | + "es": "¡Bienvenido! Regístrese o inicie sesión presionando 'Sign in with auth0' para acceder a la aplicación.", |
| 131 | + "fr": "Bienvenue! Veuillez vous inscrire ou vous connecter en appuyant sur 'Sign in with auth0' pour accéder à l'application." |
| 132 | + }, |
| 133 | + "The request to sign in was denied.": { |
| 134 | + "pt_BR": "O pedido de login foi negado.", |
| 135 | + "en": "The request to sign in was denied.", |
| 136 | + "nl": "Het verzoek om in te loggen werd geweigerd.", |
| 137 | + "es": "La solicitud de inicio de sesión fue denegada.", |
| 138 | + "fr": "La demande de connexion a été refusée." |
| 139 | + }, |
| 140 | + "You are not yet authorized to access this application. Please contact a GuardianConnector administrator for access.": { |
| 141 | + "pt_BR": "Você ainda não está autorizado a acessar este aplicativo. Por favor, entre em contato com um administrador do GuardianConnector para obter acesso.", |
| 142 | + "en": "You are not yet authorized to access this application. Please contact a GuardianConnector administrator for access.", |
| 143 | + "nl": "U bent nog niet gemachtigd om toegang te krijgen tot deze applicatie. Neem contact op met een GuardianConnector-beheerder voor toegang.", |
| 144 | + "es": "Aún no está autorizado para acceder a esta aplicación. Comuníquese con un administrador de GuardianConnector para obtener acceso.", |
| 145 | + "fr": "Vous n'êtes pas encore autorisé à accéder à cette application. Veuillez contacter un administrateur de GuardianConnector pour obtenir l'accès." |
| 146 | + } |
| 147 | +} |
| 148 | + |
| 149 | +def translate(message): |
| 150 | + locale = str(get_locale()) |
| 151 | + return translations.get(message, {}).get(locale, message) |
| 152 | + |
124 | 153 | # Extend the default AuthOAuthView to override the default message when the user is not authorized
|
125 | 154 | class CustomAuthOAuthView(AuthOAuthView):
|
| 155 | + @expose("/login") |
| 156 | + def login(self) -> WerkzeugResponse: |
| 157 | + flash(translate("Welcome! Please sign up or log in by pressing 'Sign in with auth0' to access the application"), "info") |
| 158 | + return super().login() |
| 159 | + |
126 | 160 | @expose("/oauth-authorized/<provider>")
|
127 | 161 | def oauth_authorized(self, provider: str) -> WerkzeugResponse:
|
128 | 162 | response = super().oauth_authorized(provider)
|
129 | 163 |
|
130 | 164 | messages = get_flashed_messages(with_categories=True)
|
131 |
| - if ('error', 'The request to sign in was denied.') in messages: |
132 |
| - flash("You are not yet authorized to access this application. Please contact a GuardianConnector administrator for access.", "warning") |
| 165 | + if ('error', translate("The request to sign in was denied.")) in messages: |
| 166 | + flash(translate("You are not yet authorized to access this application. Please contact a GuardianConnector administrator for access."), "warning") |
133 | 167 | return response
|
134 | 168 |
|
135 | 169 | # https://superset.apache.org/docs/installation/configuring-superset/#custom-oauth2-configuration
|
@@ -193,7 +227,6 @@ def oauth_user_info(self, provider, response=None):
|
193 | 227 | 'api_base_url':f'https://{AUTH0_DOMAIN}/oauth/',
|
194 | 228 | 'access_token_url': f'https://{AUTH0_DOMAIN}/oauth/token',
|
195 | 229 | 'authorize_url': f'https://{AUTH0_DOMAIN}/authorize'
|
196 |
| - |
197 | 230 | }
|
198 | 231 | }]
|
199 | 232 |
|
|
0 commit comments