wp-net / WordPressPCL

This is a portable library for consuimg the WordPress REST-API in (almost) any C# application
MIT License
335 stars 131 forks source link

List all users does not get roles #266

Open GuerrillaCoder opened 2 years ago

GuerrillaCoder commented 2 years ago

Currently doing:

var wpUsers = _client.Users.GetAll(useAuth:true).Result;

Will hit the endpoint:

https://example.com/wp-json/wp/v2/users

But this endpoint does not return users roles.

To return roles you need to pass edit context like so:

https://example.com/wp-json/wp/v2/users?context=edit

This needs to be an option on GetAll()

GuerrillaCoder commented 2 years ago

I had a look at code and I think issue is IReadOperation. I think it needs to have a parameter for query params.

Let me know if you want a PR as it would update quite a few places in code.

warp123 commented 6 months ago

Appart from the boolean "embed" property of the GetAll function, there should be an "edit" property in order to retrieve everything. The problem resides in the httpHelper module. There should be an easy way to fix this, but i need to see if this messes the code in other places.

hbcondo commented 5 months ago

Can the proposed "edit" property be applied to all the methods in the Users class? For example, it would beneficial to have the roles returned when calling GetCurrentUser. Right now it is null since this method does not have an embed property so AFAIK there is no way currently to get roles populated for the current user.

hbcondo commented 4 months ago

@ThomasPe, is there a way this issue can be escalated? It's actually a blocker (for me) not being able to get roles via these User methods

bindalf commented 4 months ago

i would also need the roles for current user downloaded code and edited public Task GetCurrentUser() { return _httpHelper.GetRequestAsync($"{METHOD_PATH}/me?context=edit", true, true); }

ThomasPe commented 4 months ago

I'll try to look at this soon(ish)