Skip to content

Commit

Permalink
Merge pull request #2448 from woocommerce/tweak/enable-notifications-…
Browse files Browse the repository at this point in the history
…default

[API Pull] Enable notifications by default
  • Loading branch information
puntope authored Jul 4, 2024
2 parents 13b47f0 + d47c264 commit 51eb4d3
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 21 deletions.
1 change: 1 addition & 0 deletions js/src/components/enable-new-product-sync-notice.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const EnableNewProductSyncNotice = () => {
// Do not render if already switch to new product sync.
if (
! hasGoogleMCAccountFinishedResolution ||
! googleMCAccount.notification_service_enabled ||
googleMCAccount.wpcom_rest_api_status
) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,9 @@ const ConnectedGoogleMCAccountCard = ( {
const showErrorNotificationsNotice =
! hideNotificationService &&
googleMCAccount.wpcom_rest_api_status &&
googleMCAccount.notification_service_enabled &&
googleMCAccount.wpcom_rest_api_status !==
GOOGLE_WPCOM_APP_CONNECTED_STATUS.APPROVED &&
googleMCAccount.wpcom_rest_api_status !==
GOOGLE_WPCOM_APP_CONNECTED_STATUS.DISABLED;
GOOGLE_WPCOM_APP_CONNECTED_STATUS.APPROVED;

const showFooter = ! hideAccountSwitch || showDisconnectNotificationsButton;

Expand Down
2 changes: 1 addition & 1 deletion src/API/WP/NotificationsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,6 @@ public function is_ready(): bool {
* @return bool
*/
public function is_enabled(): bool {
return apply_filters( 'woocommerce_gla_notifications_enabled', false );
return apply_filters( 'woocommerce_gla_notifications_enabled', true );
}
}
27 changes: 23 additions & 4 deletions src/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -650,11 +650,30 @@ protected function render_admin_page() {

<?php if ( $blog_token ) { ?>
<?php
$wp_api_status = $this->container->get( OptionsInterface::class )->get( OptionsInterface::WPCOM_REST_API_STATUS );
$options = $this->container->get( OptionsInterface::class );
$wp_api_status = $options->get( OptionsInterface::WPCOM_REST_API_STATUS );
$notification_service = new NotificationsService( $this->container->get( MerchantCenterService::class ) );
$notification_service->set_options_object( $options );
?>
<h2 class="title">Partner API Pull Integration</h2>
<form action="<?php echo esc_url( admin_url( 'admin.php' ) ); ?>" method="GET">
<table class="form-table" role="presentation">
<tr>
<th><label>Notification Service Enabled:</label></th>
<td>
<p>
<code><?php echo $notification_service->is_enabled() ? 'yes' : 'no' ?></code>
</p>
</td>
</tr>
<tr>
<th><label>Notification Service Ready:</label></th>
<td>
<p>
<code><?php echo $notification_service->is_ready() ? 'yes' : 'no' ?></code>
</p>
</td>
</tr>
<tr>
<th><label>WPCOM REST API Status:</label></th>
<td>
Expand Down Expand Up @@ -693,7 +712,7 @@ protected function render_admin_page() {
<tr>
<th><label>API Pull Integration Status:</label></th>
<td>
<p>
<p>
<a class="button" href="<?php echo esc_url( wp_nonce_url( add_query_arg( [ 'action' => 'partner-integration-status' ], $url ), 'partner-integration-status' ) ); ?>">Get API Pull Integration Status</a>
</p>
</td>
Expand All @@ -714,7 +733,7 @@ protected function render_admin_page() {
<code><?php echo isset( $this->integration_status_response['is_healthy'] ) && $this->integration_status_response['is_healthy'] === true ? 'Healthy' : 'Unhealthy'; ?></code>
</p>
</td>
</tr>
</tr>
<tr>
<th><label>Last Jetpack Contact:</label></th>
<td>
Expand Down Expand Up @@ -746,7 +765,7 @@ protected function render_admin_page() {
<code><?php echo isset( $this->integration_status_response['errors'] ) ? wp_kses_post( json_encode( $this->integration_status_response['errors'] ) ) ?? '' : '-'; ?></code>
</p>
</td>
</tr>
</tr>
<?php } ?>
</table>
<?php wp_nonce_field( 'partner-notification' ); ?>
Expand Down
7 changes: 4 additions & 3 deletions src/MerchantCenter/AccountService.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,10 @@ public function get_connected_status(): array {
$wpcom_rest_api_status = $this->options->get( OptionsInterface::WPCOM_REST_API_STATUS );

$status = [
'id' => $id,
'status' => $id ? 'connected' : 'disconnected',
'wpcom_rest_api_status' => $notifications_service->is_enabled() ? $wpcom_rest_api_status : 'disabled',
'id' => $id,
'status' => $id ? 'connected' : 'disconnected',
'notification_service_enabled' => $notifications_service->is_enabled(),
'wpcom_rest_api_status' => $wpcom_rest_api_status,
];

$incomplete = $this->state->last_incomplete_step();
Expand Down
23 changes: 13 additions & 10 deletions tests/Unit/MerchantCenter/AccountServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -765,9 +765,10 @@ public function test_get_connected_status() {

$this->assertEquals(
[
'id' => self::TEST_ACCOUNT_ID,
'status' => 'connected',
'wpcom_rest_api_status' => 'approved',
'id' => self::TEST_ACCOUNT_ID,
'status' => 'connected',
'notification_service_enabled' => true,
'wpcom_rest_api_status' => 'approved',
],
$this->account->get_connected_status()
);
Expand All @@ -788,9 +789,10 @@ public function test_get_connected_status_when_notifications_disabled() {

$this->assertEquals(
[
'id' => self::TEST_ACCOUNT_ID,
'status' => 'connected',
'wpcom_rest_api_status' => 'disabled',
'id' => self::TEST_ACCOUNT_ID,
'status' => 'connected',
'notification_service_enabled' => false,
'wpcom_rest_api_status' => 'approved',
],
$this->account->get_connected_status()
);
Expand All @@ -811,10 +813,11 @@ public function test_get_connected_status_incomplete() {

$this->assertEquals(
[
'id' => self::TEST_ACCOUNT_ID,
'status' => 'incomplete',
'step' => 'verify',
'wpcom_rest_api_status' => null,
'id' => self::TEST_ACCOUNT_ID,
'status' => 'incomplete',
'step' => 'verify',
'notification_service_enabled' => true,
'wpcom_rest_api_status' => null,
],
$this->account->get_connected_status()
);
Expand Down

0 comments on commit 51eb4d3

Please sign in to comment.