Skip to content

Commit 823cf0d

Browse files
Resolved the validation for monitized enabled org for enabling teams for ApigeeX and edge (#940)
Co-authored-by: Dezső BICZÓ <mxr576@users.noreply.github.com>
1 parent 90d4b38 commit 823cf0d

File tree

3 files changed

+135
-12
lines changed

3 files changed

+135
-12
lines changed

modules/apigee_edge_teams/apigee_edge_teams.install

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,21 @@ function apigee_edge_teams_requirements($phase) {
4141
$org_controller = \Drupal::service('apigee_edge.controller.organization');
4242
/* @var \Apigee\Edge\Api\Management\Entity\Organization $organization */
4343
$organization = $org_controller->load($sdk_connector->getOrganization());
44-
if ($organization && !OrganizationFeatures::isCompaniesFeatureAvailable($organization) && OrganizationFeatures::isMonetizationEnabled($organization)) {
45-
$url = [
46-
':url' => 'https://cloud.google.com/apigee/docs/api-platform/get-started/compare-apigee-products#unsupported-apis',
47-
];
48-
$message = ($phase == 'runtime') ?
49-
t("The Teams module functionality is not available for monetization enabled org on Apigee X / Hybrid and should be uninstalled, because <a href=':url' target='_blank'>AppGroup APIs are not supported in Apigee X / Hybrid orgs with monetization enabled</a>.", $url) :
50-
t("The Teams module functionality is not available for monetization enabled org on Apigee X / Hybrid because <a href=':url' target='_blank'>AppGroup APIs are not supported in Apigee X / Hybrid orgs with monetization enabled</a>.", $url);
51-
$requirements['apigee_edge_teams_not_supported'] = [
52-
'title' => t('Apigee Edge Teams'),
53-
'description' => $message,
54-
'severity' => REQUIREMENT_ERROR,
55-
];
44+
if ($organization && $org_controller->isOrganizationApigeeX()) {
45+
// AppGroup APIs are not supported in Apigee X / Hybrid orgs with monetization enabled.
46+
if ($organization->getAddonsConfig() && $organization->getAddonsConfig()->getMonetizationConfig() && TRUE === $organization->getAddonsConfig()->getMonetizationConfig()->getEnabled()) {
47+
$url = [
48+
':url' => 'https://cloud.google.com/apigee/docs/api-platform/publish/organizing-client-app-ownership?hl=en#appgroups-limitations-and-known-issues',
49+
];
50+
$message = ($phase == 'runtime') ?
51+
t("The Teams module functionality is not available for monetization enabled org on Apigee X / Hybrid and should be uninstalled, because <a href=':url' target='_blank'>AppGroup APIs are not supported in Apigee X / Hybrid orgs with monetization enabled</a>.", $url) :
52+
t("The Teams module functionality is not available for monetization enabled org on Apigee X / Hybrid because <a href=':url' target='_blank'>AppGroup APIs are not supported in Apigee X / Hybrid orgs with monetization enabled</a>.", $url);
53+
$requirements['apigee_edge_teams_not_supported'] = [
54+
'title' => t('Apigee Edge Teams'),
55+
'description' => $message,
56+
'severity' => REQUIREMENT_ERROR,
57+
];
58+
}
5659
}
5760
}
5861
catch (\Exception $exception) {

modules/apigee_edge_teams/apigee_edge_teams.services.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ services:
121121
tags:
122122
- { name: event_subscriber }
123123

124+
apigee_edge_teams.validate_apigeexteam_enabled:
125+
class: Drupal\apigee_edge_teams\EventSubscriber\ValidateApigeeXTeamEnabledSubscriber
126+
arguments: ['@current_user', '@apigee_edge.sdk_connector', '@apigee_edge.controller.organization', '@messenger']
127+
tags:
128+
- {name: event_subscriber}
129+
124130
route.subscriber.apigee_edge_teams.team_app_by_name:
125131
class: Drupal\apigee_edge_teams\Routing\TeamAppByNameRouteAlterSubscriber
126132
tags:
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2023 Google Inc.
5+
*
6+
* This program is free software; you can redistribute it and/or modify it under
7+
* the terms of the GNU General Public License version 2 as published by the
8+
* Free Software Foundation.
9+
*
10+
* This program is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
13+
* License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License along
16+
* with this program; if not, write to the Free Software Foundation, Inc., 51
17+
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18+
*/
19+
20+
namespace Drupal\apigee_edge_teams\EventSubscriber;
21+
22+
use Drupal\apigee_edge\Entity\Controller\OrganizationControllerInterface;
23+
use Drupal\apigee_edge\SDKConnectorInterface;
24+
use Drupal\Core\Messenger\MessengerInterface;
25+
use Drupal\Core\Session\AccountInterface;
26+
use Drupal\Core\StringTranslation\StringTranslationTrait;
27+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
28+
use Symfony\Component\HttpKernel\Event\RequestEvent;
29+
use Symfony\Component\HttpKernel\KernelEvents;
30+
31+
/**
32+
* Validates that Apigee X Team is enabled on every Team page request.
33+
*/
34+
final class ValidateApigeeXTeamEnabledSubscriber implements EventSubscriberInterface {
35+
36+
use StringTranslationTrait;
37+
38+
/**
39+
* The current user.
40+
*
41+
* @var \Drupal\Core\Session\AccountInterface
42+
*/
43+
private AccountInterface $currentUser;
44+
45+
/**
46+
* The SDK connector service.
47+
*
48+
* @var \Drupal\apigee_edge\SDKConnectorInterface
49+
*/
50+
private SDKConnectorInterface $connector;
51+
52+
/**
53+
* The organization controller service.
54+
*
55+
* @var \Drupal\apigee_edge\Entity\Controller\OrganizationControllerInterface
56+
*/
57+
protected OrganizationControllerInterface $orgController;
58+
59+
/**
60+
* The messenger service.
61+
*
62+
* @var \Drupal\Core\Messenger\MessengerInterface
63+
*/
64+
protected MessengerInterface $messenger;
65+
66+
/**
67+
* ValidateApigeeXTeamEnabledSubscriber constructor.
68+
*
69+
* @param \Drupal\Core\Session\AccountInterface $current_user
70+
* The current user.
71+
* @param \Drupal\apigee_edge\SDKConnectorInterface $sdk_connector
72+
* The SDK connector service.
73+
* @param \Drupal\apigee_edge\Entity\Controller\OrganizationControllerInterface $org_controller
74+
* The organization controller service.
75+
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
76+
* The messenger service.
77+
*/
78+
public function __construct(AccountInterface $current_user, SDKConnectorInterface $sdk_connector, OrganizationControllerInterface $org_controller, MessengerInterface $messenger) {
79+
$this->currentUser = $current_user;
80+
$this->connector = $sdk_connector;
81+
$this->orgController = $org_controller;
82+
$this->messenger = $messenger;
83+
}
84+
85+
/**
86+
* If monetization enabled in Apigee X org alert the user.
87+
*
88+
* @param \Symfony\Component\HttpKernel\Event\RequestEvent $event
89+
* The event.
90+
*/
91+
public function validateApigeexTeamEnabled(RequestEvent $event): void {
92+
// Check only for html request and admin users.
93+
if ($this->currentUser->hasPermission('administer modules') && $event->getRequest()->getRequestFormat() === 'html') {
94+
/** @var \Symfony\Component\Routing\Route $current_route */
95+
if (($current_route = $event->getRequest()->get('_route')) && (strpos($current_route, 'entity.team') !== FALSE || strpos($current_route, 'settings.team') !== FALSE)) {
96+
$organization = $this->orgController->load($this->connector->getOrganization());
97+
if ($organization && $this->orgController->isOrganizationApigeeX()) {
98+
if ($organization->getAddonsConfig() && $organization->getAddonsConfig()->getMonetizationConfig() && TRUE === $organization->getAddonsConfig()->getMonetizationConfig()->getEnabled()) {
99+
$this->messenger->addError($this->t('The Teams module functionality is not available for monetization enabled org on Apigee X / Hybrid and should be uninstalled.'));
100+
}
101+
}
102+
}
103+
}
104+
}
105+
106+
/**
107+
* {@inheritdoc}
108+
*/
109+
public static function getSubscribedEvents(): array {
110+
$events[KernelEvents::REQUEST][] = ['validateApigeexTeamEnabled'];
111+
return $events;
112+
}
113+
114+
}

0 commit comments

Comments
 (0)