Verified Commit a94c3963 authored by godotislate's avatar godotislate
Browse files

fix: #3560719 Add [#NoDiscard] to AccessResult methods or make them chainable

By: catch
By: andypost
By: longwave
By: benjifisher
parent fe7b094e
Loading
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -279,6 +279,7 @@ public function cachePerUser() {
  /**
   * {@inheritdoc}
   */
  #[\NoDiscard]
  public function orIf(AccessResultInterface $other) {
    $merge_other = FALSE;
    // $other's cacheability metadata is merged if $merge_other gets set to TRUE
@@ -340,6 +341,7 @@ public function orIf(AccessResultInterface $other) {
  /**
   * {@inheritdoc}
   */
  #[\NoDiscard]
  public function andIf(AccessResultInterface $other) {
    // The other access result's cacheability metadata is merged if $merge_other
    // gets set to TRUE. It gets set to TRUE in one case: if the other access
+2 −0
Original line number Diff line number Diff line
@@ -79,6 +79,7 @@ public function isNeutral();
   *
   * @return static
   */
  #[\NoDiscard]
  public function orIf(AccessResultInterface $other);

  /**
@@ -103,6 +104,7 @@ public function orIf(AccessResultInterface $other);
   *
   * @return static
   */
  #[\NoDiscard]
  public function andIf(AccessResultInterface $other);

}
+1 −1
Original line number Diff line number Diff line
@@ -127,7 +127,7 @@ protected function checkAccess(EntityInterface $entity, $operation, AccountInter
          $entity_access = $entity->access('view', $account, TRUE);
          if (!$entity->isDefaultRevision()) {
            $media_storage = $this->entityTypeManager->getStorage($entity->getEntityTypeId());
            $entity_access->andIf($this->access($media_storage->load($entity->id()), 'view', $account, TRUE));
            $entity_access = $entity_access->andIf($this->access($media_storage->load($entity->id()), 'view', $account, TRUE));
          }

          return AccessResult::allowed()->cachePerPermissions()->andIf($entity_access);
+1 −1
Original line number Diff line number Diff line
@@ -132,7 +132,7 @@ public function testMediaAccess(): void {
    $this->assertCacheContext('user');
    $assert_session->statusCodeEquals(200);
    $this->drupalGet('media/' . $user_media->id() . '/revisions/' . $previous_revision . '/view');
    $this->assertCacheContext('user.permissions');
    $this->assertCacheContext('user');
    $assert_session->statusCodeEquals(200);
    $role->revokePermission('view own unpublished media')->save();
    $this->drupalGet('media/' . $user_media->id() . '/revisions/' . $user_media->getRevisionId() . '/view');