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

Remove app warnings code from apigee_kickstart_enhancement.module #431

Closed
VladimirAus opened this issue Sep 29, 2020 · 3 comments · Fixed by #438
Closed

Remove app warnings code from apigee_kickstart_enhancement.module #431

VladimirAus opened this issue Sep 29, 2020 · 3 comments · Fixed by #438
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@VladimirAus
Copy link

Description

Warnings only present when profile is present making module is not fully functional.

Screen Shot 2020-09-29 at 6 30 15 pm

Steps to Reproduce

  1. Invalidate one of the APIs used by the application.
  2. Warning only visible when installation profile is enable

Proposal

Move the code from kickstart into the apigee edge module:

  • // 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,
    ],
    ];
    }
    }
    }
  • /**
    * 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);
    }

Apigee edge task: apigee/apigee-edge-drupal#492

@VladimirAus VladimirAus added the enhancement New feature or request label Sep 29, 2020
@shadcn
Copy link
Contributor

shadcn commented Sep 29, 2020

@VladimirAus We're actually reworking this bit.

In apigee/apigee-edge-drupal#446 we removed the warning for revoked credentials. See @cnovak comment below:

Currently the system will show a warning for apps that have revoked credentials. This should not be considered a warning state since revoking credentials is part of the maintenance of an app.

We need to update this kickstart now.

@arunz6161
Copy link
Collaborator

After fix in apigee/apigee-edge-drupal#492 , remove the warnings from kickstart.

@arunz6161 arunz6161 added this to the 8.x-1.22 milestone Sep 29, 2020
@shadcn
Copy link
Contributor

shadcn commented Sep 30, 2020

@VladimirAus we are going to handle all app warnings in apigee_edge and remove the code from kickstart. I'll update the ticket to reflect this.

Thank you for your help on this. Appreciate it.

@shadcn shadcn changed the title Application warning should be moved to apigee edge module Remove app warnings code from apigee_kickstart_enhancement.module Sep 30, 2020
shadcn added a commit to shadcn/apigee-devportal-kickstart-drupal that referenced this issue Oct 15, 2020
shadcn added a commit to shadcn/apigee-devportal-kickstart-drupal that referenced this issue Oct 15, 2020
arlina-espinoza added a commit to shadcn/apigee-devportal-kickstart-drupal that referenced this issue Nov 4, 2020
arlina-espinoza added a commit to shadcn/apigee-devportal-kickstart-drupal that referenced this issue Nov 4, 2020
arlina-espinoza added a commit that referenced this issue Nov 4, 2020
* [#431] Remove app warnings code from profile

* [#431] Add an update hook to enable the warnings field

* [#431] Require apigee_edge ^1.18

Co-authored-by: Arlina Espinoza Rhoton <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants