Repository: wagtail/wagtail

Issue:
`register_admin_viewset` does not accept list of viewsets anymore
### Issue Summary

Unfortunately, starting with the 5.2rc1 many of our `register_admin_viewset`-hooks don't work anymore, because since https://github.com/wagtail/wagtail/commit/df65ccadc6191ec346e14002132033a25be0c1ec it is no longer possible to return lists of viewsets.
Actually, this was a quite handy feature, because so you could add a bunch of unrelated viewsets. Especially with choosers, you don't need a `ViewSetGroup`, so you would have to add each with a separate `register_admin_viewset`-hook (?).

It looks like this was never documented, so we probably used this feature based on wagtail-internals (I think I've seen it in the wild (package) too, but I'm not 100% sure), so I would understand if you don't see it as a bug. I still hope, that we can get this feature back.

Options:
1) Re-add the feature to 5.2 (would be nice!)
2) Add a enhancement-issue for the next release, and maybe document the undocumented change in the release notes for 5.2

### Steps to Reproduce

We're using the hook like this:
```python
@hooks.register("register_admin_viewset")
def register_viewset():
    return [
        viewsets.gallery_collection_chooser_viewset,
        viewsets.podcast_page_chooser_viewset,
    ]
```

-   I have confirmed that this issue can be reproduced as described on a fresh Wagtail project: yes

### Technical details

-   Python version: 3.11
-   Django version: 4.2.6
-   Wagtail version: 5.2rc1



Discussion:
This was intentional in df65ccadc6191ec346e14002132033a25be0c1ec per https://github.com/wagtail/wagtail/pull/10767#discussion_r1289934664

I’m not sure we want to add this, since it was never documented and was only an ad-hoc workaround that we no longer use.

You can still register multiple viewsets with a `ViewSetGroup` even if they’re unrelated.

Though I guess it’s simple enough for us to reinstate…
+1 for adding it back - it looks simple enough to support that we should do so, rather than create a hurdle for people who used this in the wild (even if it was undocumented).
@gasman can I take this up?
@Temidayo32 Yep, go ahead!
@gasman if added back, would it be a stretch to document it or it not necessary?

Resolving patch:
diff --git a/wagtail/admin/viewsets/__init__.py b/wagtail/admin/viewsets/__init__.py
--- a/wagtail/admin/viewsets/__init__.py
+++ b/wagtail/admin/viewsets/__init__.py
@@ -11,7 +11,11 @@ def __init__(self):
     def populate(self):
         for fn in hooks.get_hooks("register_admin_viewset"):
             viewset = fn()
-            self.register(viewset)
+            if isinstance(viewset, (list, tuple)):
+                for vs in viewset:
+                    self.register(vs)
+            else:
+                self.register(viewset)
 
     def register(self, viewset):
         # Allow registering a ViewSetGroup, which will register all of its


Test patch:
diff --git a/wagtail/test/testapp/wagtail_hooks.py b/wagtail/test/testapp/wagtail_hooks.py
--- a/wagtail/test/testapp/wagtail_hooks.py
+++ b/wagtail/test/testapp/wagtail_hooks.py
@@ -251,12 +251,7 @@ def add_broken_links_summary_item(request, items):
 
 @hooks.register("register_admin_viewset")
 def register_viewsets():
-    return MiscellaneousViewSetGroup()
-
-
-@hooks.register("register_admin_viewset")
-def register_json_model_viewsets():
-    return JSONModelViewSetGroup()
+    return [MiscellaneousViewSetGroup(), JSONModelViewSetGroup()]
 
 
 @hooks.register("register_admin_viewset")