tapis_auth-1.4.1-alpha2/tapis_auth.module

tapis_auth.module
<?php

/**
 * @file
 * This file implements some of the hooks used by the tapis_auth module.
 *
 *  Tapis_auth.module.
 */

use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\user\UserInterface;

/**
 * Implements hook_help().
 */
function tapis_auth_help($route_name, RouteMatchInterface $route_match)
{
  switch ($route_name) {
    // Main module help for the tapis_auth module.
    case 'help.page.tapis_auth':
      return '<p>' . t('This module implements the Tapis authenticator service for Drupal, enabling site users to securely authenticate with Tapis API services.<br/><br/>Although Drupal users do not directly interact with this module, other Tapis modules (e.g., Tapis apps, Tapis jobs, Tapis systems, etc.) use this module to perform Tapis operations on behalf of site users (e.g., creating apps, submitting jobs, etc.).') . '</p>';
  }
}

/**
 * Implements hook_user_cancel().
 *
 * When a user account is cancelled,
 * this hook will delete all of their stored Tapis tokens.
 */
function tapis_auth_user_cancel($edit, UserInterface $account, $method)
{
  // Delete tokens.
  $storage = \Drupal::entityTypeManager()->getStorage('tapis_token');
  $tapis_token_ids = $storage->getQuery()
    ->condition('uid', $account->id())
    ->accessCheck(FALSE)
    ->execute();
  $tapis_tokens = $storage->loadMultiple($tapis_token_ids);
  $storage->delete($tapis_tokens);
}

/**
 * Implements hook_ENTITY_TYPE_predelete() for user entities.
 *
 * When a user is deleted, delete all of their stored Tapis tokens.
 */
function tapis_auth_user_predelete(UserInterface $account)
{
  // Delete tokens.
  $storage = \Drupal::entityTypeManager()->getStorage('tapis_token');
  $tapis_token_ids = $storage->getQuery()
    ->accessCheck(FALSE)
    ->condition('uid', $account->id())
    ->execute();
  $tapis_tokens = $storage->loadMultiple($tapis_token_ids);
  $storage->delete($tapis_tokens);
}

/**
 * Implements hook_node_view() for adding the "GetTenantStatus" form to the tenant node's page.
 * 
 * @param array $build
 * @param \Drupal\Core\Entity\EntityInterface $entity
 * @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display
 * @param string $view_mode
 */
function tapis_auth_node_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode)
{
  // Check if the entity type is 'tapis_tenant'.
  if ($entity->bundle() !== 'tapis_tenant') {
    return;
  }

  // Get the current user.
  $currentUser = \Drupal::currentUser();
  // Check if the current user has permission to administer tapis tenants
  // or if they are the owner of the tenant.
  /** @var \Drupal\node\Entity\Node $entity */
  if ($currentUser->hasPermission('administer tapis tenant') || $entity->getOwnerId() === $currentUser->id()) {
    // Get the form builder service.
    $formBuilder = \Drupal::service('form_builder');

    // Build the form using the form builder service.
    $form = $formBuilder->getForm('Drupal\tapis_auth\Form\GetTapisTenantStatusForm', $entity);

    // Add the form to the entity build.
    $build['test_credentials_form'] = $form;
    $build['test_credentials_form']['#weight'] = 102;
  }
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc