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

[#156] Display expired credentials #290

Merged
merged 4 commits into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apigee_edge.module
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,10 @@ function template_preprocess_app_credential(array &$variables) {
];
}
elseif ($def['value_type'] === 'status') {
// Check if expired.
if ($normalized['expiresAt'] !== -1 && \Drupal::time()->getRequestTime() - (int)($normalized['expiresAt'] / 1000) > 0) {
shadcn marked this conversation as resolved.
Show resolved Hide resolved
$value = t('Expired');
}
$variables['primary_wrapper'][$property]['value'] = [
'#type' => 'status_property',
'#value' => $value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
namespace Drupal\apigee_edge_teams\Entity\ListBuilder;

use Drupal\apigee_edge\Entity\ListBuilder\AppListBuilder;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
Expand Down Expand Up @@ -54,11 +55,13 @@ class TeamAppListByTeam extends AppListBuilder implements ContainerInjectionInte
* The render.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack object.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match object.
*/
public function __construct(EntityTypeInterface $entity_type, EntityTypeManagerInterface $entity_type_manager, RendererInterface $render, RequestStack $request_stack, RouteMatchInterface $route_match) {
parent::__construct($entity_type, $entity_type_manager, $render, $request_stack);
public function __construct(EntityTypeInterface $entity_type, EntityTypeManagerInterface $entity_type_manager, RendererInterface $render, RequestStack $request_stack, TimeInterface $time, RouteMatchInterface $route_match) {
parent::__construct($entity_type, $entity_type_manager, $render, $request_stack, $time);
$this->routeMatch = $route_match;
}

Expand All @@ -71,6 +74,7 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
$container->get('entity_type.manager'),
$container->get('renderer'),
$container->get('request_stack'),
$container->get('datetime.time'),
$container->get('current_route_match')
);
}
Expand Down
43 changes: 37 additions & 6 deletions src/Entity/ListBuilder/AppListBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Apigee\Edge\Api\Management\Entity\AppCredential;
use Apigee\Edge\Structure\CredentialProduct;
use Drupal\apigee_edge\Entity\AppInterface;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Entity\EntityInterface;
Expand Down Expand Up @@ -53,6 +54,13 @@ class AppListBuilder extends EdgeEntityListBuilder {
*/
protected $requestStack;

/**
* The time service.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected $time;

/**
* AppListBuilder constructor.
*
Expand All @@ -64,12 +72,15 @@ class AppListBuilder extends EdgeEntityListBuilder {
* The renderer service.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack object.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
*/
public function __construct(EntityTypeInterface $entity_type, EntityTypeManagerInterface $entity_type_manager, RendererInterface $renderer, RequestStack $request_stack) {
public function __construct(EntityTypeInterface $entity_type, EntityTypeManagerInterface $entity_type_manager, RendererInterface $renderer, RequestStack $request_stack, TimeInterface $time) {
parent::__construct($entity_type, $entity_type_manager);
$this->renderer = $renderer;
$this->entityTypeManager = $entity_type_manager;
$this->requestStack = $request_stack;
$this->time = $time;
}

/**
Expand All @@ -80,7 +91,8 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
$entity_type,
$container->get('entity_type.manager'),
$container->get('renderer'),
$container->get('request_stack')
$container->get('request_stack'),
$container->get('datetime.time')
);
}

Expand Down Expand Up @@ -212,10 +224,10 @@ protected function buildWarningRow(AppInterface $app, array &$rows) {

// Display warning sign next to the status if the app's status is
// approved, but:
// - any credentials of the app is in revoked status
// - any credentials of the app is in revoked or expired status
// - any products of any credentials of the app is in revoked or
// pending status.
if ($app->getStatus() === AppInterface::STATUS_APPROVED && ($warnings['revokedCred'] || $warnings['revokedOrPendingCredProduct'])) {
if ($app->getStatus() === AppInterface::STATUS_APPROVED && ($warnings['revokedCred'] || $warnings['revokedOrPendingCredProduct'] || $warnings['expiredCred'])) {
$build['status'] = $rows[$info_row_css_id]['data']['status']['data'];
$build['warning'] = [
'#type' => 'html_tag',
Expand Down Expand Up @@ -246,12 +258,22 @@ protected function buildWarningRow(AppInterface $app, array &$rows) {
'colspan' => count($this->buildHeader()),
];

$items = [];
if ($warnings['revokedCred']) {
$row['data']['info']['data'] = $warnings['revokedCred'];
$items[] = $warnings['revokedCred'];
}
elseif ($warnings['revokedOrPendingCredProduct']) {
$row['data']['info']['data'] = $warnings['revokedOrPendingCredProduct'];
$items[] = $warnings['revokedOrPendingCredProduct'];
}

if ($warnings['expiredCred']) {
kscheirer marked this conversation as resolved.
Show resolved Hide resolved
$items[] = $warnings['expiredCred'];
}

$row['data']['info']['data'] = [
'#theme' => 'item_list',
'#items' => $items,
];
}

$rows[$warning_row_css_id] = $row;
Expand Down Expand Up @@ -302,6 +324,7 @@ protected function checkAppCredentialWarnings(AppInterface $app): array {
$warnings = [];
$warnings['revokedCred'] = FALSE;
$warnings['revokedOrPendingCredProduct'] = FALSE;
$warnings['expiredCred'] = FALSE;

foreach ($app->getCredentials() as $credential) {
if ($credential->getStatus() === AppCredential::STATUS_REVOKED) {
Expand All @@ -316,6 +339,14 @@ protected function checkAppCredentialWarnings(AppInterface $app): array {
}
break;
}

// Check for expired credentials.
if (($expired_date = $credential->getExpiresAt()) && $this->time->getRequestTime() - $expired_date->getTimestamp() > 0) {
$warnings['expiredCred'] = $this->t('At least one of the credentials associated with this @app is expired.', [
'@app' => $this->entityType->getLowercaseLabel(),
]);
}

foreach ($credential->getApiProducts() as $cred_product) {
if ($cred_product->getStatus() == CredentialProduct::STATUS_REVOKED || $cred_product->getStatus() == CredentialProduct::STATUS_PENDING) {
$args = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

use Drupal\apigee_edge\Entity\AppInterface;
use Drupal\apigee_edge\Exception\DeveloperDoesNotExistException;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Component\Utility\Html;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityInterface;
Expand Down Expand Up @@ -75,13 +76,15 @@ class DeveloperAppListBuilderForDeveloper extends AppListBuilder implements Cont
* The render.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack object.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
* @param \Drupal\Core\Session\AccountInterface $current_user
* Currently logged-in user.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match object.
*/
public function __construct(EntityTypeInterface $entity_type, EntityTypeManagerInterface $entity_type_manager, RendererInterface $render, RequestStack $request_stack, AccountInterface $current_user, RouteMatchInterface $route_match) {
parent::__construct($entity_type, $entity_type_manager, $render, $request_stack);
public function __construct(EntityTypeInterface $entity_type, EntityTypeManagerInterface $entity_type_manager, RendererInterface $render, RequestStack $request_stack, TimeInterface $time, AccountInterface $current_user, RouteMatchInterface $route_match) {
parent::__construct($entity_type, $entity_type_manager, $render, $request_stack, $time);
$this->currentUser = $current_user;
$this->routeMatch = $route_match;
}
Expand All @@ -95,6 +98,7 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
$container->get('entity_type.manager'),
$container->get('renderer'),
$container->get('request_stack'),
$container->get('datetime.time'),
$container->get('current_user'),
$container->get('current_route_match')
);
Expand Down