Context
- Plone 5.2 with email login enabled
- Python3
Problem
Suppose we create a user through REST API:
curl -i -X POST http://nohost/plone/@users -H 'Accept: application/json' -H 'Content-Type: application/json' --data-raw '{"description": "Professor of Linguistics", "email": "noam.chomsky@example.com", "fullname": "Noam Avram Chomsky", "home_page": "web.mit.edu/chomsky", "location": "Cambridge, MA", "password": "colorlessgreenideas", "roles": ["Contributor"]}' --user admin:secret
Note the missing field “username”:
it is not allowed when email login is enabled .
Suppose we now want to add this user to the ploneteam
group by updating this group through REST API. If we use his email as user identifier in "users"
:
curl -i -X PATCH http://nohost/plone/@groups/ploneteam -H 'Accept: application/json' -H 'Content-Type: application/json' --data-raw '{"email": "ploneteam2@plone.org", "users": {"noam.chomsky@example.com": true}}' --user admin:secret
fails (silently: "204 No Content response") to add this user to the ploneteam
group.
By contrast, if we (manually) look at the information of this user, we'll see his user_id
is noam-avram-chomsky
and using in the previous command this user identifier instead of his email:
curl -i -X PATCH http://nohost/plone/@groups/ploneteam -H 'Accept: application/json' -H 'Content-Type: application/json' --data-raw '{"email": "ploneteam2@plone.org", "users": {"noam-avram-chomsky": true}}' --user admin:secret
successfully updates the group by adding him to the ploneteam
group.
The problem is, this cannot be done programmatically.
Am I missing something?