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

Add Dashboard Sharing info to Site Health #5420

Merged
merged 7 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 116 additions & 1 deletion includes/Core/Util/Debug_Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ protected function get_fields() {
'verification_status' => $this->get_verification_status_field(),
'connected_user_count' => $this->get_connected_user_count_field(),
'active_modules' => $this->get_active_modules_field(),
'recoverable_modules' => $this->get_recoverable_modules_field(),
'required_scopes' => $this->get_required_scopes_field(),
'capabilities' => $this->get_capabilities_field(),
'enabled_features' => $this->get_feature_fields(),
Expand All @@ -198,7 +199,7 @@ function ( $field ) use ( $none ) {

return $field;
},
array_merge( $fields, $this->get_module_fields() )
array_merge( $fields, $this->get_module_sharing_settings_fields(), $this->get_module_fields() )
);
}

Expand Down Expand Up @@ -363,6 +364,120 @@ private function get_active_modules_field() {
);
}

/**
* Gets the field definition for the recoverable_modules field.
*
* @since n.e.x.t
*
* @return array
*/
private function get_recoverable_modules_field() {
$recoverable_modules = $this->modules->get_recoverable_modules();

return array(
'label' => __( 'Recoverable Modules', 'google-site-kit' ),
'value' => join(
/* translators: used between list items, there is a space after the comma. */
__( ', ', 'google-site-kit' ),
wp_list_pluck( $recoverable_modules, 'name' )
),
'debug' => join( ', ', wp_list_pluck( $recoverable_modules, 'slug' ) ),
);
}

/**
* Gets the field definition for the module_sharing_settings field.
*
* @since n.e.x.t
*
* @return array
*/
private function get_module_sharing_settings_fields() {
$sharing_settings = $this->modules->get_module_sharing_settings()->get();
$shareable_modules = $this->modules->get_shareable_modules();
$fields = array();

foreach ( $shareable_modules as $module_slug => $module_details ) {
$fields[] = array_merge(
array(
/* translators: %s: module name */
'label' => sprintf( __( '%s Shared Roles', 'google-site-kit' ), $module_details->name ),
),
$this->get_module_shared_role_names( $sharing_settings[ $module_slug ]['sharedRoles'] )
);

$fields[] = array_merge(
array(
/* translators: %s: module name */
'label' => sprintf( __( '%s Management', 'google-site-kit' ), $module_details->name ),
),
$this->get_module_management( $sharing_settings[ $module_slug ]['management'] )
);
}

return $fields;
}

/**
* Gets the comma separated list of shared role names for module_sharing_settings.
*
* @since n.e.x.t
*
* @param array $role_slugs List of role slugs.
*
* @return array $role_names Comma separated list of role names for module_sharing_settings within value and debug keys.
*/
private function get_module_shared_role_names( $role_slugs ) {
if ( ! $role_slugs ) {
return array(
'value' => __( 'None', 'google-site-kit' ),
'debug' => 'none',
);
}

$wp_role_names = wp_roles()->get_names();
$shared_role_names = array_filter(
$wp_role_names,
function( $key ) use ( $role_slugs ) {
return in_array( $key, $role_slugs, true );
},
ARRAY_FILTER_USE_KEY
);

return array(
'value' => join(
/* translators: used between list items, there is a space after the comma. */
__( ', ', 'google-site-kit' ),
$shared_role_names
),
'debug' => join( ', ', $role_slugs ),
);
}

/**
* Gets the user friendly and debug values for module management used in module_sharing_settings.
*
* @since n.e.x.t
*
* @param string $management The module sharing settings management value. Can be either `owner` or `all_admins`.
*
* @return array User friendly and debug values for module management used in module_sharing_settings within value and debug keys.
*/
private function get_module_management( $management ) {
switch ( $management ) {
case 'all_admins':
return array(
'value' => __( 'Any admin signed in with Google', 'google-site-kit' ),
'debug' => 'all_admins',
);
default:
return array(
'value' => __( 'Owner', 'google-site-kit' ),
'debug' => 'owner',
);
}
}

/**
* Gets the field definition for the required_scopes field.
*
Expand Down
1 change: 1 addition & 0 deletions tests/phpunit/integration/Core/Util/Debug_DataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function test_register() {
'verification_status',
'connected_user_count',
'active_modules',
'recoverable_modules',
'reference_url',
'search_console_property',
'required_scopes',
Expand Down