-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '3.x' into app_credential_warnings_bigpipe
- Loading branch information
Showing
4 changed files
with
137 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
modules/apigee_edge_teams/src/EventSubscriber/ValidateApigeeXTeamEnabledSubscriber.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?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\apigee_edge_teams\EventSubscriber; | ||
|
||
use Drupal\apigee_edge\Entity\Controller\OrganizationControllerInterface; | ||
use Drupal\apigee_edge\SDKConnectorInterface; | ||
use Drupal\Core\Messenger\MessengerInterface; | ||
use Drupal\Core\Session\AccountInterface; | ||
use Drupal\Core\StringTranslation\StringTranslationTrait; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\HttpKernel\Event\RequestEvent; | ||
use Symfony\Component\HttpKernel\KernelEvents; | ||
|
||
/** | ||
* Validates that Apigee X Team is enabled on every Team page request. | ||
*/ | ||
final class ValidateApigeeXTeamEnabledSubscriber implements EventSubscriberInterface { | ||
|
||
use StringTranslationTrait; | ||
|
||
/** | ||
* The current user. | ||
* | ||
* @var \Drupal\Core\Session\AccountInterface | ||
*/ | ||
private AccountInterface $currentUser; | ||
|
||
/** | ||
* The SDK connector service. | ||
* | ||
* @var \Drupal\apigee_edge\SDKConnectorInterface | ||
*/ | ||
private SDKConnectorInterface $connector; | ||
|
||
/** | ||
* The organization controller service. | ||
* | ||
* @var \Drupal\apigee_edge\Entity\Controller\OrganizationControllerInterface | ||
*/ | ||
protected OrganizationControllerInterface $orgController; | ||
|
||
/** | ||
* The messenger service. | ||
* | ||
* @var \Drupal\Core\Messenger\MessengerInterface | ||
*/ | ||
protected MessengerInterface $messenger; | ||
|
||
/** | ||
* ValidateApigeeXTeamEnabledSubscriber constructor. | ||
* | ||
* @param \Drupal\Core\Session\AccountInterface $current_user | ||
* The current user. | ||
* @param \Drupal\apigee_edge\SDKConnectorInterface $sdk_connector | ||
* The SDK connector service. | ||
* @param \Drupal\apigee_edge\Entity\Controller\OrganizationControllerInterface $org_controller | ||
* The organization controller service. | ||
* @param \Drupal\Core\Messenger\MessengerInterface $messenger | ||
* The messenger service. | ||
*/ | ||
public function __construct(AccountInterface $current_user, SDKConnectorInterface $sdk_connector, OrganizationControllerInterface $org_controller, MessengerInterface $messenger) { | ||
$this->currentUser = $current_user; | ||
$this->connector = $sdk_connector; | ||
$this->orgController = $org_controller; | ||
$this->messenger = $messenger; | ||
} | ||
|
||
/** | ||
* If monetization enabled in Apigee X org alert the user. | ||
* | ||
* @param \Symfony\Component\HttpKernel\Event\RequestEvent $event | ||
* The event. | ||
*/ | ||
public function validateApigeexTeamEnabled(RequestEvent $event): void { | ||
// Check only for html request and admin users. | ||
if ($this->currentUser->hasPermission('administer modules') && $event->getRequest()->getRequestFormat() === 'html') { | ||
/** @var \Symfony\Component\Routing\Route $current_route */ | ||
if (($current_route = $event->getRequest()->get('_route')) && (strpos($current_route, 'entity.team') !== FALSE || strpos($current_route, 'settings.team') !== FALSE)) { | ||
$organization = $this->orgController->load($this->connector->getOrganization()); | ||
if ($organization && $this->orgController->isOrganizationApigeeX()) { | ||
if ($organization->getAddonsConfig() && $organization->getAddonsConfig()->getMonetizationConfig() && TRUE === $organization->getAddonsConfig()->getMonetizationConfig()->getEnabled()) { | ||
$this->messenger->addError($this->t('The Teams module functionality is not available for monetization enabled org on Apigee X / Hybrid and should be uninstalled.')); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function getSubscribedEvents(): array { | ||
$events[KernelEvents::REQUEST][] = ['validateApigeexTeamEnabled']; | ||
return $events; | ||
} | ||
|
||
} |