Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation for monetized enabled org for enabling teams for ApigeeX #448

Merged
merged 7 commits into from
Oct 4, 2023
53 changes: 53 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,56 @@ 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() || TRUE === $organization->getAddonsConfig()->getMonetizationConfig()->getEnabled()) {
$url = [
':url' => 'https://cloud.google.com/apigee/docs/api-platform/get-started/compare-apigee-products#unsupported-apis',
];
$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,
];
}
} else {
// Edge company APIs are not supported in Apigee Hybrid orgs.
if ($organization && !OrganizationFeatures::isCompaniesFeatureAvailable($organization)) {
shishir-intelli marked this conversation as resolved.
Show resolved Hide resolved
$url = [
':url' => 'https://cloud.google.com/apigee/docs/api-platform/get-started/compare-apigee-products#unsupported-apis',
];
$message = ($phase == 'runtime') ?
t("The Apigee Monetization Teams module functionality is not available for your org and should be uninstalled, because <a href=':url' target='_blank'>Edge company APIs are not supported for Apigee Hybrid orgs</a>.", $url) :
shishir-intelli marked this conversation as resolved.
Show resolved Hide resolved
t("The Apigee Monetization Teams module functionality is not available for your org because <a href=':url' target='_blank'>Edge company APIs are not supported for Apigee Hybrid orgs</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;
}