diff --git a/swh/web/admin/add_forge_now.py b/swh/web/add_forge_now/admin_views.py rename from swh/web/admin/add_forge_now.py rename to swh/web/add_forge_now/admin_views.py --- a/swh/web/admin/add_forge_now.py +++ b/swh/web/add_forge_now/admin_views.py @@ -8,28 +8,19 @@ from django.shortcuts import render from swh.web.add_forge_now.models import RequestStatus -from swh.web.admin.adminurls import admin_route from swh.web.auth.utils import is_add_forge_now_moderator -@admin_route( - r"add-forge/requests/", - view_name="add-forge-now-requests-moderation", -) @user_passes_test(is_add_forge_now_moderator, login_url=settings.LOGIN_URL) def add_forge_now_requests_moderation_dashboard(request): """Moderation dashboard to allow listing current requests.""" return render( request, - "add_forge_now/requests-moderation.html", + "add-forge-requests-moderation.html", {"heading": "Add forge now requests moderation"}, ) -@admin_route( - r"add-forge/request/(?P<request_id>(\d)+)/", - view_name="add-forge-now-request-dashboard", -) @user_passes_test(is_add_forge_now_moderator, login_url=settings.LOGIN_URL) def add_forge_now_request_dashboard(request, request_id): """Moderation dashboard to allow listing current requests.""" diff --git a/swh/web/api/views/add_forge_now.py b/swh/web/add_forge_now/api_views.py rename from swh/web/api/views/add_forge_now.py rename to swh/web/add_forge_now/api_views.py diff --git a/swh/web/templates/add_forge_now/common.html b/swh/web/add_forge_now/templates/add-forge-common.html rename from swh/web/templates/add_forge_now/common.html rename to swh/web/add_forge_now/templates/add-forge-common.html --- a/swh/web/templates/add_forge_now/common.html +++ b/swh/web/add_forge_now/templates/add-forge-common.html @@ -1,4 +1,4 @@ -{% extends "../layout.html" %} +{% extends "layout.html" %} {% comment %} Copyright (C) 2022 The Software Heritage developers diff --git a/swh/web/templates/add_forge_now/creation_form.html b/swh/web/add_forge_now/templates/add-forge-creation-form.html rename from swh/web/templates/add_forge_now/creation_form.html rename to swh/web/add_forge_now/templates/add-forge-creation-form.html --- a/swh/web/templates/add_forge_now/creation_form.html +++ b/swh/web/add_forge_now/templates/add-forge-creation-form.html @@ -1,4 +1,4 @@ -{% extends "./common.html" %} +{% extends "./add-forge-common.html" %} {% comment %} Copyright (C) 2022 The Software Heritage developers diff --git a/swh/web/templates/add_forge_now/help.html b/swh/web/add_forge_now/templates/add-forge-help.html rename from swh/web/templates/add_forge_now/help.html rename to swh/web/add_forge_now/templates/add-forge-help.html --- a/swh/web/templates/add_forge_now/help.html +++ b/swh/web/add_forge_now/templates/add-forge-help.html @@ -1,4 +1,4 @@ -{% extends "./common.html" %} +{% extends "./add-forge-common.html" %} {% comment %} Copyright (C) 2022 The Software Heritage developers diff --git a/swh/web/templates/add_forge_now/list.html b/swh/web/add_forge_now/templates/add-forge-list.html rename from swh/web/templates/add_forge_now/list.html rename to swh/web/add_forge_now/templates/add-forge-list.html --- a/swh/web/templates/add_forge_now/list.html +++ b/swh/web/add_forge_now/templates/add-forge-list.html @@ -1,4 +1,4 @@ -{% extends "./common.html" %} +{% extends "./add-forge-common.html" %} {% comment %} Copyright (C) 2022 The Software Heritage developers diff --git a/swh/web/templates/add_forge_now/request-dashboard.html b/swh/web/add_forge_now/templates/add-forge-request-dashboard.html rename from swh/web/templates/add_forge_now/request-dashboard.html rename to swh/web/add_forge_now/templates/add-forge-request-dashboard.html --- a/swh/web/templates/add_forge_now/request-dashboard.html +++ b/swh/web/add_forge_now/templates/add-forge-request-dashboard.html @@ -1,4 +1,4 @@ -{% extends "../layout.html" %} +{% extends "layout.html" %} {% comment %} Copyright (C) 2022 The Software Heritage developers diff --git a/swh/web/templates/add_forge_now/requests-moderation.html b/swh/web/add_forge_now/templates/add-forge-requests-moderation.html rename from swh/web/templates/add_forge_now/requests-moderation.html rename to swh/web/add_forge_now/templates/add-forge-requests-moderation.html --- a/swh/web/templates/add_forge_now/requests-moderation.html +++ b/swh/web/add_forge_now/templates/add-forge-requests-moderation.html @@ -1,4 +1,4 @@ -{% extends "../layout.html" %} +{% extends "layout.html" %} {% comment %} Copyright (C) 2022 The Software Heritage developers diff --git a/swh/web/add_forge_now/urls.py b/swh/web/add_forge_now/urls.py new file mode 100644 --- /dev/null +++ b/swh/web/add_forge_now/urls.py @@ -0,0 +1,47 @@ +# Copyright (C) 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 + +from django.urls import re_path as url + +from swh.web.add_forge_now.admin_views import ( + add_forge_now_request_dashboard, + add_forge_now_requests_moderation_dashboard, +) + +# register Web API endpoints +import swh.web.add_forge_now.api_views # noqa +from swh.web.add_forge_now.views import ( + add_forge_request_list_datatables, + create_request_create, + create_request_help, + create_request_list, + create_request_message_source, +) + +urlpatterns = [ + url( + r"^add-forge/request/list/datatables/$", + add_forge_request_list_datatables, + name="add-forge-request-list-datatables", + ), + url(r"^add-forge/request/create/$", create_request_create, name="forge-add-create"), + url(r"^add-forge/request/list/$", create_request_list, name="forge-add-list"), + url( + r"^add-forge/request/message-source/(?P<id>\d+)/$", + create_request_message_source, + name="forge-add-message-source", + ), + url(r"^add-forge/request/help/$", create_request_help, name="forge-add-help"), + url( + r"^admin/add-forge/requests/$", + add_forge_now_requests_moderation_dashboard, + name="add-forge-now-requests-moderation", + ), + url( + r"^admin/add-forge/request/(?P<request_id>(\d)+)/$", + add_forge_now_request_dashboard, + name="add-forge-now-request-dashboard", + ), +] diff --git a/swh/web/add_forge_now/views.py b/swh/web/add_forge_now/views.py --- a/swh/web/add_forge_now/views.py +++ b/swh/web/add_forge_now/views.py @@ -12,14 +12,13 @@ from django.http.request import HttpRequest from django.http.response import HttpResponse, JsonResponse from django.shortcuts import render -from django.urls import re_path as url -from swh.web.add_forge_now.models import Request as AddForgeRequest -from swh.web.add_forge_now.models import RequestHistory -from swh.web.api.views.add_forge_now import ( +from swh.web.add_forge_now.api_views import ( AddForgeNowRequestPublicSerializer, AddForgeNowRequestSerializer, ) +from swh.web.add_forge_now.models import Request as AddForgeRequest +from swh.web.add_forge_now.models import RequestHistory from swh.web.auth.utils import is_add_forge_now_moderator @@ -94,7 +93,7 @@ return render( request, - "add_forge_now/creation_form.html", + "add-forge-creation-form.html", {"forge_types": FORGE_TYPES}, ) @@ -104,7 +103,7 @@ return render( request, - "add_forge_now/list.html", + "add-forge-list.html", ) @@ -113,7 +112,7 @@ return render( request, - "add_forge_now/help.html", + "add-forge-help.html", ) @@ -141,20 +140,3 @@ response["Content-Disposition"] = f'attachment; filename="{filename}"' return response - - -urlpatterns = [ - url( - r"^add-forge/request/list/datatables/$", - add_forge_request_list_datatables, - name="add-forge-request-list-datatables", - ), - url(r"^add-forge/request/create/$", create_request_create, name="forge-add-create"), - url(r"^add-forge/request/list/$", create_request_list, name="forge-add-list"), - url( - r"^add-forge/request/message-source/(?P<id>\d+)/$", - create_request_message_source, - name="forge-add-message-source", - ), - url(r"^add-forge/request/help/$", create_request_help, name="forge-add-help"), -] 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 @@ -9,10 +9,6 @@ from swh.web.admin.adminurls import AdminUrls import swh.web.admin.deposit # 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/api/urls.py b/swh/web/api/urls.py --- a/swh/web/api/urls.py +++ b/swh/web/api/urls.py @@ -5,7 +5,6 @@ from swh.web.api.apiurls import APIUrls -import swh.web.api.views.add_forge_now # noqa import swh.web.api.views.content # noqa import swh.web.api.views.directory # noqa import swh.web.api.views.graph # noqa 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 @@ -318,7 +318,6 @@ "iframe_mode": False, "ADMIN_LIST_DEPOSIT_PERMISSION": ADMIN_LIST_DEPOSIT_PERMISSION, "ADD_FORGE_MODERATOR_PERMISSION": ADD_FORGE_MODERATOR_PERMISSION, - "FEATURES": get_config()["features"], "MAILMAP_ADMIN_PERMISSION": MAILMAP_ADMIN_PERMISSION, "lang": "en", "sidebar_state": request.COOKIES.get("sidebar-state", "expanded"), diff --git a/swh/web/config.py b/swh/web/config.py --- a/swh/web/config.py +++ b/swh/web/config.py @@ -232,11 +232,3 @@ def counters(): """Return the current application's 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) 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,7 +209,7 @@ </a> </li> {% endif %} - {% if FEATURES.add_forge_now %} + {% if "swh.web.add_forge_now" in SWH_DJANGO_APPS %} <li class="nav-item swh-add-forge-now-item" title="Request adding a new forge listing"> <a href="{% url 'forge-add-create' %}" class="nav-link swh-add-forge-now-link"> <i style="color: #e20026;" class="nav-icon mdi mdi-24px mdi-anvil"></i> @@ -233,7 +233,7 @@ </a> </li> {% endif %} - {% if FEATURES.add_forge_now %} + {% if "swh.web.add_forge_now" in SWH_DJANGO_APPS %} {% if user.is_staff or ADD_FORGE_MODERATOR_PERMISSION in user.get_all_permissions %} <li class="nav-item swh-add-forge-now-moderation-item" title="Add forge now moderation"> <a href="{% url 'add-forge-now-requests-moderation' %}" class="nav-link swh-add-forge-now-moderation-link"> diff --git a/swh/web/tests/add_forge_now/__init__.py b/swh/web/tests/add_forge_now/__init__.py new file mode 100644 diff --git a/swh/web/tests/api/views/test_add_forge_now.py b/swh/web/tests/add_forge_now/test_api_views.py rename from swh/web/tests/api/views/test_add_forge_now.py rename to swh/web/tests/add_forge_now/test_api_views.py --- a/swh/web/tests/api/views/test_add_forge_now.py +++ b/swh/web/tests/add_forge_now/test_api_views.py @@ -316,7 +316,7 @@ ): _block_while_testing = mocker.patch( - "swh.web.api.views.add_forge_now._block_while_testing" + "swh.web.add_forge_now.api_views._block_while_testing" ) _block_while_testing.side_effect = lambda: time.sleep(1) diff --git a/swh/web/tests/add_forge_now/test_app.py b/swh/web/tests/add_forge_now/test_app.py new file mode 100644 --- /dev/null +++ b/swh/web/tests/add_forge_now/test_app.py @@ -0,0 +1,33 @@ +# Copyright (C) 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 + +import pytest + +from django.urls import get_resolver + +from swh.web.add_forge_now.urls import urlpatterns +from swh.web.common.utils import reverse +from swh.web.tests.django_asserts import assert_not_contains +from swh.web.tests.utils import check_html_get_response + + +@pytest.mark.django_db +def test_add_forge_now_deactivate(client, staff_user, django_settings): + """Check Add forge now feature is deactivated when the swh.web.add_forge_now django + application is not in installed apps.""" + + django_settings.SWH_DJANGO_APPS = [ + app for app in django_settings.SWH_DJANGO_APPS if app != "swh.web.add_forge_now" + ] + + url = reverse("swh-web-homepage") + client.force_login(staff_user) + resp = check_html_get_response(client, url, status_code=200) + assert_not_contains(resp, "swh-add-forge-now-item") + assert_not_contains(resp, "swh-add-forge-now-moderation-item") + + add_forge_now_view_names = set(urlpattern.name for urlpattern in urlpatterns) + all_view_names = set(get_resolver().reverse_dict.keys()) + assert add_forge_now_view_names & all_view_names == set() diff --git a/swh/web/tests/add_forge_now/test_views.py b/swh/web/tests/add_forge_now/test_views.py --- a/swh/web/tests/add_forge_now/test_views.py +++ b/swh/web/tests/add_forge_now/test_views.py @@ -8,9 +8,10 @@ import pytest from swh.web.common.utils import reverse -from swh.web.tests.api.views.test_add_forge_now import create_add_forge_request from swh.web.tests.utils import check_http_get_response +from .test_api_views import create_add_forge_request + NB_FORGE_TYPE = 2 NB_FORGES_PER_TYPE = 20 diff --git a/swh/web/tests/test_config.py b/swh/web/tests/test_config.py deleted file mode 100644 --- a/swh/web/tests/test_config.py +++ /dev/null @@ -1,24 +0,0 @@ -# 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 @@ -23,7 +23,7 @@ swh_handle500, ) from swh.web.common.utils import origin_visit_types -from swh.web.config import get_config, is_feature_enabled +from swh.web.config import get_config swh_web_config = get_config() @@ -67,9 +67,6 @@ except ModuleNotFoundError: assert False, f"Django application {app} not found !" -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