diff --git a/swh/web/admin/urls.py b/swh/web/admin/urls.py --- a/swh/web/admin/urls.py +++ b/swh/web/admin/urls.py @@ -7,10 +7,13 @@ from django.contrib.auth.views import LoginView from django.shortcuts import redirect -import swh.web.admin.add_forge_now # noqa from swh.web.admin.adminurls import AdminUrls import swh.web.admin.deposit # noqa import swh.web.admin.origin_save # noqa +from swh.web.config import is_feature_enabled + +if is_feature_enabled("add_forge_now"): + import swh.web.admin.add_forge_now # noqa def _admin_default_view(request): diff --git a/swh/web/common/utils.py b/swh/web/common/utils.py --- a/swh/web/common/utils.py +++ b/swh/web/common/utils.py @@ -315,6 +315,7 @@ "iframe_mode": False, "ADMIN_LIST_DEPOSIT_PERMISSION": ADMIN_LIST_DEPOSIT_PERMISSION, "ADD_FORGE_MODERATOR_PERMISSION": ADD_FORGE_MODERATOR_PERMISSION, + "FEATURES": get_config()["features"], } diff --git a/swh/web/config.py b/swh/web/config.py --- a/swh/web/config.py +++ b/swh/web/config.py @@ -127,6 +127,7 @@ "staging_server_names": ("list", SWH_WEB_STAGING_SERVER_NAMES), "instance_name": ("str", "archive-test.softwareheritage.org"), "give": ("dict", {"public_key": "", "token": ""}), + "features": ("dict", {"add_forge_now": False}), } swhweb_config: Dict[str, Any] = {} @@ -207,3 +208,11 @@ """ return get_config()["counters"] + + +def is_feature_enabled(feature_name: str) -> bool: + """Determine whether a feature is enabled or not. If feature_name is not found at all, + it's considered disabled. + + """ + return get_config()["features"].get(feature_name, False) diff --git a/swh/web/settings/tests.py b/swh/web/settings/tests.py --- a/swh/web/settings/tests.py +++ b/swh/web/settings/tests.py @@ -81,6 +81,7 @@ "server_url": "http://localhost:8080/auth/" if _pytest else "", "realm_name": "SoftwareHeritage", }, + "features": {"add_forge_now": True,}, } ) diff --git a/swh/web/templates/layout.html b/swh/web/templates/layout.html --- a/swh/web/templates/layout.html +++ b/swh/web/templates/layout.html @@ -209,12 +209,14 @@

Save code now

+ {% if FEATURES.add_forge_now %} + {% endif %} {% endif %} - {% if user.is_staff or ADD_FORGE_MODERATOR_PERMISSION in user.get_all_permissions %} + {% if FEATURES.add_forge_now %} + {% if user.is_staff or ADD_FORGE_MODERATOR_PERMISSION in user.get_all_permissions %} + {% endif %} {% endif %} {% if user.is_staff or ADMIN_LIST_DEPOSIT_PERMISSION in user.get_all_permissions %}