Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Roles test #366

Merged
merged 9 commits into from
Sep 22, 2024
Merged

Roles test #366

merged 9 commits into from
Sep 22, 2024

Conversation

ThomasPe
Copy link
Member

@ThomasPe ThomasPe commented Apr 4, 2024

adds test to validate user queries with context=edit will return user roles as expected
also removes all IEnumerables in favor of Lists (as they are materialized already anyways).

@TREVORPINKS
Copy link

Cool. But - is this in the main release yet? I had to branch the wordpresspcl projec tto get things working: #266

@ThomasPe
Copy link
Member Author

this should be possible all along, it just wasn't documented. can you try this?

To retreive users with roles, you'll need to set the Context property of the UsersQueryBuilder to Context.Edit.

UsersQueryBuilder queryBuilder = new()
{
    // required for roles to be loaded
    Context = Context.Edit
};

List<User> users = await _clientAuth.Users.QueryAsync(queryBuilder, true);

@ThomasPe ThomasPe merged commit cc1cea5 into master Sep 22, 2024
3 checks passed
@ThomasPe ThomasPe deleted the roles-test branch September 22, 2024 19:43
@TREVORPINKS
Copy link

Hi @ThomasPe , I confirmed that the fix/suggestion works on the current 2.1 version. So... that way I can at least use NuGet instead of my one off branch now.

I think that to save the frustration of anyone using the API, you may need to shield this context=edit from the caller because I assume people want all the fields by default. (in the next version of WordPressPCL).

There is so many ways to do it. The easiest way may be to check if UseAuth is true, and if so, automatically add Context=Edit to the call. Or you could add a third param on top of embed/useauth and call the third one contextedit=true.

I think the point of the C# api is to shield some of these word press nuances.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants