diff --git a/Makefile.local b/Makefile.local --- a/Makefile.local +++ b/Makefile.local @@ -27,10 +27,12 @@ .PHONY: run-migrations-dev run-migrations-dev: + python3 swh/web/manage.py rename_app --settings=$(SETTINGS_DEV) swh_web_common swh_web_save_code_now python3 swh/web/manage.py migrate --settings=$(SETTINGS_DEV) -v0 .PHONY: run-migrations-prod run-migrations-prod: + django-admin rename_app --settings=$(SETTINGS_PROD) swh_web_common swh_web_save_code_now django-admin migrate --settings=$(SETTINGS_PROD) -v0 .PHONY: run-migrations-test 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,7 +9,6 @@ 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"): 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 @@ -1,8 +1,9 @@ -# Copyright (C) 2017-2020 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 + from swh.web.api.apiurls import APIUrls import swh.web.api.views.add_forge_now # noqa import swh.web.api.views.content # noqa @@ -11,7 +12,6 @@ import swh.web.api.views.identifiers # noqa import swh.web.api.views.metadata # noqa import swh.web.api.views.origin # noqa -import swh.web.api.views.origin_save # noqa import swh.web.api.views.ping # noqa import swh.web.api.views.raw # noqa import swh.web.api.views.release # noqa diff --git a/swh/web/common/__init__.py b/swh/web/common/__init__.py --- a/swh/web/common/__init__.py +++ b/swh/web/common/__init__.py @@ -1,6 +0,0 @@ -# Copyright (C) 2018 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 - -default_app_config = "swh.web.common.apps.SwhWebCommonConfig" diff --git a/swh/web/common/swh_templatetags.py b/swh/web/common/swh_templatetags.py --- a/swh/web/common/swh_templatetags.py +++ b/swh/web/common/swh_templatetags.py @@ -10,8 +10,8 @@ from django.utils.safestring import mark_safe from swh.web.common.converters import SWHDjangoJSONEncoder -from swh.web.common.origin_save import get_savable_visit_types from swh.web.common.utils import rst_to_html +from swh.web.save_code_now.origin_save import get_savable_visit_types register = template.Library() diff --git a/swh/web/config.py b/swh/web/config.py --- a/swh/web/config.py +++ b/swh/web/config.py @@ -161,6 +161,7 @@ "swh.web.inbound_email", "swh.web.add_forge_now", "swh.web.mailmap", + "swh.web.save_code_now", ], ), } diff --git a/swh/web/misc/metrics.py b/swh/web/misc/metrics.py --- a/swh/web/misc/metrics.py +++ b/swh/web/misc/metrics.py @@ -7,8 +7,8 @@ from django.http import HttpResponse -from swh.web.common.origin_save import compute_save_requests_metrics from swh.web.common.utils import SWH_WEB_METRICS_REGISTRY +from swh.web.save_code_now.origin_save import compute_save_requests_metrics def prometheus_metrics(request): diff --git a/swh/web/misc/urls.py b/swh/web/misc/urls.py --- a/swh/web/misc/urls.py +++ b/swh/web/misc/urls.py @@ -63,7 +63,6 @@ urlpatterns = [ url(r"^", include("swh.web.misc.coverage")), url(r"^jslicenses/$", _jslicenses, name="jslicenses"), - url(r"^", include("swh.web.misc.origin_save")), url(r"^stat_counters/$", _stat_counters, name="stat-counters"), url(r"^", include("swh.web.misc.badges")), url(r"^metrics/prometheus/$", prometheus_metrics, name="metrics-prometheus"), diff --git a/swh/web/common/__init__.py b/swh/web/save_code_now/__init__.py copy from swh/web/common/__init__.py copy to swh/web/save_code_now/__init__.py --- a/swh/web/common/__init__.py +++ b/swh/web/save_code_now/__init__.py @@ -1,6 +1,6 @@ -# Copyright (C) 2018 The Software Heritage developers +# 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 -default_app_config = "swh.web.common.apps.SwhWebCommonConfig" +default_app_config = "swh.web.save_code_now.apps.SaveCodeNowConfig" diff --git a/swh/web/admin/origin_save.py b/swh/web/save_code_now/admin_views.py rename from swh/web/admin/origin_save.py rename to swh/web/save_code_now/admin_views.py --- a/swh/web/admin/origin_save.py +++ b/swh/web/save_code_now/admin_views.py @@ -1,4 +1,4 @@ -# Copyright (C) 2018-2019 The Software Heritage developers +# Copyright (C) 2018-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 @@ -13,29 +13,26 @@ from django.shortcuts import render from django.views.decorators.http import require_POST -from swh.web.admin.adminurls import admin_route -from swh.web.common.models import ( +from swh.web.save_code_now.models import ( SaveAuthorizedOrigin, SaveOriginRequest, SaveUnauthorizedOrigin, ) -from swh.web.common.origin_save import ( +from swh.web.save_code_now.origin_save import ( SAVE_REQUEST_PENDING, SAVE_REQUEST_REJECTED, create_save_origin_request, ) -@admin_route(r"origin/save/requests/", view_name="admin-origin-save-requests") @staff_member_required(view_func=None, login_url=settings.LOGIN_URL) -def _admin_origin_save_requests(request): - return render(request, "admin/origin-save/requests.html") +def admin_origin_save_requests(request): + return render(request, "admin/origin-save-requests.html") -@admin_route(r"origin/save/filters/", view_name="admin-origin-save-filters") @staff_member_required(view_func=None, login_url=settings.LOGIN_URL) -def _admin_origin_save_filters(request): - return render(request, "admin/origin-save/filters.html") +def admin_origin_save_filters(request): + return render(request, "admin/origin-save-filters.html") def _datatables_origin_urls_response(request, urls_query_set): @@ -63,23 +60,15 @@ return JsonResponse(table_data) -@admin_route( - r"origin/save/authorized_urls/list/", - view_name="admin-origin-save-authorized-urls-list", -) @staff_member_required(view_func=None, login_url=settings.LOGIN_URL) -def _admin_origin_save_authorized_urls_list(request): +def admin_origin_save_authorized_urls_list(request): authorized_urls = SaveAuthorizedOrigin.objects.all() return _datatables_origin_urls_response(request, authorized_urls) -@admin_route( - r"origin/save/authorized_urls/add/(?P.+)/", - view_name="admin-origin-save-add-authorized-url", -) @require_POST @staff_member_required(view_func=None, login_url=settings.LOGIN_URL) -def _admin_origin_save_add_authorized_url(request, origin_url): +def admin_origin_save_add_authorized_url(request, origin_url): try: SaveAuthorizedOrigin.objects.get(url=origin_url) except ObjectDoesNotExist: @@ -98,13 +87,9 @@ return HttpResponse(status=status_code) -@admin_route( - r"origin/save/authorized_urls/remove/(?P.+)/", - view_name="admin-origin-save-remove-authorized-url", -) @require_POST @staff_member_required(view_func=None, login_url=settings.LOGIN_URL) -def _admin_origin_save_remove_authorized_url(request, origin_url): +def admin_origin_save_remove_authorized_url(request, origin_url): try: entry = SaveAuthorizedOrigin.objects.get(url=origin_url) except ObjectDoesNotExist: @@ -115,23 +100,15 @@ return HttpResponse(status=status_code) -@admin_route( - r"origin/save/unauthorized_urls/list/", - view_name="admin-origin-save-unauthorized-urls-list", -) @staff_member_required(view_func=None, login_url=settings.LOGIN_URL) -def _admin_origin_save_unauthorized_urls_list(request): +def admin_origin_save_unauthorized_urls_list(request): unauthorized_urls = SaveUnauthorizedOrigin.objects.all() return _datatables_origin_urls_response(request, unauthorized_urls) -@admin_route( - r"origin/save/unauthorized_urls/add/(?P.+)/", - view_name="admin-origin-save-add-unauthorized-url", -) @require_POST @staff_member_required(view_func=None, login_url=settings.LOGIN_URL) -def _admin_origin_save_add_unauthorized_url(request, origin_url): +def admin_origin_save_add_unauthorized_url(request, origin_url): try: SaveUnauthorizedOrigin.objects.get(url=origin_url) except ObjectDoesNotExist: @@ -150,13 +127,9 @@ return HttpResponse(status=status_code) -@admin_route( - r"origin/save/unauthorized_urls/remove/(?P.+)/", - view_name="admin-origin-save-remove-unauthorized-url", -) @require_POST @staff_member_required(view_func=None, login_url=settings.LOGIN_URL) -def _admin_origin_save_remove_unauthorized_url(request, origin_url): +def admin_origin_save_remove_unauthorized_url(request, origin_url): try: entry = SaveUnauthorizedOrigin.objects.get(url=origin_url) except ObjectDoesNotExist: @@ -167,13 +140,9 @@ return HttpResponse(status=status_code) -@admin_route( - r"origin/save/request/accept/(?P.+)/url/(?P.+)/", - view_name="admin-origin-save-request-accept", -) @require_POST @staff_member_required(view_func=None, login_url=settings.LOGIN_URL) -def _admin_origin_save_request_accept(request, visit_type, origin_url): +def admin_origin_save_request_accept(request, visit_type, origin_url): try: SaveAuthorizedOrigin.objects.get(url=origin_url) except ObjectDoesNotExist: @@ -182,13 +151,9 @@ return HttpResponse(status=200) -@admin_route( - r"origin/save/request/reject/(?P.+)/url/(?P.+)/", - view_name="admin-origin-save-request-reject", -) @require_POST @staff_member_required(view_func=None, login_url=settings.LOGIN_URL) -def _admin_origin_save_request_reject(request, visit_type, origin_url): +def admin_origin_save_request_reject(request, visit_type, origin_url): try: sor = SaveOriginRequest.objects.get( visit_type=visit_type, origin_url=origin_url, status=SAVE_REQUEST_PENDING @@ -203,13 +168,9 @@ return HttpResponse(status=status_code) -@admin_route( - r"origin/save/request/remove/(?P.+)/", - view_name="admin-origin-save-request-remove", -) @require_POST @staff_member_required(view_func=None, login_url=settings.LOGIN_URL) -def _admin_origin_save_request_remove(request, sor_id): +def admin_origin_save_request_remove(request, sor_id): try: entry = SaveOriginRequest.objects.get(id=sor_id) except ObjectDoesNotExist: diff --git a/swh/web/api/views/origin_save.py b/swh/web/save_code_now/api_views.py rename from swh/web/api/views/origin_save.py rename to swh/web/save_code_now/api_views.py --- a/swh/web/api/views/origin_save.py +++ b/swh/web/save_code_now/api_views.py @@ -15,7 +15,7 @@ SWH_AMBASSADOR_PERMISSION, privileged_user, ) -from swh.web.common.origin_save import ( +from swh.web.save_code_now.origin_save import ( create_save_origin_request, get_savable_visit_types, get_save_origin_requests, diff --git a/swh/web/common/apps.py b/swh/web/save_code_now/apps.py rename from swh/web/common/apps.py rename to swh/web/save_code_now/apps.py --- a/swh/web/common/apps.py +++ b/swh/web/save_code_now/apps.py @@ -1,4 +1,4 @@ -# Copyright (C) 2018 The Software Heritage developers +# 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 @@ -6,6 +6,6 @@ from django.apps import AppConfig -class SwhWebCommonConfig(AppConfig): - name = "swh.web.common" - label = "swh_web_common" +class SaveCodeNowConfig(AppConfig): + name = "swh.web.save_code_now" + label = "swh_web_save_code_now" diff --git a/swh/web/common/management/__init__.py b/swh/web/save_code_now/management/__init__.py rename from swh/web/common/management/__init__.py rename to swh/web/save_code_now/management/__init__.py diff --git a/swh/web/common/management/commands/__init__.py b/swh/web/save_code_now/management/commands/__init__.py rename from swh/web/common/management/commands/__init__.py rename to swh/web/save_code_now/management/commands/__init__.py diff --git a/swh/web/common/management/commands/refresh_savecodenow_statuses.py b/swh/web/save_code_now/management/commands/refresh_savecodenow_statuses.py rename from swh/web/common/management/commands/refresh_savecodenow_statuses.py rename to swh/web/save_code_now/management/commands/refresh_savecodenow_statuses.py --- a/swh/web/common/management/commands/refresh_savecodenow_statuses.py +++ b/swh/web/save_code_now/management/commands/refresh_savecodenow_statuses.py @@ -8,10 +8,10 @@ from django.core.management.base import BaseCommand from swh.scheduler.model import ListedOrigin -from swh.web.common.models import VISIT_STATUS_FULL, VISIT_STATUS_PARTIAL -from swh.web.common.origin_save import refresh_save_origin_request_statuses from swh.web.config import get_config from swh.web.config import scheduler as get_scheduler +from swh.web.save_code_now.models import VISIT_STATUS_FULL, VISIT_STATUS_PARTIAL +from swh.web.save_code_now.origin_save import refresh_save_origin_request_statuses class Command(BaseCommand): diff --git a/swh/web/common/migrations/0001_initial.py b/swh/web/save_code_now/migrations/0001_initial.py rename from swh/web/common/migrations/0001_initial.py rename to swh/web/save_code_now/migrations/0001_initial.py --- a/swh/web/common/migrations/0001_initial.py +++ b/swh/web/save_code_now/migrations/0001_initial.py @@ -21,7 +21,9 @@ def _populate_save_authorized_origins(apps, schema_editor): - SaveAuthorizedOrigin = apps.get_model("swh_web_common", "SaveAuthorizedOrigin") + SaveAuthorizedOrigin = apps.get_model( + "swh_web_save_code_now", "SaveAuthorizedOrigin" + ) for origin_url in _authorized_origins: SaveAuthorizedOrigin.objects.create(url=origin_url) diff --git a/swh/web/common/migrations/0002_saveoriginrequest_visit_date.py b/swh/web/save_code_now/migrations/0002_saveoriginrequest_visit_date.py rename from swh/web/common/migrations/0002_saveoriginrequest_visit_date.py rename to swh/web/save_code_now/migrations/0002_saveoriginrequest_visit_date.py --- a/swh/web/common/migrations/0002_saveoriginrequest_visit_date.py +++ b/swh/web/save_code_now/migrations/0002_saveoriginrequest_visit_date.py @@ -11,7 +11,7 @@ class Migration(migrations.Migration): dependencies = [ - ("swh_web_common", "0001_initial"), + ("swh_web_save_code_now", "0001_initial"), ] operations = [ diff --git a/swh/web/common/migrations/0003_saveoriginrequest_loading_task_status.py b/swh/web/save_code_now/migrations/0003_saveoriginrequest_loading_task_status.py rename from swh/web/common/migrations/0003_saveoriginrequest_loading_task_status.py rename to swh/web/save_code_now/migrations/0003_saveoriginrequest_loading_task_status.py --- a/swh/web/common/migrations/0003_saveoriginrequest_loading_task_status.py +++ b/swh/web/save_code_now/migrations/0003_saveoriginrequest_loading_task_status.py @@ -18,7 +18,7 @@ So remove the rows associated to already archived tasks as the loading status can not be retrieved anymore. """ - SaveOriginRequest = apps.get_model("swh_web_common", "SaveOriginRequest") + SaveOriginRequest = apps.get_model("swh_web_save_code_now", "SaveOriginRequest") no_saved_status_tasks = [] for sor in SaveOriginRequest.objects.all(): tasks = scheduler().get_tasks([sor.loading_task_id]) @@ -30,7 +30,7 @@ class Migration(migrations.Migration): dependencies = [ - ("swh_web_common", "0002_saveoriginrequest_visit_date"), + ("swh_web_save_code_now", "0002_saveoriginrequest_visit_date"), ] operations = [ diff --git a/swh/web/common/migrations/0004_auto_20190204_1324.py b/swh/web/save_code_now/migrations/0004_auto_20190204_1324.py rename from swh/web/common/migrations/0004_auto_20190204_1324.py rename to swh/web/save_code_now/migrations/0004_auto_20190204_1324.py --- a/swh/web/common/migrations/0004_auto_20190204_1324.py +++ b/swh/web/save_code_now/migrations/0004_auto_20190204_1324.py @@ -11,7 +11,7 @@ class Migration(migrations.Migration): dependencies = [ - ("swh_web_common", "0003_saveoriginrequest_loading_task_status"), + ("swh_web_save_code_now", "0003_saveoriginrequest_loading_task_status"), ] operations = [ diff --git a/swh/web/common/migrations/0005_remove_duplicated_authorized_origins.py b/swh/web/save_code_now/migrations/0005_remove_duplicated_authorized_origins.py rename from swh/web/common/migrations/0005_remove_duplicated_authorized_origins.py rename to swh/web/save_code_now/migrations/0005_remove_duplicated_authorized_origins.py --- a/swh/web/common/migrations/0005_remove_duplicated_authorized_origins.py +++ b/swh/web/save_code_now/migrations/0005_remove_duplicated_authorized_origins.py @@ -7,7 +7,7 @@ from django.db import migrations -from swh.web.common.models import SaveAuthorizedOrigin +from swh.web.save_code_now.models import SaveAuthorizedOrigin def _remove_duplicated_urls_in_authorized_list(apps, schema_editor): @@ -19,7 +19,7 @@ class Migration(migrations.Migration): dependencies = [ - ("swh_web_common", "0004_auto_20190204_1324"), + ("swh_web_save_code_now", "0004_auto_20190204_1324"), ] operations = [migrations.RunPython(_remove_duplicated_urls_in_authorized_list)] diff --git a/swh/web/common/migrations/0006_rename_origin_type.py b/swh/web/save_code_now/migrations/0006_rename_origin_type.py rename from swh/web/common/migrations/0006_rename_origin_type.py rename to swh/web/save_code_now/migrations/0006_rename_origin_type.py --- a/swh/web/common/migrations/0006_rename_origin_type.py +++ b/swh/web/save_code_now/migrations/0006_rename_origin_type.py @@ -11,7 +11,7 @@ class Migration(migrations.Migration): dependencies = [ - ("swh_web_common", "0005_remove_duplicated_authorized_origins"), + ("swh_web_save_code_now", "0005_remove_duplicated_authorized_origins"), ] operations = [ diff --git a/swh/web/common/migrations/0007_save_request_task_status_fix_typo.py b/swh/web/save_code_now/migrations/0007_save_request_task_status_fix_typo.py rename from swh/web/common/migrations/0007_save_request_task_status_fix_typo.py rename to swh/web/save_code_now/migrations/0007_save_request_task_status_fix_typo.py --- a/swh/web/common/migrations/0007_save_request_task_status_fix_typo.py +++ b/swh/web/save_code_now/migrations/0007_save_request_task_status_fix_typo.py @@ -10,7 +10,7 @@ """ Fix a typo in save request status value. """ - SaveOriginRequest = apps.get_model("swh_web_common", "SaveOriginRequest") + SaveOriginRequest = apps.get_model("swh_web_save_code_now", "SaveOriginRequest") for sor in SaveOriginRequest.objects.all(): if sor.loading_task_status == "succeed": sor.loading_task_status = "succeeded" @@ -20,7 +20,7 @@ class Migration(migrations.Migration): dependencies = [ - ("swh_web_common", "0006_rename_origin_type"), + ("swh_web_save_code_now", "0006_rename_origin_type"), ] operations = [ diff --git a/swh/web/common/migrations/0008_save-code-now_indexes_20210106_1327.py b/swh/web/save_code_now/migrations/0008_save-code-now_indexes_20210106_1327.py rename from swh/web/common/migrations/0008_save-code-now_indexes_20210106_1327.py rename to swh/web/save_code_now/migrations/0008_save-code-now_indexes_20210106_1327.py --- a/swh/web/common/migrations/0008_save-code-now_indexes_20210106_1327.py +++ b/swh/web/save_code_now/migrations/0008_save-code-now_indexes_20210106_1327.py @@ -8,7 +8,7 @@ class Migration(migrations.Migration): dependencies = [ - ("swh_web_common", "0007_save_request_task_status_fix_typo"), + ("swh_web_save_code_now", "0007_save_request_task_status_fix_typo"), ] operations = [ diff --git a/swh/web/common/migrations/0009_saveoriginrequest_visit_status.py b/swh/web/save_code_now/migrations/0009_saveoriginrequest_visit_status.py rename from swh/web/common/migrations/0009_saveoriginrequest_visit_status.py rename to swh/web/save_code_now/migrations/0009_saveoriginrequest_visit_status.py --- a/swh/web/common/migrations/0009_saveoriginrequest_visit_status.py +++ b/swh/web/save_code_now/migrations/0009_saveoriginrequest_visit_status.py @@ -10,7 +10,7 @@ class Migration(migrations.Migration): dependencies = [ - ("swh_web_common", "0008_save-code-now_indexes_20210106_1327"), + ("swh_web_save_code_now", "0008_save-code-now_indexes_20210106_1327"), ] operations = [ diff --git a/swh/web/common/migrations/0010_saveoriginrequest_user_id.py b/swh/web/save_code_now/migrations/0010_saveoriginrequest_user_id.py rename from swh/web/common/migrations/0010_saveoriginrequest_user_id.py rename to swh/web/save_code_now/migrations/0010_saveoriginrequest_user_id.py --- a/swh/web/common/migrations/0010_saveoriginrequest_user_id.py +++ b/swh/web/save_code_now/migrations/0010_saveoriginrequest_user_id.py @@ -10,7 +10,7 @@ class Migration(migrations.Migration): dependencies = [ - ("swh_web_common", "0009_saveoriginrequest_visit_status"), + ("swh_web_save_code_now", "0009_saveoriginrequest_visit_status"), ] operations = [ diff --git a/swh/web/common/migrations/0011_saveoriginrequest_user_ids.py b/swh/web/save_code_now/migrations/0011_saveoriginrequest_user_ids.py rename from swh/web/common/migrations/0011_saveoriginrequest_user_ids.py rename to swh/web/save_code_now/migrations/0011_saveoriginrequest_user_ids.py --- a/swh/web/common/migrations/0011_saveoriginrequest_user_ids.py +++ b/swh/web/save_code_now/migrations/0011_saveoriginrequest_user_ids.py @@ -9,7 +9,7 @@ class Migration(migrations.Migration): dependencies = [ - ("swh_web_common", "0010_saveoriginrequest_user_id"), + ("swh_web_save_code_now", "0010_saveoriginrequest_user_id"), ] operations = [ diff --git a/swh/web/common/migrations/0012_saveoriginrequest_note.py b/swh/web/save_code_now/migrations/0012_saveoriginrequest_note.py rename from swh/web/common/migrations/0012_saveoriginrequest_note.py rename to swh/web/save_code_now/migrations/0012_saveoriginrequest_note.py --- a/swh/web/common/migrations/0012_saveoriginrequest_note.py +++ b/swh/web/save_code_now/migrations/0012_saveoriginrequest_note.py @@ -9,7 +9,7 @@ class Migration(migrations.Migration): dependencies = [ - ("swh_web_common", "0011_saveoriginrequest_user_ids"), + ("swh_web_save_code_now", "0011_saveoriginrequest_user_ids"), ] operations = [ diff --git a/swh/web/common/migrations/__init__.py b/swh/web/save_code_now/migrations/__init__.py rename from swh/web/common/migrations/__init__.py rename to swh/web/save_code_now/migrations/__init__.py diff --git a/swh/web/common/models.py b/swh/web/save_code_now/models.py rename from swh/web/common/models.py rename to swh/web/save_code_now/models.py --- a/swh/web/common/models.py +++ b/swh/web/save_code_now/models.py @@ -1,4 +1,4 @@ -# Copyright (C) 2018-2021 The Software Heritage developers +# Copyright (C) 2018-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 @@ -16,7 +16,7 @@ url = models.CharField(max_length=200, null=False) class Meta: - app_label = "swh_web_common" + app_label = "swh_web_save_code_now" db_table = "save_authorized_origin" indexes = [models.Index(fields=["url"])] @@ -33,7 +33,7 @@ url = models.CharField(max_length=200, null=False) class Meta: - app_label = "swh_web_common" + app_label = "swh_web_save_code_now" db_table = "save_unauthorized_origin" indexes = [models.Index(fields=["url"])] @@ -105,7 +105,7 @@ note = models.TextField(null=True) class Meta: - app_label = "swh_web_common" + app_label = "swh_web_save_code_now" db_table = "save_origin_request" ordering = ["-id"] indexes = [models.Index(fields=["origin_url", "status"])] diff --git a/swh/web/common/origin_save.py b/swh/web/save_code_now/origin_save.py rename from swh/web/common/origin_save.py rename to swh/web/save_code_now/origin_save.py --- a/swh/web/common/origin_save.py +++ b/swh/web/save_code_now/origin_save.py @@ -27,7 +27,10 @@ NotFoundExc, sentry_capture_exception, ) -from swh.web.common.models import ( +from swh.web.common.typing import OriginExistenceCheckInfo, SaveOriginRequestInfo +from swh.web.common.utils import SWH_WEB_METRICS_REGISTRY, parse_iso8601_date_to_utc +from swh.web.config import get_config, scheduler +from swh.web.save_code_now.models import ( SAVE_REQUEST_ACCEPTED, SAVE_REQUEST_PENDING, SAVE_REQUEST_REJECTED, @@ -43,9 +46,6 @@ SaveOriginRequest, SaveUnauthorizedOrigin, ) -from swh.web.common.typing import OriginExistenceCheckInfo, SaveOriginRequestInfo -from swh.web.common.utils import SWH_WEB_METRICS_REGISTRY, parse_iso8601_date_to_utc -from swh.web.config import get_config, scheduler logger = logging.getLogger(__name__) @@ -605,7 +605,7 @@ Returns: list: A list of save origin request info dicts as described in - :func:`swh.web.common.origin_save.create_save_origin_request` + :func:`swh.web.save_code_now.origin_save.create_save_origin_request` """ task_ids = [] @@ -681,7 +681,7 @@ Returns: list: A list of save origin requests dict as described in - :func:`swh.web.common.origin_save.create_save_origin_request` + :func:`swh.web.save_code_now.origin_save.create_save_origin_request` """ _check_visit_type_savable(visit_type) _check_origin_url_valid(origin_url) diff --git a/swh/web/templates/admin/origin-save/common.html b/swh/web/save_code_now/templates/admin/origin-save-common.html rename from swh/web/templates/admin/origin-save/common.html rename to swh/web/save_code_now/templates/admin/origin-save-common.html diff --git a/swh/web/templates/admin/origin-save/filters.html b/swh/web/save_code_now/templates/admin/origin-save-filters.html rename from swh/web/templates/admin/origin-save/filters.html rename to swh/web/save_code_now/templates/admin/origin-save-filters.html --- a/swh/web/templates/admin/origin-save/filters.html +++ b/swh/web/save_code_now/templates/admin/origin-save-filters.html @@ -1,4 +1,4 @@ -{% extends "./common.html" %} +{% extends "./origin-save-common.html" %} {% comment %} Copyright (C) 2018-2022 The Software Heritage developers diff --git a/swh/web/templates/admin/origin-save/requests.html b/swh/web/save_code_now/templates/admin/origin-save-requests.html rename from swh/web/templates/admin/origin-save/requests.html rename to swh/web/save_code_now/templates/admin/origin-save-requests.html --- a/swh/web/templates/admin/origin-save/requests.html +++ b/swh/web/save_code_now/templates/admin/origin-save-requests.html @@ -1,4 +1,4 @@ -{% extends "./common.html" %} +{% extends "./origin-save-common.html" %} {% comment %} Copyright (C) 2018-2022 The Software Heritage developers diff --git a/swh/web/templates/misc/origin-save-help.html b/swh/web/save_code_now/templates/origin-save-help.html rename from swh/web/templates/misc/origin-save-help.html rename to swh/web/save_code_now/templates/origin-save-help.html diff --git a/swh/web/templates/misc/origin-save-list.html b/swh/web/save_code_now/templates/origin-save-list.html rename from swh/web/templates/misc/origin-save-list.html rename to swh/web/save_code_now/templates/origin-save-list.html diff --git a/swh/web/templates/misc/origin-save.html b/swh/web/save_code_now/templates/origin-save.html rename from swh/web/templates/misc/origin-save.html rename to swh/web/save_code_now/templates/origin-save.html --- a/swh/web/templates/misc/origin-save.html +++ b/swh/web/save_code_now/templates/origin-save.html @@ -1,4 +1,4 @@ -{% extends "../layout.html" %} +{% extends "layout.html" %} {% comment %} Copyright (C) 2018-2021 The Software Heritage developers diff --git a/swh/web/save_code_now/urls.py b/swh/web/save_code_now/urls.py new file mode 100644 --- /dev/null +++ b/swh/web/save_code_now/urls.py @@ -0,0 +1,99 @@ +# 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.save_code_now.admin_views import ( + admin_origin_save_add_authorized_url, + admin_origin_save_add_unauthorized_url, + admin_origin_save_authorized_urls_list, + admin_origin_save_filters, + admin_origin_save_remove_authorized_url, + admin_origin_save_remove_unauthorized_url, + admin_origin_save_request_accept, + admin_origin_save_request_reject, + admin_origin_save_request_remove, + admin_origin_save_requests, + admin_origin_save_unauthorized_urls_list, +) + +# register Web API endpoints +import swh.web.save_code_now.api_views # noqa +from swh.web.save_code_now.views import ( + origin_save_help_view, + origin_save_list_view, + origin_save_requests_list, + save_origin_task_info, +) + +urlpatterns = [ + url(r"^save/$", origin_save_help_view, name="origin-save"), + url(r"^save/list/$", origin_save_list_view, name="origin-save-list"), + url( + r"^save/requests/list/(?P.+)/$", + origin_save_requests_list, + name="origin-save-requests-list", + ), + url( + r"^save/task/info/(?P.+)/$", + save_origin_task_info, + name="origin-save-task-info", + ), + url( + r"^admin/origin/save/requests/$", + admin_origin_save_requests, + name="admin-origin-save-requests", + ), + url( + r"^admin/origin/save/filters/$", + admin_origin_save_filters, + name="admin-origin-save-filters", + ), + url( + r"^admin/origin/save/authorized_urls/list/$", + admin_origin_save_authorized_urls_list, + name="admin-origin-save-authorized-urls-list", + ), + url( + r"^admin/origin/save/authorized_urls/add/(?P.+)/$", + admin_origin_save_add_authorized_url, + name="admin-origin-save-add-authorized-url", + ), + url( + r"^admin/origin/save/authorized_urls/remove/(?P.+)/$", + admin_origin_save_remove_authorized_url, + name="admin-origin-save-remove-authorized-url", + ), + url( + r"^admin/origin/save/unauthorized_urls/list/$", + admin_origin_save_unauthorized_urls_list, + name="admin-origin-save-unauthorized-urls-list", + ), + url( + r"^admin/origin/save/unauthorized_urls/add/(?P.+)/$", + admin_origin_save_add_unauthorized_url, + name="admin-origin-save-add-unauthorized-url", + ), + url( + r"^admin/origin/save/unauthorized_urls/remove/(?P.+)/$", + admin_origin_save_remove_unauthorized_url, + name="admin-origin-save-remove-unauthorized-url", + ), + url( + r"^admin/origin/save/request/accept/(?P.+)/url/(?P.+)/$", + admin_origin_save_request_accept, + name="admin-origin-save-request-accept", + ), + url( + r"^admin/origin/save/request/reject/(?P.+)/url/(?P.+)/$", + admin_origin_save_request_reject, + name="admin-origin-save-request-reject", + ), + url( + r"^admin/origin/save/request/remove/(?P.+)/$", + admin_origin_save_request_remove, + name="admin-origin-save-request-remove", + ), +] diff --git a/swh/web/misc/origin_save.py b/swh/web/save_code_now/views.py rename from swh/web/misc/origin_save.py rename to swh/web/save_code_now/views.py --- a/swh/web/misc/origin_save.py +++ b/swh/web/save_code_now/views.py @@ -3,24 +3,24 @@ # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information + from django.core.paginator import Paginator from django.db.models import Q from django.http import JsonResponse from django.shortcuts import render -from django.urls import re_path as url from swh.web.auth.utils import SWH_AMBASSADOR_PERMISSION, privileged_user -from swh.web.common.models import SaveOriginRequest -from swh.web.common.origin_save import ( +from swh.web.save_code_now.models import SaveOriginRequest +from swh.web.save_code_now.origin_save import ( get_savable_visit_types, get_save_origin_task_info, ) -def _origin_save_help_view(request): +def origin_save_help_view(request): return render( request, - "misc/origin-save-help.html", + "origin-save-help.html", { "heading": ("Request the saving of a software origin into the archive"), "visit_types": get_savable_visit_types( @@ -30,10 +30,10 @@ ) -def _origin_save_list_view(request): +def origin_save_list_view(request): return render( request, - "misc/origin-save-list.html", + "origin-save-list.html", { "heading": ("Request the saving of a software origin into the archive"), "visit_types": get_savable_visit_types( @@ -43,7 +43,7 @@ ) -def _origin_save_requests_list(request, status): +def origin_save_requests_list(request, status): if status != "all": save_requests = SaveOriginRequest.objects.filter(status=status) @@ -87,7 +87,7 @@ return JsonResponse(table_data) -def _save_origin_task_info(request, save_request_id): +def save_origin_task_info(request, save_request_id): request_info = get_save_origin_task_info( save_request_id, full_info=request.user.is_staff ) @@ -95,19 +95,3 @@ if date_field in request_info and request_info[date_field] is not None: request_info[date_field] = request_info[date_field].isoformat() return JsonResponse(request_info) - - -urlpatterns = [ - url(r"^save/$", _origin_save_help_view, name="origin-save"), - url(r"^save/list/$", _origin_save_list_view, name="origin-save-list"), - url( - r"^save/requests/list/(?P.+)/$", - _origin_save_requests_list, - name="origin-save-requests-list", - ), - url( - r"^save/task/info/(?P.+)/$", - _save_origin_task_info, - name="origin-save-task-info", - ), -] diff --git a/swh/web/settings/common.py b/swh/web/settings/common.py --- a/swh/web/settings/common.py +++ b/swh/web/settings/common.py @@ -58,6 +58,7 @@ # its URLS are registered SWH_DJANGO_APPS = SWH_EXTRA_DJANGO_APPS + SWH_BASE_DJANGO_APPS + INSTALLED_APPS = [ "django.contrib.admin", "django.contrib.auth", diff --git a/swh/web/templates/includes/top-navigation.html b/swh/web/templates/includes/top-navigation.html --- a/swh/web/templates/includes/top-navigation.html +++ b/swh/web/templates/includes/top-navigation.html @@ -128,7 +128,9 @@ {% if not snapshot_context or not snapshot_context.is_empty %} {% include "includes/vault-create-tasks.html" %} {% endif %} - {% include "includes/take-new-snapshot.html" %} + {% if "swh.web.save_code_now" in SWH_DJANGO_APPS %} + {% include "includes/take-new-snapshot.html" %} + {% endif %} {% include "includes/show-metadata.html" %} {% endif %} 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 @@ -201,12 +201,14 @@

Downloads

- + {% if "swh.web.save_code_now" in SWH_DJANGO_APPS %} + + {% endif %} {% if FEATURES.add_forge_now %} {% if user.is_authenticated %} - {% if user.is_staff %} + {% if "swh.web.save_code_now" in SWH_DJANGO_APPS and user.is_staff %}