You are here

class WebformAccountAccess in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Access/WebformAccountAccess.php \Drupal\webform\Access\WebformAccountAccess

Defines the custom access control handler for the user accounts.

Hierarchy

Expanded class hierarchy of WebformAccountAccess

1 file declares its use of WebformAccountAccess
WebformAccountAccessTest.php in tests/src/Unit/Access/WebformAccountAccessTest.php

File

src/Access/WebformAccountAccess.php, line 12

Namespace

Drupal\webform\Access
View source
class WebformAccountAccess {

  /**
   * Check whether the user has 'administer webform' or 'administer webform submission' permission.
   *
   * @param \Drupal\Core\Session\AccountInterface $account
   *   Run access checks for this account.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result.
   */
  public static function checkAdminAccess(AccountInterface $account) {
    return AccessResult::allowedIfHasPermissions($account, [
      'administer webform',
      'administer webform submission',
    ], 'OR');
  }

  /**
   * Check whether the user has 'administer' or 'overview' permission.
   *
   * @param \Drupal\Core\Session\AccountInterface $account
   *   Run access checks for this account.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result.
   */
  public static function checkOverviewAccess(AccountInterface $account) {
    return AccessResult::allowedIfHasPermissions($account, [
      'administer webform',
      'administer webform submission',
      'access webform overview',
    ], 'OR');
  }

  /**
   * Check whether the user has 'overview' with 'create' permission.
   *
   * @param \Drupal\Core\Session\AccountInterface $account
   *   Run access checks for this account.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result.
   */
  public static function checkTemplatesAccess(AccountInterface $account) {
    $condition = $account
      ->hasPermission('access webform overview') && ($account
      ->hasPermission('administer webform') || $account
      ->hasPermission('create webform'));
    return AccessResult::allowedIf($condition)
      ->cachePerPermissions();
  }

  /**
   * Check whether the user can view submissions.
   *
   * @param \Drupal\Core\Session\AccountInterface $account
   *   Run access checks for this account.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result.
   */
  public static function checkSubmissionAccess(AccountInterface $account) {
    return AccessResult::allowedIfHasPermissions($account, [
      'administer webform',
      'administer webform submission',
      'view any webform submission',
    ], 'OR');
  }

  /**
   * Check whether the user can view own submissions.
   *
   * @param \Drupal\Core\Session\AccountInterface $account
   *   Run access checks for this account.
   * @param \Drupal\user\UserInterface $user
   *   The access checked routes' associated user account.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result.
   */
  public static function checkUserSubmissionsAccess(AccountInterface $account, UserInterface $user) {
    $condition = $account
      ->hasPermission('administer webform') || $account
      ->hasPermission('administer webform submission') || $account
      ->hasPermission('view any webform submission') || $account
      ->hasPermission('access webform submission user') && $account
      ->id() === $user
      ->id();
    return AccessResult::allowedIf($condition)
      ->cachePerPermissions();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
WebformAccountAccess::checkAdminAccess public static function Check whether the user has 'administer webform' or 'administer webform submission' permission.
WebformAccountAccess::checkOverviewAccess public static function Check whether the user has 'administer' or 'overview' permission.
WebformAccountAccess::checkSubmissionAccess public static function Check whether the user can view submissions.
WebformAccountAccess::checkTemplatesAccess public static function Check whether the user has 'overview' with 'create' permission.
WebformAccountAccess::checkUserSubmissionsAccess public static function Check whether the user can view own submissions.