Skip to content

Commit

Permalink
Support more expressive plugin URLs #11320 (#11325)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls authored Aug 12, 2024
1 parent d093f8f commit eec0666
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
7 changes: 2 additions & 5 deletions arches/app/views/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,14 @@
class PluginView(MapBaseManagerView):
action = None

def get(self, request, pluginid=None, slug=None):
def get(self, request, pluginid=None, slug=None, path=None):
if slug is not None:
plugin = models.Plugin.objects.get(slug=slug)
else:
plugin = models.Plugin.objects.get(pk=pluginid)

if not request.user.has_perm("view_plugin", plugin):
if slug is not None:
return redirect("/auth?next=/plugins/{}".format(slug))
if slug is not None:
return redirect("/auth?next=/plugins/{}".format(pluginid))
return redirect("/auth/?next=" + request.path)

if request.GET.get("json"):
return JSONResponse(plugin)
Expand Down
8 changes: 4 additions & 4 deletions arches/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,10 +648,10 @@
api.Concepts.as_view(),
name="concepts",
),
re_path(
r"^plugins/(?P<pluginid>%s)$" % uuid_regex, PluginView.as_view(), name="plugins"
),
re_path(r"^plugins/(?P<slug>[-\w]+)$", PluginView.as_view(), name="plugins"),
path("plugins/<uuid:pluginid>", PluginView.as_view(), name="plugins"),
path("plugins/<uuid:pluginid>/<path:path>", PluginView.as_view(), name="plugins"),
path("plugins/<slug:slug>", PluginView.as_view(), name="plugins"),
path("plugins/<slug:slug>/<path:path>", PluginView.as_view(), name="plugins"),
re_path(
r"^workflow_history/(?P<workflowid>%s|())$" % uuid_regex,
WorkflowHistoryView.as_view(),
Expand Down
1 change: 1 addition & 0 deletions releases/8.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Arches 8.0.0 Release Notes

- Add session-based REST APIs for login, logout [#11261](https://github.com/archesproject/arches/issues/11261)
- Improve handling of longer model names [#11317](https://github.com/archesproject/arches/issues/11317)
- Support more expressive plugin URLs [#11320](https://github.com/archesproject/arches/issues/11320)

### Dependency changes
```
Expand Down
12 changes: 12 additions & 0 deletions tests/views/plugin_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.test import TestCase

# these tests can be run from the command line via
# python manage.py test tests.views.plugin_tests --settings="tests.test_settings"


class PluginViewTests(TestCase):
def test_post_auth_redirect_preserves_full_path(self):
response = self.client.get("/plugins/bulk-data-manager/full-path")
self.assertRedirects(
response, "/auth/?next=/plugins/bulk-data-manager/full-path"
)

0 comments on commit eec0666

Please sign in to comment.