Skip to content

Commit

Permalink
chg ! admin panel - process deduplication set - is root
Browse files Browse the repository at this point in the history
  • Loading branch information
vitali-yanushchyk-valor committed Oct 23, 2024
1 parent 4920915 commit fd743ac
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/hope_dedup_engine/apps/api/admin/deduplicationset.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

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 is_root


@register(DeduplicationSet)
Expand Down Expand Up @@ -45,11 +46,12 @@ class DeduplicationSetAdmin(AdminFiltersMixin, ExtraButtonsMixin, ModelAdmin):
def has_add_permission(self, request):
return False

@button(label="Process")
@button(permission=is_root)
def process(self, request: HttpRequest, pk: str) -> HttpResponseRedirect:
dd = DeduplicationSet.objects.get(pk=pk)
start_processing(dd)
self.message_user(
request, f"Processing for deduplication set '{dd}' has been started."
request,
f"Processing for deduplication set '{dd}' has been started.",
)
return HttpResponseRedirect(reverse("admin:api_deduplicationset_changelist"))
11 changes: 9 additions & 2 deletions src/hope_dedup_engine/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from enum import Enum
from typing import TYPE_CHECKING, Any, Dict, Tuple, TypeAlias, Union
from uuid import uuid4

from smart_env import SmartEnv

Expand Down Expand Up @@ -173,8 +174,14 @@ class Group(Enum):
setting("media-root"),
),
"MEDIA_URL": (str, "/media/", "/media", False, setting("media-root")), # nosec
"ROOT_TOKEN_HEADER": (str, "x-root-token", "x-root-token"),
"ROOT_TOKEN": (str, ""),
"ROOT_ACCESS_TOKEN": (str, uuid4().hex, uuid4().hex, False, "Root access token"),
"ROOT_TOKEN_HEADER": (
str,
"x-root-token",
"x-root-token",
False,
"Root token header",
),
"SECRET_KEY": (
str,
"",
Expand Down
4 changes: 2 additions & 2 deletions src/hope_dedup_engine/config/fragments/root.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from hope_dedup_engine.config import env

ROOT_TOKEN = env("ROOT_TOKEN")
ROOT_TOKEN_HEADER = env("ROOT_TOKEN_HEADER", default="x-root-token")
ROOT_TOKEN = env("ROOT_ACCESS_TOKEN")
ROOT_TOKEN_HEADER = env("ROOT_TOKEN_HEADER")
2 changes: 1 addition & 1 deletion tests/admin/test_admin_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def test_admin_delete(app, modeladmin, record, monkeypatch):
pytest.skip("No 'delete' permission")


@pytest.mark.skip_buttons("security.UserAdmin:link_user_data")
@pytest.mark.skip_buttons("api.DeduplicationSetAdmin:process")
def test_admin_buttons(app, modeladmin, button_handler, record, monkeypatch):
from admin_extra_buttons.handlers import LinkHandler

Expand Down

0 comments on commit fd743ac

Please sign in to comment.