You are here

class UpdateThreadAccess in Opigno messaging 3.x

Check if the user can edit the given PM thread.

@package Drupal\opigno_messaging\Access

Hierarchy

Expanded class hierarchy of UpdateThreadAccess

1 string reference to 'UpdateThreadAccess'
opigno_messaging.services.yml in ./opigno_messaging.services.yml
opigno_messaging.services.yml
1 service uses UpdateThreadAccess
opigno_messaging.update_thread_access_check in ./opigno_messaging.services.yml
Drupal\opigno_messaging\Access\UpdateThreadAccess

File

src/Access/UpdateThreadAccess.php, line 17

Namespace

Drupal\opigno_messaging\Access
View source
class UpdateThreadAccess implements AccessInterface {

  /**
   * Checks the access.
   *
   * @param \Symfony\Component\Routing\Route $route
   *   The route to check the access to.
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The currently logged in user's account.
   * @param \Drupal\private_message\Entity\PrivateMessageThreadInterface $private_message_thread
   *   The thread to check the access to.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result.
   */
  public function access(Route $route, AccountInterface $account, PrivateMessageThreadInterface $private_message_thread) : AccessResultInterface {
    if (!$private_message_thread
      ->hasField('field_author')) {
      return AccessResult::forbidden();
    }

    // Only group discussions can be edited be the author.
    $owner = (int) $private_message_thread
      ->get('field_author')
      ->getString();
    $is_group = count($private_message_thread
      ->getMembers()) > 2;
    return AccessResult::allowedIf($is_group && $owner === (int) $account
      ->id());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
UpdateThreadAccess::access public function Checks the access.