Aggiunta membri di gruppo vs aggiunta proprietari: il formato dei dati è diverso

Quando si utilizza l’API per aggiungere membri e proprietari a un gruppo, sembra che il formato dei dati richiesti sia diverso. Potrebbe essere intenzionale, ma vorrei sapere il motivo (sta rompendo pydiscourse, la migliore libreria che riesco a trovare per interagire con l’API di Discourse in Python).

Aggiunta di un membro a un gruppo:

curl -X PUT "https://{mydomain}/admin/groups/{group_id}/members.json" \ 
    -d 'usernames={my-username}' \
    -H "Api-Key: {my-api-key}" \
    -H "Api-Username: {my-api-username}"

Aggiunta di un proprietario a un gruppo:

curl -X PUT "https://{mydomain}/admin/groups/{group_id}/owners.json" \ 
    -d 'group[usernames]={my-username}' \
    -H "Api-Key: {my-api-key}" \
    -H "Api-Username: {my-api-username}"

Mi incuriosisce perché la chiave per il parametro username nell’endpoint dei proprietari debba essere scritta come group[usernames] invece di semplicemente usernames?

The only reason I can give as to why is that they are actually using two different controllers.

The add members endpoint is mapped to the groups controller:

PUT /admin/groups/:id/members(.:format) groups#add_members 

And the add owners endpoint is mapped to the admin groups controller.

PUT /admin/groups/:id/owners(.:format) admin/groups#add_owners

It’s unlikely we will update this endpoint because lots of integrations already use this endpoint as is. You best bet is to open up an issue in the pydiscourse repo. You could also monkey patch a fix for add_group_owner in your python app until it gets resolved inside of pydiscourse.

1 Mi Piace