Skip to content

Commit eddc23d

Browse files
authored
Translate flashed messages (and add one) for authentication flow (#28)
* Flash welcome message at login screen * Add translations for flashed messages * Bump version * Clarify welcome message
1 parent 0873b04 commit eddc23d

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ First you must commit to a specific release version of Superset, and
5757
Now you can build the image, and might as well push it to the container registry too:
5858

5959
```bash
60-
SS_VERSION=3.0.2
60+
SS_VERSION=3.0.3
6161
BUILD=$(date +"%Y%m%d-%H%M")
6262
OUR_TAG="${SS_VERSION}_${BUILD}"
6363
docker build -t guardiancr.azurecr.io/superset-docker:${OUR_TAG} .

docker-compose-non-dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
x-superset-image: &superset-image guardiancr.azurecr.io/superset-docker:3.0.2_20231215-0854
1+
x-superset-image: &superset-image guardiancr.azurecr.io/superset-docker:3.0.3_20240605-1556
22
x-superset-depends-on: &superset-depends-on []
33

44
version: "3.7"

docker/pythonpath/superset_config.py

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from flask_appbuilder.security.views import AuthOAuthView
3131
from flask_appbuilder import expose
3232
from flask import flash, get_flashed_messages
33+
from flask_babel import get_locale
3334
from werkzeug.wrappers import Response as WerkzeugResponse
3435

3536
from superset.security import SupersetSecurityManager
@@ -39,7 +40,6 @@
3940

4041
logger = logging.getLogger()
4142

42-
4343
def get_env_variable(var_name: str, default: Optional[str] = None) -> str:
4444
"""Get the environment variable or raise exception."""
4545
try:
@@ -121,15 +121,49 @@ class CeleryConfig(object):
121121
# Custom config for biocultural monitoring deployments by CMI
122122
AUTH0_DOMAIN = get_env_variable("AUTH0_DOMAIN")
123123

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+
124153
# Extend the default AuthOAuthView to override the default message when the user is not authorized
125154
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+
126160
@expose("/oauth-authorized/<provider>")
127161
def oauth_authorized(self, provider: str) -> WerkzeugResponse:
128162
response = super().oauth_authorized(provider)
129163

130164
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")
133167
return response
134168

135169
# https://superset.apache.org/docs/installation/configuring-superset/#custom-oauth2-configuration
@@ -193,7 +227,6 @@ def oauth_user_info(self, provider, response=None):
193227
'api_base_url':f'https://{AUTH0_DOMAIN}/oauth/',
194228
'access_token_url': f'https://{AUTH0_DOMAIN}/oauth/token',
195229
'authorize_url': f'https://{AUTH0_DOMAIN}/authorize'
196-
197230
}
198231
}]
199232

0 commit comments

Comments
 (0)