plone / plone.restapi

RESTful API for Plone.
http://plonerestapi.readthedocs.org/
85 stars 75 forks source link

Vocabularies should be called with query, if it exists #1806

Closed tiberiuichim closed 2 weeks ago

tiberiuichim commented 2 weeks ago

https://github.com/plone/plone.restapi/blob/aec08ce8f9d787694142a76b16f3147fef5d628c/src/plone/restapi/services/vocabularies/get.py#L89

Calling vocabularies can take a query:

https://github.com/plone/plone.app.vocabularies/blob/e228d563f4c3fd8fd68ea25f0a86dc9562cfea7e/plone/app/vocabularies/principals.py#L215

Calling getVocabulary action in Volto allows a query, too:

https://github.com/plone/volto/blob/41da257edaba21dd479f385b9d53d688283d093e/packages/volto/src/actions/vocabularies/vocabularies.js#L25

And there's a widget that supports this type of searching with vocabularies, already:

https://github.com/plone/volto/blob/41da257edaba21dd479f385b9d53d688283d093e/packages/volto/src/components/manage/Widgets/SelectAutoComplete.jsx#L192

tiberiuichim commented 2 weeks ago

~Nevermind, this is handled in the vocabulary serializer~

tiberiuichim commented 2 weeks ago

The problem is that the Principals vocabulary factory wants to be called with a query:

https://github.com/plone/plone.restapi/blob/aec08ce8f9d787694142a76b16f3147fef5d628c/src/plone/restapi/services/vocabularies/get.py#L89-L92

It dynamically builds a vocabulary based on the query, by searching acl_users. I think, based on the existing code in Volto, we should pass query=self.request.form.get('title')

davisagli commented 2 weeks ago

@tiberiuichim I explained in https://github.com/plone/plone.restapi/pull/1807#discussion_r1744266530 that this is a bit complicated, because not all vocabularies support being called with a query parameter.

Can you explain a bit more about the context of what problem you are trying to solve?

tiberiuichim commented 2 weeks ago

Can you explain a bit more about the context of what problem you are trying to solve?

In the contributors field of the IOwnership interface, I want to show the user's fullname, rather then the userid. In addition, this would allow the SelectAutocomplete widget to search the vocabulary and provide autocomplete of users.

The problem is that on the EEA website we have Azure login and the userids are uids. We want to show, in the widget, their name. When I use the users management tool in Plone control panel, I can search for users by name and they are found, so the support is there. This PR would help, but it wouldn't be everything that's needed.

davisagli commented 2 weeks ago

Got it. The users control panel uses the @users endpoint, which does support filtering, but is only available for manager users. I'll need to think some more about how to handle this well.

davisagli commented 2 weeks ago

@tiberiuichim For your specific use case, maybe it's most expedient to create a custom service which calls the user vocabulary with the query.