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 @@ -8,7 +8,6 @@ from django.urls import re_path as url from swh.web.admin.adminurls import AdminUrls -import swh.web.admin.deposit # noqa def _admin_default_view(request): diff --git a/swh/web/common/urlsindex.py b/swh/web/common/urlsindex.py --- a/swh/web/common/urlsindex.py +++ b/swh/web/common/urlsindex.py @@ -3,6 +3,7 @@ # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information +from collections import defaultdict from typing import Dict, List from django.shortcuts import redirect @@ -10,7 +11,7 @@ from django.urls import re_path as url -class UrlsIndex(object): +class UrlsIndex: """ Simple helper class for centralizing url patterns of a Django web application. @@ -19,7 +20,7 @@ all declared patterns will be grouped under the default one. """ - _urlpatterns: Dict[str, List[URLPattern]] = {} + _urlpatterns: Dict[str, List[URLPattern]] = defaultdict(list) scope = "default" @classmethod diff --git a/swh/web/config.py b/swh/web/config.py --- a/swh/web/config.py +++ b/swh/web/config.py @@ -162,6 +162,7 @@ "swh.web.add_forge_now", "swh.web.mailmap", "swh.web.save_code_now", + "swh.web.deposit", ], ), } diff --git a/swh/web/deposit/__init__.py b/swh/web/deposit/__init__.py new file mode 100644 diff --git a/swh/web/templates/admin/deposit.html b/swh/web/deposit/templates/deposit-admin.html rename from swh/web/templates/admin/deposit.html rename to swh/web/deposit/templates/deposit-admin.html diff --git a/swh/web/admin/deposit.py b/swh/web/deposit/urls.py rename from swh/web/admin/deposit.py rename to swh/web/deposit/urls.py --- a/swh/web/admin/deposit.py +++ b/swh/web/deposit/urls.py @@ -11,25 +11,23 @@ from django.contrib.auth.decorators import user_passes_test from django.http import JsonResponse from django.shortcuts import render +from django.urls import re_path as url -from swh.web.admin.adminurls import admin_route from swh.web.auth.utils import ADMIN_LIST_DEPOSIT_PERMISSION from swh.web.config import get_config -def _can_list_deposits(user): +def can_list_deposits(user): return user.is_staff or user.has_perm(ADMIN_LIST_DEPOSIT_PERMISSION) -@admin_route(r"deposit/", view_name="admin-deposit") -@user_passes_test(_can_list_deposits, login_url=settings.LOGIN_URL) -def _admin_origin_save(request): - return render(request, "admin/deposit.html") +@user_passes_test(can_list_deposits, login_url=settings.LOGIN_URL) +def admin_deposit(request): + return render(request, "deposit-admin.html") -@admin_route(r"deposit/list/", view_name="admin-deposit-list") -@user_passes_test(_can_list_deposits, login_url=settings.LOGIN_URL) -def _admin_deposit_list(request): +@user_passes_test(can_list_deposits, login_url=settings.LOGIN_URL) +def admin_deposit_list(request): config = get_config()["deposit"] private_api_url = config["private_api_url"].rstrip("/") + "/" deposits_list_url = private_api_url + "deposits/datatables/" @@ -42,3 +40,9 @@ ).json() return JsonResponse(deposits) + + +urlpatterns = [ + url(r"^admin/deposit/$", admin_deposit, name="admin-deposit"), + url(r"^admin/deposit/list/$", admin_deposit_list, name="admin-deposit-list"), +] 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 @@ -243,7 +243,7 @@ {% endif %} {% endif %} - {% if user.is_staff or ADMIN_LIST_DEPOSIT_PERMISSION in user.get_all_permissions %} + {% if "swh.web.deposit" in SWH_DJANGO_APPS and user.is_staff or ADMIN_LIST_DEPOSIT_PERMISSION in user.get_all_permissions %}