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 %}
Add forge now
+ {% endif %}
@@ -231,13 +233,15 @@
{% 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 %}
Add forge now
+ {% endif %}
{% endif %}
{% if user.is_staff or ADMIN_LIST_DEPOSIT_PERMISSION in user.get_all_permissions %}
diff --git a/swh/web/tests/test_config.py b/swh/web/tests/test_config.py
new file mode 100644
--- /dev/null
+++ b/swh/web/tests/test_config.py
@@ -0,0 +1,23 @@
+# Copyright (C) 2022 The Software Heritage developers
+# See the AUTHORS file at the top-level directory of this distribution
+# License: GNU General Public License version 3, or any later version
+# See top-level LICENSE file for more information
+
+import pytest
+
+from swh.web.config import get_config, is_feature_enabled
+
+
+@pytest.mark.parametrize(
+ "feature_name", ["inexistant-feature", "awesome-stuff"],
+)
+def test_is_feature_enabled(feature_name):
+ config = get_config()
+ # by default, feature non configured are considered disabled
+ assert is_feature_enabled(feature_name) is False
+
+ for enabled in [True, False]:
+ # Let's configure the feature
+ config["features"] = {feature_name: enabled}
+ # and check its configuration is properly read
+ assert is_feature_enabled(feature_name) is enabled
diff --git a/swh/web/urls.py b/swh/web/urls.py
--- a/swh/web/urls.py
+++ b/swh/web/urls.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2017-2021 The Software Heritage developers
+# Copyright (C) 2017-2022 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -28,7 +28,7 @@
swh_handle500,
)
from swh.web.common.utils import origin_visit_types
-from swh.web.config import get_config
+from swh.web.config import get_config, is_feature_enabled
swh_web_config = get_config()
@@ -60,11 +60,13 @@
name="browse-swhid",
),
url(r"^", include("swh.web.misc.urls")),
- url(r"^", include("swh.web.add_forge_now.views")),
url(r"^", include("swh.web.auth.views")),
url(r"^logout/$", LogoutView.as_view(template_name="logout.html"), name="logout"),
]
+if is_feature_enabled("add_forge_now"):
+ urlpatterns += (url(r"^", include("swh.web.add_forge_now.views")),)
+
# allow to serve assets through django staticfiles
# even if settings.DEBUG is False