Skip to content

Commit

Permalink
Merge branch '3.x' into issue/948
Browse files Browse the repository at this point in the history
  • Loading branch information
divya-intelli authored Nov 20, 2023
2 parents 503539b + 56e8d62 commit f86e71d
Show file tree
Hide file tree
Showing 34 changed files with 844 additions and 43 deletions.
22 changes: 17 additions & 5 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ env:
APIGEE_EDGE_INSTANCE_TYPE: ${{ secrets.APIGEE_EDGE_INSTANCE_TYPE }}
APIGEE_INTEGRATION_ENABLE: ${{ secrets.APIGEE_INTEGRATION_ENABLE }}
APIGEE_EDGE_ENDPOINT: ${{ secrets.APIGEE_EDGE_ENDPOINT }}
APIGEE_EDGE_ACCOUNT_JSON_KEY: ${{ secrets.APIGEE_EDGE_ACCOUNT_JSON_KEY }}
APIGEE_EDGE_HYBRID_ENDPOINT: ${{ secrets.APIGEE_EDGE_HYBRID_ENDPOINT }}
APIGEE_EDGE_HYBRID_ORGANIZATION: ${{ secrets.APIGEE_EDGE_HYBRID_ORGANIZATION }}
BROWSERTEST_OUTPUT_DIRECTORY: "sites/simpletest/browser_output"
BROWSERTEST_OUTPUT_BASE_URL: ""
MINK_DRIVER_ARGS_WEBDRIVER: '["chrome", { "chromeOptions": { "w3c": false } }, "http://127.0.0.1:9515/wd/hub"]'
Expand All @@ -24,7 +27,7 @@ jobs:

runs-on: ubuntu-latest

name: "PHP ${{ matrix.php-version }} | Drupal ${{ matrix.drupal-core }}"
name: "PHP ${{ matrix.php-version }} | Drupal ${{ matrix.drupal-core }} | ${{ matrix.instance-type }}"
strategy:
fail-fast: false
matrix:
Expand All @@ -34,6 +37,9 @@ jobs:
drupal-core:
# Should update the following as the minimum supported version from Drupal.org
- "10.1.x"
instance-type:
- "Edge"
- "X"

steps:

Expand Down Expand Up @@ -105,11 +111,17 @@ jobs:
vendor/bin/drush en apigee_edge -y
vendor/bin/drush rs 8000 &
- name: "PHPCS"
- name: "PHPCS and setting up Apigee X environment"
if: ${{ matrix.instance-type == 'X' }}
run: |
cd drupal
cp modules/contrib/apigee_edge/phpcs.xml.dist .
vendor/bin/phpcs --standard=./phpcs.xml.dist modules/contrib/apigee_edge -p -s -n --colors
# Setting environment variables to run Apigee X tests
echo "APIGEE_EDGE_INSTANCE_TYPE=hybrid" >> $GITHUB_ENV
echo "APIGEE_EDGE_ORGANIZATION=$APIGEE_EDGE_HYBRID_ORGANIZATION" >> $GITHUB_ENV
echo "APIGEE_EDGE_ENDPOINT=$APIGEE_EDGE_HYBRID_ENDPOINT" >> $GITHUB_ENV
composer show > composer-show.txt
- name: "Drupal check"
run: |
Expand All @@ -134,20 +146,20 @@ jobs:
run: |
cd drupal
cp modules/contrib/apigee_edge/phpunit.core.xml.dist core/phpunit.xml
vendor/bin/phpunit -c core --verbose --color --group apigee_edge --testsuite unit,kernel,functional,functional-javascript --debug --coverage-clover /tmp/coverage.xml modules/contrib/apigee_edge
vendor/bin/phpunit -c core --verbose --color --group apigee_edge --testsuite unit,kernel,functional,functional-javascript --debug --coverage-clover /tmp/coverage_${{ matrix.instance-type }}.xml modules/contrib/apigee_edge
- name: Artifacts
if: failure()
uses: actions/upload-artifact@v3
with:
name: browser-output-${{ matrix.php-version }}-${{ matrix.drupal-core }}-artifact
name: browser-output-${{ matrix.php-version }}-${{ matrix.drupal-core }}-${{ matrix.instance-type }}-artifact
path: drupal/sites/simpletest/browser_output/*

- name: Upload coverage to Codecov
if: ${{ matrix.drupal-core == '9.5.x' && matrix.php-version == '8.1' }}
uses: codecov/codecov-action@v3
with:
files: /tmp/coverage.xml
files: /tmp/coverage_${{ matrix.instance-type }}.xml
name: codecov-umbrella
fail_ci_if_error: true
verbose: true
7 changes: 1 addition & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"require": {
"php": "~8.1.0 || ~8.2.0",
"ext-json": "*",
"apigee/apigee-client-php": "^3.0.1",
"apigee/apigee-client-php": "~3.0.2",
"drupal/core": "^10.1",
"drupal/entity": "^1.0",
"drupal/key": "^1.8",
Expand All @@ -33,11 +33,6 @@
"services": {
"drush.services.yml": "^12"
}
},
"patches": {
"drupal/core": {
"Add a method to access the original property": "https://www.drupal.org/files/issues/2023-07-22/2839195-105.patch"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

namespace Drupal\Tests\apigee_edge_actions\Kernel;

use Drupal\apigee_edge\Plugin\EdgeKeyTypeInterface;
use Drupal\Core\Database\Database;
use Drupal\dblog\Controller\DbLogController;
use Drupal\Tests\apigee_mock_api_client\Traits\ApigeeMockApiClientHelperTrait;
Expand Down Expand Up @@ -67,6 +68,11 @@ class ApigeeEdgeActionsRulesKernelTestBase extends RulesKernelTestBase {
* {@inheritdoc}
*/
protected function setUp(): void {
// Skipping the test if instance type is Public.
$instance_type = getenv('APIGEE_EDGE_INSTANCE_TYPE');
if (!empty($instance_type) && $instance_type === EdgeKeyTypeInterface::INSTANCE_TYPE_HYBRID) {
$this->markTestSkipped('This test suite is expecting a PUBLIC instance type.');
}
parent::setUp();

$this->storage = $this->container->get('entity_type.manager')->getStorage('rules_reaction_rule');
Expand Down
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

/**
* Copyright 2023 Google Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 2 as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

namespace Drupal\Tests\apigee_edge_teams\Functional\ApigeeX;

use Drupal\apigee_edge\OauthTokenFileStorage;
use Drupal\Tests\apigee_edge\Functional\ApigeeX\ApigeeEdgeFunctionalTestBase;

/**
* Base class for Apigee Edge Teams functional tests.
*/
abstract class ApigeeEdgeTeamsFunctionalTestBase extends ApigeeEdgeFunctionalTestBase {

/**
* {@inheritdoc}
*/
protected static $modules = [
'apigee_edge_teams',
];

/**
* Stores pre-configured token storage service for testing.
*/
protected function storeToken() {
// Storing the token for Appigeex Hybrid Org.
$this->testTokenData = [
'access_token' => mb_strtolower($this->randomMachineName(32)),
'token_type' => 'bearer',
'expires_in' => 300,
'refresh_token' => mb_strtolower($this->randomMachineName(32)),
'scope' => 'create',
];
$storage = $this->tokenStorage();

// Save the token.
$storage->saveToken($this->testTokenData);
}

/**
* Returns a pre-configured token storage service for testing.
*
* @param bool $rebuild
* Enforces rebuild of the container and with the the token storage
* service.
*
* @return \Drupal\apigee_edge\OauthTokenFileStorage
* The configured and initialized OAuth file token storage service.
*
* @throws \Exception
*/
private function tokenStorage(bool $rebuild = FALSE): OauthTokenFileStorage {
$config = $this->config('apigee_edge.auth');
$config->set('oauth_token_storage_location', OauthTokenFileStorage::DEFAULT_DIRECTORY)->save();
if ($rebuild) {
$this->container->get('kernel')->rebuildContainer();
}
return $this->container->get('apigee_edge.authentication.oauth_token_storage');
}

}
Loading

0 comments on commit f86e71d

Please sign in to comment.