From 374230ed3e26fafa853e18b75072ffa2148d499d Mon Sep 17 00:00:00 2001 From: Kedar Khaire Date: Tue, 5 Dec 2023 17:05:55 +0530 Subject: [PATCH] Enhancements for adding filter with ChannelId on condition (#1001) * Aligning 2x for issue 961 and pr 962 * Aligning 2x for issue 947 and pr 939 * solving whitespace error * Removing changes for issue 961 for pr 962 --------- Co-authored-by: Shishir <75600200+shishir-intelli@users.noreply.github.com> --- .../apigee_edge_teams.install | 15 ++++++++++++ .../apigee_edge_teams.team_settings.yml | 1 + .../schema/apigee_edge_teams.schema.yml | 3 +++ .../src/Entity/Controller/TeamController.php | 23 +++++++++++++++++++ .../src/Form/TeamAliasForm.php | 10 +++++++- 5 files changed, 51 insertions(+), 1 deletion(-) diff --git a/modules/apigee_edge_teams/apigee_edge_teams.install b/modules/apigee_edge_teams/apigee_edge_teams.install index d0a83c20..9fa5a30c 100644 --- a/modules/apigee_edge_teams/apigee_edge_teams.install +++ b/modules/apigee_edge_teams/apigee_edge_teams.install @@ -218,3 +218,18 @@ function apigee_edge_teams_update_9002() { $team_settings['content']['callbackUrl'] = $new_team_settings['content']['callbackUrl']; $config_storage->write('core.entity_view_display.team_app.team_app.default', $team_settings); } + +/** + * Install Configs for TeamAlias Form for Teams Setting Page + */ +function apigee_edge_teams_update_9003() { + // Update existing config. + /** @var \Drupal\Core\Config\StorageInterface $config_storage */ + $config_storage = \Drupal::service('config.storage'); + $module_path = \Drupal::service('extension.list.module')->getPath('apigee_edge_teams'); + $source = new FileStorage("$module_path/config/install"); + $new_team_settings = $source->read('apigee_edge_teams.team_settings'); + $team_settings = $config_storage->read('apigee_edge_teams.team_settings'); + $team_settings['enablefilter'] = $new_team_settings['enablefilter']; + $config_storage->write('apigee_edge_teams.team_settings', $team_settings); +} diff --git a/modules/apigee_edge_teams/config/install/apigee_edge_teams.team_settings.yml b/modules/apigee_edge_teams/config/install/apigee_edge_teams.team_settings.yml index 388d93e3..fda69532 100644 --- a/modules/apigee_edge_teams/config/install/apigee_edge_teams.team_settings.yml +++ b/modules/apigee_edge_teams/config/install/apigee_edge_teams.team_settings.yml @@ -1,6 +1,7 @@ langcode: en team_prefix: '' channelid: '' +enablefilter: '' entity_label_singular: '' entity_label_plural: '' cache_expiration: 900 diff --git a/modules/apigee_edge_teams/config/schema/apigee_edge_teams.schema.yml b/modules/apigee_edge_teams/config/schema/apigee_edge_teams.schema.yml index 69f5d137..2a4df60a 100644 --- a/modules/apigee_edge_teams/config/schema/apigee_edge_teams.schema.yml +++ b/modules/apigee_edge_teams/config/schema/apigee_edge_teams.schema.yml @@ -8,6 +8,9 @@ apigee_edge_teams.team_settings: channelid: type: label label: 'ChannelId settings' + enablefilter: + type: label + label: 'Filter by Channel ID' entity_label_singular: type: label label: 'How to refer to a Team on the UI (singular)' diff --git a/modules/apigee_edge_teams/src/Entity/Controller/TeamController.php b/modules/apigee_edge_teams/src/Entity/Controller/TeamController.php index b9243917..8b147912 100644 --- a/modules/apigee_edge_teams/src/Entity/Controller/TeamController.php +++ b/modules/apigee_edge_teams/src/Entity/Controller/TeamController.php @@ -25,6 +25,7 @@ use Apigee\Edge\Api\Management\Controller\CompanyController as EdgeCompanyController; use Apigee\Edge\Api\Management\Controller\CompanyControllerInterface as EdgeCompanyControllerInterface; use Apigee\Edge\Entity\EntityInterface; +use Apigee\Edge\Structure\PagerInterface; use Drupal\apigee_edge\Entity\Controller\Cache\AppCacheByOwnerFactoryInterface; use Drupal\apigee_edge\Entity\Controller\Cache\AppNameCacheByOwnerFactoryInterface; use Drupal\apigee_edge\Entity\Controller\Cache\EntityCacheInterface; @@ -38,6 +39,7 @@ use Drupal\apigee_edge\Entity\DeveloperCompaniesCacheInterface; use Drupal\apigee_edge\SDKConnectorInterface; use Drupal\apigee_edge_teams\CompanyMembershipObjectCacheInterface; +use Drupal\apigee_edge_teams\Form\TeamAliasForm; /** * Definition of the Team controller service. @@ -233,4 +235,25 @@ public function delete(string $entity_id): EntityInterface { return $entity; } + /** + * {@inheritdoc} + */ + public function getEntities(PagerInterface $pager = NULL, string $key_provider = 'id'): array { + $queryparam = []; + if ($this->orgController->isOrganizationApigeeX()) { + // Getting the channelId & filter enable check from Config form. + $channelconfig = \Drupal::config('apigee_edge_teams.team_settings'); + $channelid = $channelconfig->get('channelid'); + $channelfilter = $channelconfig->get('enablefilter'); + if ($channelfilter) { + $channelid = $channelid ? $channelid : TeamAliasForm::originalChannelId(); + $queryparam = [ + 'filter' => 'channelId=' . $channelid + ]; + } + } + $entities = $this->decorated()->getEntities($pager, $key_provider, $queryparam); + return $entities; + } + } diff --git a/modules/apigee_edge_teams/src/Form/TeamAliasForm.php b/modules/apigee_edge_teams/src/Form/TeamAliasForm.php index 97d392a8..cd785910 100644 --- a/modules/apigee_edge_teams/src/Form/TeamAliasForm.php +++ b/modules/apigee_edge_teams/src/Form/TeamAliasForm.php @@ -68,6 +68,13 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#default_value' => $config->get('channelid'), '#description' => $this->t('Leave empty to use the default "@channelid" as channel ID.', ['@channelid' => $this->originalChannelId()]), ]; + + $form['channel_label']['enablefilter'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Filter by Channel ID'), + '#default_value' => $config->get('enablefilter'), + '#description' => $this->t('Enforce the filtering of AppGroups based on Channel ID specified in the field above.'), + ]; } return parent::buildForm($form, $form_state); } @@ -97,9 +104,10 @@ public function validateForm(array &$form, FormStateInterface $form_state) { public function submitForm(array &$form, FormStateInterface $form_state) { $config = $this->config($this->getConfigNameWithLabels()); - if ($config->get('team_prefix') !== $form_state->getValue('team_prefix') || $config->get('channelid') !== $form_state->getValue('channelid')) { + if ($config->get('team_prefix') !== $form_state->getValue('team_prefix') || $config->get('channelid') !== $form_state->getValue('channelid') || $config->get('enablefilter') !== $form_state->getValue('enablefilter')) { $config->set('team_prefix', $form_state->getValue('team_prefix')) ->set('channelid', $form_state->getValue('channelid')) + ->set('enablefilter', $form_state->getValue('enablefilter')) ->save(); }