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 @@ -33,7 +33,7 @@ ) from swh.web.common.exc import BadInputExc from swh.web.common.typing import QueryParameters -from swh.web.config import SWH_WEB_SERVER_NAME, get_config, search +from swh.web.config import SWH_WEB_SERVER_NAME, get_config, is_feature_enabled, search SWH_WEB_METRICS_REGISTRY = CollectorRegistry(auto_describe=True) @@ -315,6 +315,7 @@ "iframe_mode": False, "ADMIN_LIST_DEPOSIT_PERMISSION": ADMIN_LIST_DEPOSIT_PERMISSION, "ADD_FORGE_MODERATOR_PERMISSION": ADD_FORGE_MODERATOR_PERMISSION, + "addforgenow_enabled": is_feature_enabled("add-forge-now"), } 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 addforgenow_enabled %}Add forge now
Add forge now