Skip to content
Snippets Groups Projects
Verified Commit d7bb4cb6 authored by Antoine R. Dumont's avatar Antoine R. Dumont
Browse files

Add feature flag to toggle on/off add-forge-now feature

This also prevents the server code from being served when the feature flag is off.

Related to T4040
parent a3adf134
No related branches found
No related tags found
No related merge requests found
......@@ -7,10 +7,13 @@ from django.conf.urls import url
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):
......
......@@ -315,6 +315,7 @@ def context_processor(request):
"iframe_mode": False,
"ADMIN_LIST_DEPOSIT_PERMISSION": ADMIN_LIST_DEPOSIT_PERMISSION,
"ADD_FORGE_MODERATOR_PERMISSION": ADD_FORGE_MODERATOR_PERMISSION,
"FEATURES": get_config()["features"],
}
......
......@@ -127,6 +127,7 @@ DEFAULT_CONFIG = {
"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 @@ def counters():
"""
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)
......@@ -81,6 +81,7 @@ swh_web_config.update(
"server_url": "http://localhost:8080/auth/" if _pytest else "",
"realm_name": "SoftwareHeritage",
},
"features": {"add_forge_now": True,},
}
)
......
......@@ -209,12 +209,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
<p>Save code now</p>
</a>
</li>
{% if FEATURES.add_forge_now %}
<li class="nav-item swh-origin-save-item" title="Request adding a new forge listing">
<a href="{% url 'forge-add' %}" class="nav-link swh-forge-add-link">
<i style="color: #e20026;" class="nav-icon mdi mdi-24px mdi-anvil"></i>
<p>Add forge now</p>
</a>
</li>
{% endif %}
<li class="nav-item swh-help-item" title="How to browse the archive ?">
<a href="#" class="nav-link swh-help-link" onclick="swh.guided_tour.guidedTourButtonClick(event)">
<i style="color: #e20026;" class="nav-icon mdi mdi-24px mdi-help-circle"></i>
......@@ -231,13 +233,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
</a>
</li>
{% 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 %}
<li class="nav-item swh-forge-add-moderation-item" title="Add forge now moderation">
<a href="{% url 'add-forge-now-requests-moderation' %}" class="nav-link swh-forge-add-moderation-link">
<i style="color: #fecd1b;" class="nav-icon mdi mdi-24px mdi-anvil"></i>
<p>Add forge now</p>
</a>
</li>
{% endif %}
{% endif %}
{% if user.is_staff or ADMIN_LIST_DEPOSIT_PERMISSION in user.get_all_permissions %}
<li class="nav-item swh-deposit-admin-item" title="Deposit administration">
......
# 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
# 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 @@ from swh.web.common.exc import (
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 @@ urlpatterns = [
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment