From b70e5ef63ed92050e53f8424cde319f194d35c37 Mon Sep 17 00:00:00 2001 From: Vitali Yanushchyk Date: Tue, 12 Nov 2024 05:47:52 -0300 Subject: [PATCH] del ! rerun duplicate finding in case ERROR state in admin Deduplication sets -> change --- .../apps/api/admin/deduplicationset.py | 23 +------------------ src/hope_dedup_engine/utils/security.py | 14 ----------- .../api/deduplicationset/change_form.html | 8 ------- 3 files changed, 1 insertion(+), 44 deletions(-) delete mode 100644 src/hope_dedup_engine/web/templates/admin/api/deduplicationset/change_form.html diff --git a/src/hope_dedup_engine/apps/api/admin/deduplicationset.py b/src/hope_dedup_engine/apps/api/admin/deduplicationset.py index a902dae6..c41ffbd6 100644 --- a/src/hope_dedup_engine/apps/api/admin/deduplicationset.py +++ b/src/hope_dedup_engine/apps/api/admin/deduplicationset.py @@ -1,22 +1,14 @@ -from uuid import UUID - from django.contrib.admin import ModelAdmin, register -from django.http import HttpRequest, HttpResponseRedirect -from django.urls import reverse -from admin_extra_buttons.api import button -from admin_extra_buttons.mixins import ExtraButtonsMixin from adminfilters.dates import DateRangeFilter from adminfilters.filters import ChoicesFieldComboFilter, DjangoLookupFilter from adminfilters.mixin import AdminFiltersMixin from hope_dedup_engine.apps.api.models import DeduplicationSet -from hope_dedup_engine.apps.api.utils.process import start_processing -from hope_dedup_engine.utils.security import can_reprocess @register(DeduplicationSet) -class DeduplicationSetAdmin(AdminFiltersMixin, ExtraButtonsMixin, ModelAdmin): +class DeduplicationSetAdmin(AdminFiltersMixin, ModelAdmin): list_display = ( "id", "name", @@ -44,19 +36,6 @@ class DeduplicationSetAdmin(AdminFiltersMixin, ExtraButtonsMixin, ModelAdmin): ("updated_at", DateRangeFilter), DjangoLookupFilter, ) - change_form_template = "admin/api/deduplicationset/change_form.html" def has_add_permission(self, request): return False - - @button(permission=can_reprocess) - def process( - self, request: HttpRequest, pk: UUID - ) -> HttpResponseRedirect: # pragma: no cover - obj = self.get_object(request, pk) - start_processing(obj) - self.message_user( - request, - f"Processing for deduplication set '{obj}' has been started.", - ) - return HttpResponseRedirect(reverse("admin:api_deduplicationset_changelist")) diff --git a/src/hope_dedup_engine/utils/security.py b/src/hope_dedup_engine/utils/security.py index 6f404de1..9ee29f33 100644 --- a/src/hope_dedup_engine/utils/security.py +++ b/src/hope_dedup_engine/utils/security.py @@ -2,23 +2,9 @@ from django.conf import settings -from hope_dedup_engine.apps.api.models.deduplication import DeduplicationSet - def is_root(request: Any, *args: Any, **kwargs: Any) -> bool: return ( request.user.is_superuser and request.headers.get(settings.ROOT_TOKEN_HEADER) == settings.ROOT_TOKEN != "" ) - - -def can_reprocess(request: Any, *args: Any, **kwargs: Any) -> bool: - obj = args[0] if args and isinstance(args[0], DeduplicationSet) else None - if obj: - return any( - ( - request.user.is_superuser and obj.state == DeduplicationSet.State.ERROR, - is_root(request), - ) - ) - return False diff --git a/src/hope_dedup_engine/web/templates/admin/api/deduplicationset/change_form.html b/src/hope_dedup_engine/web/templates/admin/api/deduplicationset/change_form.html deleted file mode 100644 index acd63c38..00000000 --- a/src/hope_dedup_engine/web/templates/admin/api/deduplicationset/change_form.html +++ /dev/null @@ -1,8 +0,0 @@ -{% extends "admin/change_form.html" %} - -{% block object-tools-items %} - {{ block.super }} - {% include "admin_extra_buttons/includes/change_form_buttons.html" %} -{% endblock %} - -{% block pagination %}{% endblock %}