Is it possible to delete a user from group by restapi

Problem:
With pulp-cli pulp group user remove , I can remove a user from a pulp group

I would like to try by restapi, according to the doc:
https://docs.pulpproject.org/pulpcore/restapi.html#tag/Groups:-Users/operation/groups_users_delete
but I don’t know where to get the groups_user_href?
I have :

/pulp/api/v3/groups/4/users/
/pulp/api/v3/groups/
/pulp/api/v3/users/

Does anyone know this?

Thanks in advance


“versions”: [
{
“component”: “core”,
“version”: “3.45.1”,
“package”: “pulpcore”,
“module”: “pulpcore.app”,
“domain_compatible”: true
},
{
“component”: “rpm”,
“version”: “3.25.0”,
“package”: “pulp-rpm”,
“module”: “pulp_rpm.app”,
“domain_compatible”: true
},

pulp-cli 0.23.2

pulp-cli 0.23.2
pulp-glue 0.23.2

Well, this is Fun! After some investigation, the group_user_href is constructed as “the part of the user-href after the API ROOT appended to the group-href”.

Example: user ‘testuser’ is in group ‘test-group’

$ pulp group show --name test-group | jq -r '.pulp_href'
/pulp/api/v3/groups/1/
$ pulp user show --username testuser | jq -r '.pulp_href'
/pulp/api/v3/users/2/
$ pulp group user list --group test-group
[
  {
    "username": "testuser",
    "pulp_href": "/pulp/api/v3/users/2/"
  }
]

To delete that user from that group, you need to create the group-user-href by hand to be

/pulp/api/v3/groups/1/users/2/

which is…kind of suboptimal.

You can see pulp-cli doing this work here : https://github.com/pulp/pulp-cli/blob/main/pulpcore/cli/core/group.py#L198

This could prob use an RFE to provide a means of getting the group-user-hrefs for a group from the API. It would be great if you could open one here!

2 Likes

Hello @ggainey , Thanks very much for the example!
Sorry my late reply. I have tested it, it works!
About the RFE( ?), I will do it late. :slight_smile:

1 Like

I think the confusion stems from the fact that the REST api provides access to the group-user which is in fact the join model. So to add a user to a group, you create a join object, and to remove it again, you delete that association again. (Not saying that this was a good design…)

So your RFE would be an add_user and a remove_user http verb?

Hadn’t thought it through as far as implementation - just as far as “requiring as input an HREF that the API doesn’t ever show anywhere is Rude” :slight_smile:

Adding new verbs would definitely work. My initial thought, though, was just “improve the usergroup serializer to show the usergroup_href list” - so one could query the group, and then use those HREFs directly in the delete-from-group call.

THe desired-end-state, regardless of how we implement it, is “a user can remove a pulp-user from a group in a way that doesn’t require building HREFs by hand.”

1 Like

after reading your further explanation, i am not sure if my demand is suitable or not, because maybe some usecase needs user_href when doing groups:users/list users query

I was guessing the groups_user_href must be a a kind of combination of group+user href, but was not sure how, so I put my question :slight_smile:

Your requirement is perfectly valid, and your assumption was perfectly correct - removing a user-from-a-group requires a “hybrid” of the group-href and the user-href. But it’s unreasonable for the API to expect the caller to know how to correctly build such an HREF - there has to be some way for you to query pulp to get the list-of-group/user-hrefs in order to pass them to the remove-from-group API, and currently we don’t have such a thing.

after know how, to construct it is not difficult, so I can do it, anyway, I put a REF here :slight_smile:

3 Likes

Well, one of the key goals of REST is, clients have enough information in the resource representation to modify or delete the resource if they want to. This absence violates that expectation - very rude :slight_smile:

Thanks for the RFE - future users will thank you for it! :slight_smile:

1 Like