Skip to content

Commit

Permalink
del ! rerun duplicate finding in case ERROR state in admin Deduplicat…
Browse files Browse the repository at this point in the history
…ion sets -> change
  • Loading branch information
vitali-yanushchyk-valor committed Nov 12, 2024
1 parent 0465529 commit b70e5ef
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 44 deletions.
23 changes: 1 addition & 22 deletions src/hope_dedup_engine/apps/api/admin/deduplicationset.py
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"))
14 changes: 0 additions & 14 deletions src/hope_dedup_engine/utils/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

This file was deleted.

0 comments on commit b70e5ef

Please sign in to comment.