From dc4015ca53826c5245a20c7b78f50124e04768b0 Mon Sep 17 00:00:00 2001 From: arshad Date: Thu, 15 Oct 2020 11:54:43 +0400 Subject: [PATCH] [#431] Remove app warnings code from profile --- ...per_app.developer_app.collapsible_card.yml | 17 ++-- ...ay.developer_app.developer_app.default.yml | 17 ++-- .../apigee_kickstart_enhancement.module | 89 ------------------- .../apigee_kickstart/includes/apigee.inc | 4 + 4 files changed, 26 insertions(+), 101 deletions(-) diff --git a/config/install/core.entity_view_display.developer_app.developer_app.collapsible_card.yml b/config/install/core.entity_view_display.developer_app.developer_app.collapsible_card.yml index c18c6969..6725440c 100644 --- a/config/install/core.entity_view_display.developer_app.developer_app.collapsible_card.yml +++ b/config/install/core.entity_view_display.developer_app.developer_app.collapsible_card.yml @@ -12,7 +12,7 @@ mode: collapsible_card content: callbackUrl: label: inline - weight: 2 + weight: 3 region: content settings: { } third_party_settings: { } @@ -20,7 +20,7 @@ content: createdAt: type: timestamp_ago label: inline - weight: 4 + weight: 5 region: content settings: future_format: '@interval hence' @@ -28,13 +28,13 @@ content: granularity: 2 third_party_settings: { } credentials: - weight: 3 + weight: 4 region: content settings: { } third_party_settings: { } description: label: inline - weight: 1 + weight: 2 region: content settings: { } third_party_settings: { } @@ -42,7 +42,7 @@ content: lastModifiedAt: type: timestamp_ago label: inline - weight: 5 + weight: 6 region: content settings: future_format: '@interval hence' @@ -52,13 +52,18 @@ content: status: label: hidden type: status_property - weight: 0 + weight: 1 region: content settings: indicator_status_ok: approved indicator_status_warning: '' indicator_status_error: revoked third_party_settings: { } + warnings: + weight: 0 + region: content + settings: { } + third_party_settings: { } hidden: appFamily: true appId: true diff --git a/config/install/core.entity_view_display.developer_app.developer_app.default.yml b/config/install/core.entity_view_display.developer_app.developer_app.default.yml index 73ea000b..fc3fd824 100644 --- a/config/install/core.entity_view_display.developer_app.developer_app.default.yml +++ b/config/install/core.entity_view_display.developer_app.developer_app.default.yml @@ -10,7 +10,7 @@ mode: default content: callbackUrl: label: inline - weight: 2 + weight: 3 region: content settings: { } third_party_settings: { } @@ -18,7 +18,7 @@ content: createdAt: type: timestamp_ago label: inline - weight: 4 + weight: 5 region: content settings: future_format: '@interval hence' @@ -26,13 +26,13 @@ content: granularity: 2 third_party_settings: { } credentials: - weight: 3 + weight: 4 region: content settings: { } third_party_settings: { } description: label: inline - weight: 1 + weight: 2 region: content settings: { } third_party_settings: { } @@ -40,7 +40,7 @@ content: lastModifiedAt: type: timestamp_ago label: inline - weight: 5 + weight: 6 region: content settings: future_format: '@interval hence' @@ -50,13 +50,18 @@ content: status: label: inline type: status_property - weight: 0 + weight: 1 region: content settings: indicator_status_ok: approved indicator_status_warning: '' indicator_status_error: revoked third_party_settings: { } + warnings: + weight: 0 + region: content + settings: { } + third_party_settings: { } hidden: appFamily: true appId: true diff --git a/modules/custom/apigee_kickstart_enhancement/apigee_kickstart_enhancement.module b/modules/custom/apigee_kickstart_enhancement/apigee_kickstart_enhancement.module index 600079ba..643cda6b 100644 --- a/modules/custom/apigee_kickstart_enhancement/apigee_kickstart_enhancement.module +++ b/modules/custom/apigee_kickstart_enhancement/apigee_kickstart_enhancement.module @@ -23,13 +23,9 @@ * Main module file for Apigee Kickstart Enhancement. */ -use Apigee\Edge\Api\Management\Entity\AppCredentialInterface; -use Apigee\Edge\Structure\CredentialProduct; -use Drupal\apigee_edge\Entity\AppInterface; use Drupal\apigee_edge\Entity\EdgeEntityViewBuilder; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; use Drupal\user\UserInterface; @@ -107,37 +103,9 @@ function apigee_kickstart_enhancement_entity_extra_field_info() { ]; } - // Add warnings to app. - foreach (\Drupal::service('apigee_kickstart.enhancer')->getAppEntityTypes() as $entity_type_id => $app_entity_type) { - $fields[$entity_type_id][$entity_type_id]['display']['warnings'] = [ - 'label' => t('Warnings'), - 'weight' => 10, - 'visible' => FALSE, - ]; - } - return $fields; } -/** - * Implements hook_entity_view(). - */ -function apigee_kickstart_enhancement_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) { - $entity_type = $entity->getEntityType(); - if (\Drupal::service('apigee_kickstart.enhancer') - ->isAppEntityType($entity_type)) { - $warnings = _apigee_kickstart_enhancement_check_app_warnings($entity, $entity_type); - if (count($warnings)) { - $build['warnings'] = [ - '#theme' => 'status_messages', - '#message_list' => [ - 'warning' => $warnings, - ], - ]; - } - } -} - /** * Implements hook_ENTITY_TYPE_view(). */ @@ -254,60 +222,3 @@ function _apigee_kickstart_user_extra_fields() { ], ]; } - -/** - * Checks credentials of an app and returns warnings about them. - * - * TODO: Abstract - * \Drupal\apigee_edge\Entity\ListBuilder\AppListBuilder::checkAppCredentialWarnings. - * - * @param \Drupal\apigee_edge\Entity\AppInterface $app - * The app entity to be checked. - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The app entity type. - * - * @return array - * An associative array that contains information about the revoked - * credentials and revoked or pending API products in a credential. - * - * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException - * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException - */ -function _apigee_kickstart_enhancement_check_app_warnings(AppInterface $app, EntityTypeInterface $entity_type) { - $warnings = []; - $warnings['revokedCred'] = FALSE; - $warnings['revokedOrPendingCredProduct'] = FALSE; - $warnings['expiredCred'] = FALSE; - - foreach ($app->getCredentials() as $credential) { - // Check for expired credentials. - if (($expired_date = $credential->getExpiresAt()) && Drupal::time()->getRequestTime() - $expired_date->getTimestamp() > 0) { - $warnings['expiredCred'] = t('At least one of the credentials associated with this @app is expired.', [ - '@app' => mb_strtolower($entity_type->getSingularLabel()), - ]); - } - - if ($credential->getStatus() === AppCredentialInterface::STATUS_APPROVED) { - foreach ($credential->getApiProducts() as $cred_product) { - if ($cred_product->getStatus() == CredentialProduct::STATUS_REVOKED || $cred_product->getStatus() == CredentialProduct::STATUS_PENDING) { - $args = [ - '@app' => mb_strtolower($entity_type->getSingularLabel()), - '@api_product' => mb_strtolower(Drupal::entityTypeManager()->getDefinition('api_product')->getSingularLabel()), - '@status' => $cred_product->getStatus() == CredentialProduct::STATUS_REVOKED ? t('revoked') : t('pending'), - ]; - if (count($app->getCredentials()) === 1) { - /** @var \Drupal\apigee_edge\Entity\ApiProductInterface $apiProduct */ - $api_product = Drupal::entityTypeManager()->getStorage('api_product')->load($cred_product->getApiproduct()); - $args['%name'] = $api_product->label(); - $warnings['revokedOrPendingCredProduct'] = t('%name @api_product associated with this @app is in @status status.', $args); - } else { - $warnings['revokedOrPendingCredProduct'] = t('At least one @api_product associated with one of the credentials of this @app is in @status status.', $args); - } - break; - } - } - } - } - - return array_filter($warnings); -} diff --git a/themes/custom/apigee_kickstart/includes/apigee.inc b/themes/custom/apigee_kickstart/includes/apigee.inc index d9543893..a5830538 100644 --- a/themes/custom/apigee_kickstart/includes/apigee.inc +++ b/themes/custom/apigee_kickstart/includes/apigee.inc @@ -102,6 +102,10 @@ function apigee_kickstart_preprocess_apigee_entity__app(array &$variables) { function apigee_kickstart_preprocess_app_credential(&$variables) { // Render the consumerKey and the consumerSecret as secret fields. foreach (['consumerKey', 'consumerSecret'] as $field_name) { + if (empty($variables['primary_wrapper'][$field_name]['value']['#value'])) { + continue; + } + $variables['primary_wrapper'][$field_name]['value'] = [ '#type' => 'secret', '#value' => $variables['primary_wrapper'][$field_name]['value']['#value'],