Skip to content

Commit

Permalink
Configurable header
Browse files Browse the repository at this point in the history
Insert the logic for georchestra/superset-core#46
In geOrchestra, the header (top menu) is controlled by params rom the
default.properties file. This commit provides a means to parse this file
and get a header that is consistent with geOrchestra's other apps.
It is also possible to disable the header's display by setting
GEORCHESTRA_NOHEADER=True in the superset config file
  • Loading branch information
jeanpommier committed Feb 19, 2025
1 parent 6fe0baf commit beadf0d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
56 changes: 56 additions & 0 deletions config/superset/GeorchestraCustomizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from flask_appbuilder._compat import as_unicode
from flask_login import login_user, logout_user

from configparser import ConfigParser
from itertools import chain
import logging

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -153,6 +155,52 @@ def before_request(self):
logger.debug("Logged in as anonymous user")


class GeorchestraDatadirLoader(object):
def __init__(self, app):
self.sections = None
self.app = app
self.properties_file_path = app.config.get("GEORCHESTRA_PROPERTIES_FILE_PATH", "")
self.noheader = app.config.get("GEORCHESTRA_NOHEADER", False)

def init_app(self) -> None:
"""
Load the geOrchestra configuration (datadir/default.properties)
into the Flask app context
:return:
"""
if self.app:
self.app.context_processor(self.get_georchestra_default_properties)


def get_georchestra_default_properties(self):
self.sections = dict()
if self.properties_file_path:
parser = ConfigParser()
with open(self.properties_file_path) as lines:
# ConfigParser complains about missing sections in the file. This line does the trick:
lines = chain(("[section]",), lines)
parser.read_file(lines)
self.sections['default'] = parser['section']
return { "georchestra":
{
'headerScript': self.get('headerScript'),
'headerHeight': self.get('headerHeight'),
'headerUrl': self.get('headerUrl'),
'headerConfigFile': self.get('headerConfigFile'),
'useLegacyHeader': self.get('useLegacyHeader'),
'georchestraStyleSheet': self.get('georchestraStyleSheet'),
'logoUrl': self.get('logoUrl'),
'noheader': self.noheader,
}
}

def get(self, key, section='default'):
if section in self.sections:
return self.sections[section].get(key, None)
else:
return None


# Redefine home page (Superset default is /superset/welcome)
# You can either define a path (including the potential prefix)
# or a view name
Expand All @@ -171,10 +219,18 @@ def index(self) -> FlaskResponse:

from superset.app import SupersetAppInitializer
def app_init(app):
# Activate the geOrchestra REMOTE_USER logic
logger.info("REMOTE_USER Registering RemoteUserLogin")
app.before_request(RemoteUserLogin(app).before_request)

# Set the home page
app.config['FAB_INDEX_VIEW'] = f"{SupersetIndexView.__module__}.{SupersetIndexView.__name__}"

# Read default.properties file from geOrchestra datadir
# Used to configure the geOrchestra header (unless superset's config has GEORCHESTRA_NOHEADER=True in that case,
# no header will be shown)
GeorchestraDatadirLoader(app).init_app()

return SupersetAppInitializer(app)

logger.info(f"Using custom REMOTE_USER logic")
Expand Down
2 changes: 2 additions & 0 deletions config/superset/superset_georchestra_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
APP_INITIALIZER = app_init
# GEORCHESTRA_ORG_AS_ROLE=False
GEORCHESTRA_ROLES_PREFIX = "ROLE_SUPERSET_"
GEORCHESTRA_PROPERTIES_FILE_PATH="/etc/georchestra/default.properties"
GEORCHESTRA_NOHEADER=False
PUBLIC_ROLE_LIKE = "Gamma"
AUTH_USER_REGISTRATION_ROLE = "Public"
LOGOUT_REDIRECT_URL="/logout"
Expand Down

0 comments on commit beadf0d

Please sign in to comment.