Skip to content

Commit

Permalink
Validation for monetized enabled org for enabling teams for ApigeeX (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
shishir-intelli authored Oct 4, 2023
1 parent 93939d0 commit 9b66c9a
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions modules/apigee_m10n_teams/apigee_m10n_teams.install
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,41 @@ function apigee_m10n_teams_install() {
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, MonetizationTeamsInterface::DEFAULT_AUTHENTICATED_PERMISSIONS);
}
}

/**
* Implements hook_requirements().
*/
function apigee_m10n_teams_requirements($phase) {
$requirements = [];

if ($phase == 'install' || $phase == 'runtime') {
try {
/** @var \Drupal\apigee_edge\SDKConnectorInterface $sdk_connector */
$sdk_connector = \Drupal::service('apigee_edge.sdk_connector');
$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 && $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 Apigee Monetization 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) :
t("The Apigee Monetization 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);
$requirements['apigee_edge_teams_not_supported'] = [
'title' => t('Apigee Edge Teams'),
'description' => $message,
'severity' => REQUIREMENT_ERROR,
];
}
}
}
catch (\Exception $exception) {
// Do nothing if connection to Edge is not available.
}
}

return $requirements;
}

0 comments on commit 9b66c9a

Please sign in to comment.