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

Experimental auditing features #79

Merged
merged 12 commits into from
Apr 10, 2024

Conversation

adekbadek
Copy link
Member

@adekbadek adekbadek commented Feb 29, 2024

All Submissions:

Changes proposed in this Pull Request:

A few auditing features, for now restricted to a specific WP user.

  1. In the Membership Plans view, the tables are now unified. Two columns are added to help with auditing the synchronisation:
image
  1. New column in the WP Users view, featuring origin site URL and User ID on that site (the text is a link to the user edit screen):
image
  1. New column in the Nodes table, displaying synchronisable users count:
image

How to test the changes in this Pull Request:

  1. Verify none of the features are visible until the next step is done
  2. Set NEWSPACK_NETWORK_EXPERIMENTAL_AUDITING_USER wp-config variable, with the value of the admin user you're using (e.g. admin)
  3. Visit WP Users tables (/wp-admin?users.php) on the Hub and Node sites, verify the new column features correct data and links
  4. Visit the "Nodes" view on the Hub site
    1. Click the user counts, observe the links point to WP Users table filtered by synchronized roles
    2. Visit the corresponding Node sites, confirm the numbers are correct
  5. Visit the "Membership Plans" view on the Hub site
    1. observe a new "Active Members" column
    2. Observe a new "Discrepancies" column and verify the discrepancies between synchronised plan members*
    3. Click the link to view the discrepant members

* to create some discrepancies, add plan members and then quickly remove the corresponding event (wp_newspack_hub_event_log table) or webhook (np_webhook_request post type), if on hub or node, respectively

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@adekbadek adekbadek force-pushed the feat/experimental-member-discrepancy-detection branch from 4947894 to 67569b5 Compare March 8, 2024 09:12
Copy link
Contributor

@chickenn00dle chickenn00dle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as expected @adekbadek

There are two very minor issues and a handful of nitpicks, and then this is okay. Nitpicks are not blocking and can be ignored.

@@ -191,4 +191,16 @@ public static function admin_init() {
*/
public static function enqueue_scripts() {
}

/**
* Has experimental auditing features?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: A return tag is missing and would be helpful here and in a handful of other methods in this PR

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 121cc68

@@ -29,10 +31,14 @@ protected function get_processed_item_output( $event ) {
* @return \Newspack_Network\Incoming_Events\Abstract_Incoming_Event[] $events An array of events.
*/
public function get_events() {
$roles_to_sync = \Newspack_Network\Utils\Users::get_synced_user_roles();
if ( $roles_to_sync === [] ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Maybe we can use something like PHP empty here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 121cc68

@@ -49,6 +55,8 @@ public function get_events() {
]
);

WP_CLI::line( sprintf( 'Found %s users eligible for sync.', count( $users ) ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to account for single user (Found 1 user eligible for sync)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 121cc68

$edit_url = get_edit_post_link( $item['id'] );
if ( isset( $item['node_url'] ) ) {
$edit_url = sprintf( '%s/wp-admin/post.php?post=%d&action=edit', $item['node_url'], $item['id'] );
if ( $column_name === 'network_pass_discrepancies' && isset( $item['network_pass_discrepancies'] ) && $item['network_pass_id'] ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be checking $item['network_pass_id'] with isset as well? Will this always be present at this stage?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for that, network_pass_id is not optional. network_pass_discrepancies is, because it's only included if the auditing features are enabled.

@@ -123,14 +132,44 @@ public static function get_membershp_plans_from_nodes() {
$network_pass_id = $meta->value;
}
}
if ( $network_pass_id && \Newspack_Network\Admin::use_experimental_auditing_features() ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Might be worth namespacing this since we call use_experimental_auditing_features multiple times in this file

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 121cc68

@adekbadek adekbadek force-pushed the feat/experimental-member-discrepancy-detection branch from f18f18e to 121cc68 Compare April 8, 2024 06:55
@adekbadek adekbadek merged commit 0c31fd6 into trunk Apr 10, 2024
3 checks passed
@adekbadek adekbadek deleted the feat/experimental-member-discrepancy-detection branch April 10, 2024 08:03
matticbot pushed a commit that referenced this pull request Apr 11, 2024
# [1.6.0-alpha.1](v1.5.0...v1.6.0-alpha.1) (2024-04-11)

### Features

* experimental auditing features ([#79](#79)) ([0c31fd6](0c31fd6))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.6.0-alpha.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Apr 24, 2024
# [1.6.0](v1.5.0...v1.6.0) (2024-04-24)

### Features

* experimental auditing features ([#79](#79)) ([0c31fd6](0c31fd6))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.6.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

3 participants