diff --git a/modules/apigee_edge_teams/apigee_edge_teams.install b/modules/apigee_edge_teams/apigee_edge_teams.install index a3191e3bb..d0a83c205 100644 --- a/modules/apigee_edge_teams/apigee_edge_teams.install +++ b/modules/apigee_edge_teams/apigee_edge_teams.install @@ -41,18 +41,21 @@ function apigee_edge_teams_requirements($phase) { $org_controller = \Drupal::service('apigee_edge.controller.organization'); /* @var \Apigee\Edge\Api\Management\Entity\Organization $organization */ $organization = $org_controller->load($sdk_connector->getOrganization()); - if ($organization && !OrganizationFeatures::isCompaniesFeatureAvailable($organization) && OrganizationFeatures::isMonetizationEnabled($organization)) { - $url = [ - ':url' => 'https://cloud.google.com/apigee/docs/api-platform/get-started/compare-apigee-products#unsupported-apis', - ]; - $message = ($phase == 'runtime') ? - t("The Teams module functionality is not available for monetization enabled org on Apigee X / Hybrid and should be uninstalled, because AppGroup APIs are not supported in Apigee X / Hybrid orgs with monetization enabled.", $url) : - t("The Teams module functionality is not available for monetization enabled org on Apigee X / Hybrid because AppGroup APIs are not supported in Apigee X / Hybrid orgs with monetization enabled.", $url); - $requirements['apigee_edge_teams_not_supported'] = [ - 'title' => t('Apigee Edge Teams'), - 'description' => $message, - 'severity' => REQUIREMENT_ERROR, - ]; + if ($organization && $org_controller->isOrganizationApigeeX()) { + // AppGroup APIs are not supported in Apigee X / Hybrid orgs with monetization enabled. + if ($organization->getAddonsConfig() && $organization->getAddonsConfig()->getMonetizationConfig() && TRUE === $organization->getAddonsConfig()->getMonetizationConfig()->getEnabled()) { + $url = [ + ':url' => 'https://cloud.google.com/apigee/docs/api-platform/publish/organizing-client-app-ownership?hl=en#appgroups-limitations-and-known-issues', + ]; + $message = ($phase == 'runtime') ? + t("The Teams module functionality is not available for monetization enabled org on Apigee X / Hybrid and should be uninstalled, because AppGroup APIs are not supported in Apigee X / Hybrid orgs with monetization enabled.", $url) : + t("The Teams module functionality is not available for monetization enabled org on Apigee X / Hybrid because AppGroup APIs are not supported in Apigee X / Hybrid orgs with monetization enabled.", $url); + $requirements['apigee_edge_teams_not_supported'] = [ + 'title' => t('Apigee Edge Teams'), + 'description' => $message, + 'severity' => REQUIREMENT_ERROR, + ]; + } } } catch (\Exception $exception) { diff --git a/modules/apigee_edge_teams/apigee_edge_teams.services.yml b/modules/apigee_edge_teams/apigee_edge_teams.services.yml index 0db1d3f96..6e7729129 100644 --- a/modules/apigee_edge_teams/apigee_edge_teams.services.yml +++ b/modules/apigee_edge_teams/apigee_edge_teams.services.yml @@ -121,6 +121,12 @@ services: tags: - { name: event_subscriber } + apigee_edge_teams.validate_apigeexteam_enabled: + class: Drupal\apigee_edge_teams\EventSubscriber\ValidateApigeeXTeamEnabledSubscriber + arguments: ['@current_user', '@apigee_edge.sdk_connector', '@apigee_edge.controller.organization', '@messenger'] + tags: + - {name: event_subscriber} + route.subscriber.apigee_edge_teams.team_app_by_name: class: Drupal\apigee_edge_teams\Routing\TeamAppByNameRouteAlterSubscriber tags: diff --git a/modules/apigee_edge_teams/src/Commands/ApigeeEdgeCommands.php b/modules/apigee_edge_teams/src/Commands/ApigeeEdgeCommands.php index 508af339b..d1b4fc09d 100644 --- a/modules/apigee_edge_teams/src/Commands/ApigeeEdgeCommands.php +++ b/modules/apigee_edge_teams/src/Commands/ApigeeEdgeCommands.php @@ -49,9 +49,9 @@ public function __construct(CliServiceInterface $cli_service = NULL) { /** * Team Member synchronization. * - * @command apigee-edge-teams:sync + * @command apigee-edge:teams-sync * - * @usage drush apigee-edge-teams:sync + * @usage drush apigee-edge:teams-sync * Starts the team member synchronization. */ public function sync() { diff --git a/modules/apigee_edge_teams/src/EventSubscriber/ValidateApigeeXTeamEnabledSubscriber.php b/modules/apigee_edge_teams/src/EventSubscriber/ValidateApigeeXTeamEnabledSubscriber.php new file mode 100644 index 000000000..2b2129f93 --- /dev/null +++ b/modules/apigee_edge_teams/src/EventSubscriber/ValidateApigeeXTeamEnabledSubscriber.php @@ -0,0 +1,114 @@ +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; + } + +}