Discourse gem group_add

It looks like the API to add and remove users from a group has changed too from the version in the Gem.

The gem makes a patch request to /admin/groups/group_id with

{
    "changes": {
        "add": [
            "sam"
        ]
    }
}

Discourse currently seems to expect a PUT to /admin/groups/group_id/members.json to add a user, and a DELETE to the same path to remove a user. However the DELETE call now seems to take the user_id as a param, not the username.

Again I am happy to fix. Shall we just change the gem to fit the current Discourse API? It means we only need to change the code in the gem. The drawback is that it is a little ugly to add users via username and remove via id in the interface.

1 Like

Feel free to make PRs to fix/improve the discourse_api gem :wink:

The Discourse API is designed around the UI. It happens that admins

  • often add users to a group via their username (hence the add_members method which requires a list of usernames)
  • rarely remove users from a group and do so by clicking the :x: button next to the user (hence the remove_member method which requires a user_id)

Again, feel free to make PRs to update the Discourse API if you want to:

  • add the add_member / remove_members methods
  • allow either of these methods to take a username or a user_id as parameter.

allow either of these methods to take a username or a user_id as parameter.

Are you thinking this is by making an extra request to get the user_id or username as appropriate inside the group_add / group_remove methods, or by updating the API on the discourse side to allow either (and hence will need a PR against both repos)?

That one :point_down:

Cool. Will do that… :smile:

1 Like

I have created a PR for the discourse side here

1 Like

PR now opened on the gem side: Update add and remove group calls for changed discourse API by dansingerman · Pull Request #69 · discourse/discourse_api · GitHub :sunglasses:

1 Like