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 2 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() - intval($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
25 changes: 22 additions & 3 deletions src/Entity/ListBuilder/AppListBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ protected function buildWarningRow(AppInterface $app, array &$rows) {
// - any credentials of the app is in revoked status
shadcn marked this conversation as resolved.
Show resolved Hide resolved
// - 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 +246,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 +312,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 +327,14 @@ protected function checkAppCredentialWarnings(AppInterface $app): array {
}
break;
}

// Check for expired credentials.
if (($expired_date = $credential->getExpiresAt()) && \Drupal::time()->getRequestTime() - intval($expired_date->getTimestamp() / 1000) > 0) {
shadcn marked this conversation as resolved.
Show resolved Hide resolved
shadcn marked this conversation as resolved.
Show resolved Hide resolved
$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