Skip to content

Commit

Permalink
fix: check if the pulled active accounts are also available
Browse files Browse the repository at this point in the history
  • Loading branch information
Soare-Robert-Daniel committed Jul 9, 2024
1 parent 91464a0 commit e6aa658
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions includes/admin/class-rop-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -686,10 +686,34 @@ private function get_authenticated_services() {
* @return array
*/
private function get_active_accounts() {
$model = new Rop_Services_Model();
// $model->reset_authenticated_services();
$model = new Rop_Services_Model();
$saved_active_accounts = $model->get_active_accounts();
$available_services = $model->get_authenticated_services();

// Return the active accounts that are also available.
$valid_accounts = array();
$available_accounts_ids = array();

foreach ( $available_services as $_ => $service ) {
if ( ! isset( $service['available_accounts'] ) ) {
continue;
}

foreach ( $service['available_accounts'] as $account_id => $_ ) {
$available_accounts_ids[] = $account_id;
}
}

foreach ( $saved_active_accounts as $active_account_id => $active_account ) {
if ( ! in_array( $active_account_id, $available_accounts_ids, true ) ) {
continue;
}

$valid_accounts[ $active_account_id ] = $active_account;
}

$this->response->set_code( '200' )
->set_data( $model->get_active_accounts() );
->set_data( $valid_accounts );

return $this->response->to_array();
}
Expand Down

0 comments on commit e6aa658

Please sign in to comment.