Skip to content

Commit

Permalink
Enhancements for adding filter with ChannelId on condition (#1001)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
kedarkhaire and shishir-intelli authored Dec 5, 2023
1 parent c164633 commit 374230e
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
15 changes: 15 additions & 0 deletions modules/apigee_edge_teams/apigee_edge_teams.install
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
langcode: en
team_prefix: ''
channelid: ''
enablefilter: ''
entity_label_singular: ''
entity_label_plural: ''
cache_expiration: 900
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)'
Expand Down
23 changes: 23 additions & 0 deletions modules/apigee_edge_teams/src/Entity/Controller/TeamController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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;
}

}
10 changes: 9 additions & 1 deletion modules/apigee_edge_teams/src/Form/TeamAliasForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit 374230e

Please sign in to comment.