Skip to content

Commit

Permalink
Allow plugins to redirect with full path
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Jul 31, 2024
1 parent 93b66f4 commit 1475469
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
12 changes: 12 additions & 0 deletions arches_references/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,21 @@
ListItemImageView,
ListItemImageMetadataView,
ListItemValueView,
PluginWithFullRedirectView,
)

urlpatterns = [
# Override plugins routes from core to preserve full path on auth redirect.
path(
"plugins/<uuid:pluginid>/<path:path>",
PluginWithFullRedirectView.as_view(),
name="plugins",
),
path(
"plugins/<slug:slug>/<path:path>",
PluginWithFullRedirectView.as_view(),
name="plugins",
),
path("api/controlled_lists", ListsView.as_view(), name="controlled_lists"),
path(
"api/controlled_list/<uuid:list_id>",
Expand Down
21 changes: 17 additions & 4 deletions arches_references/views.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import logging
from http import HTTPStatus
from uuid import UUID

from django.core.exceptions import ValidationError
from django.db import transaction
from django.db.models import Max
from django.views.generic import View
from django.shortcuts import redirect
from django.utils.decorators import method_decorator
from django.utils.translation import gettext as _
from django.views.generic import View

from arches.app.models.models import Plugin
from arches.app.models.utils import field_names
from arches.app.utils.betterJSONSerializer import JSONDeserializer
from arches.app.utils.decorators import group_required
from arches.app.utils.permission_backend import get_nodegroups_by_perm
from arches.app.utils.response import JSONErrorResponse, JSONResponse
from arches.app.utils.string_utils import str_to_bool
from arches.app.views.api import APIBase
from arches.app.views.plugin import PluginView
from arches_references.models import (
List,
ListItem,
Expand All @@ -25,8 +27,6 @@
NodeProxy,
)

logger = logging.getLogger(__name__)


def _prefetch_terms(request):
"""Children at arbitrary depth will still be returned, but tell
Expand Down Expand Up @@ -369,3 +369,16 @@ def delete(self, request, metadata_id):
if not count:
return JSONErrorResponse(status=HTTPStatus.NOT_FOUND)
return JSONResponse(status=HTTPStatus.NO_CONTENT)


class PluginWithFullRedirectView(PluginView):
def get(self, request, pluginid=None, slug=None, path=None):
if slug:
plugin = Plugin.objects.get(slug=slug)
else:
plugin = Plugin.objects.get(pk=pluginid)

if not request.user.has_perm("view_plugin", plugin):
return redirect("/auth?next=" + request.path)

return super().get(request, pluginid=pluginid, slug=slug)

0 comments on commit 1475469

Please sign in to comment.