Skip to content

Commit

Permalink
Merge pull request #11178 from camptocamp/detect-admin
Browse files Browse the repository at this point in the history
Disable admin interface it he is not installed
  • Loading branch information
sbrunner authored Jun 21, 2024
2 parents b7ce426 + 13dca9b commit 1d97069
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions geoportal/c2cgeoportal_geoportal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,14 @@ def add_admin_interface(config: pyramid.config.Configurator) -> None:

assert c2cgeoportal_commons.models.DBSession is not None

if config.get_settings().get("enable_admin_interface", False):
config.add_request_method(
lambda request: c2cgeoportal_commons.models.DBSession(),
"dbsession",
reify=True,
)
config.add_view(c2cgeoportal_geoportal.views.add_ending_slash, route_name="admin_add_ending_slash")
config.add_route("admin_add_ending_slash", "/admin", request_method="GET")
config.include("c2cgeoportal_admin")
config.add_request_method(
lambda request: c2cgeoportal_commons.models.DBSession(),
"dbsession",
reify=True,
)
config.add_view(c2cgeoportal_geoportal.views.add_ending_slash, route_name="admin_add_ending_slash")
config.add_route("admin_add_ending_slash", "/admin", request_method="GET")
config.include("c2cgeoportal_admin")


def add_getitfixed(config: pyramid.config.Configurator) -> None:
Expand Down Expand Up @@ -721,7 +720,17 @@ def add_static_route(name: str, attr: str, path: str, renderer: str) -> None:
]
)

add_admin_interface(config)
admin_interface = (
config.get_settings().get("enable_admin_interface", False)
and importlib.util.find_spec("c2cgeoportal_admin") is not None
)
if admin_interface:
add_admin_interface(config)
else:
if not config.get_settings().get("enable_admin_interface", False):
LOG.info("Admin interface disabled by configuration")
else:
LOG.info("Admin interface disabled because c2cgeoportal_admin is not installed")
add_getitfixed(config)

# Add the project static view with cache buster
Expand Down Expand Up @@ -770,7 +779,7 @@ def add_static_route(name: str, attr: str, path: str, renderer: str) -> None:
'<a href="../memory">Memory status</a><br>',
]
)
if config.get_settings().get("enable_admin_interface", False):
if admin_interface:
c2cwsgiutils.index.additional_noauth.append('<a href="../admin/">Admin</a><br>')

c2cwsgiutils.index.additional_noauth.append(
Expand Down

0 comments on commit 1d97069

Please sign in to comment.