-
Notifications
You must be signed in to change notification settings - Fork 819
Users API endpoint: add 'viewer' role to user roles array and dedupe return value #41707
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
base: trunk
Are you sure you want to change the base?
Conversation
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. Follow this PR Review Process:
Still unsure? Reach out in #jetpack-developers for guidance! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Code Coverage SummaryCoverage changed in 3 files.
|
8f989b7
to
74e3633
Compare
@@ -0,0 +1,164 @@ | |||
<?php | |||
/** | |||
* Jetpack WPCOM JSON API `sites/%s/users` endpoint unit tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added these basic tests because they weren't there.
Testing the viewer role might have to be done on WPCOM as it's gated behind the IS_WPCOM
constant and calls internal methods, e.g., get_private_blog_users
}, | ||
$viewers | ||
); | ||
$combined_users = array_map( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This API does not dedupe users or the count where there are users with WordPress roles that were once viewers: they'll be included in the viewers list and merged as is.
See: #28317 (comment)
} | ||
|
||
// Get viewers. | ||
if ( $include_viewers ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've refactored all this to test out grabbing, deduping and merging the user and viewer lists before we return arbitrary count values that are not accurate.
This would remove the need for frontend hacks like:
Code Coverage SummaryCoverage changed in 1 file.
Full summary · PHP report · JS report If appropriate, add one of these labels to override the failing coverage check:
Covered by non-unit tests
|
31853ff
to
298b8a0
Compare
projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-list-users-endpoint.php
Show resolved
Hide resolved
break; | ||
} | ||
} | ||
|
||
return $return; | ||
return $response; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something about these changes also screws with the /people/viewers/$wordpress_site/$user_id
Calypso page. Check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's this check: https://github.com/Automattic/wp-calypso/blob/trunk/client/my-sites/people/team-members/index.tsx#L114
It assumes that the roles array is empty for viewers.
It should be something like const type = user.roles?.length && user.roles?.includes( 'viewer' ) ? 'viewer' : 'email';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…le can consume it.
…nt to save it in the commit history for reference.
298b8a0
to
bdbf075
Compare
} else { | ||
$viewer_count = count( $viewers ); | ||
} | ||
$viewer_count = count( $viewers ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't be accurate due to legacy duplication. See: Automattic/wp-calypso#100674 (comment)
Proposed changes:
Where viewers exist for site, add 'viewer' to the user roles array so the WP Admin table can consume it.
E.g., user item:
Furthermore, dedupe the return users list.
Why are these changes being made?
As part of Untangling Users, the API should return whether a WPCOM user has the viewer role in order that the WP Admin Users table can display correct labels. See 171239-ghe-Automattic/wpcom
Viewers that have been assigned a WordPress role, like Author, are not removed from the private blog table, and are therefore duplicated in both the found and users parameters.
This makes the found count inaccurate and also create duplicates in the users list.
Testing instructions
Local tests
WPCOM tests
173364-ghe-Automattic/wpcom
Other information:
Jetpack product discussion
Does this pull request change what data or activity we track or use?