Skip to content
Snippets Groups Projects
Commit 9c240f96 authored by catch's avatar catch
Browse files

Issue #2905748 by vaplas: MediaAccessControlHandler does not provide a helpful...

Issue #2905748 by vaplas: MediaAccessControlHandler does not provide a helpful reason for when access is denied for the view operation
parent c3f080e7
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -23,9 +23,13 @@ protected function checkAccess(EntityInterface $entity, $operation, AccountInter ...@@ -23,9 +23,13 @@ protected function checkAccess(EntityInterface $entity, $operation, AccountInter
$is_owner = ($account->id() && $account->id() === $entity->getOwnerId()); $is_owner = ($account->id() && $account->id() === $entity->getOwnerId());
switch ($operation) { switch ($operation) {
case 'view': case 'view':
return AccessResult::allowedIf($account->hasPermission('view media') && $entity->isPublished()) $access_result = AccessResult::allowedIf($account->hasPermission('view media') && $entity->isPublished())
->cachePerPermissions() ->cachePerPermissions()
->addCacheableDependency($entity); ->addCacheableDependency($entity);
if (!$access_result->isAllowed()) {
$access_result->setReason("The 'view media' permission is required and the media item must be published.");
}
return $access_result;
case 'update': case 'update':
if ($account->hasPermission('update any media')) { if ($account->hasPermission('update any media')) {
......
...@@ -60,6 +60,8 @@ public function testMediaAccess() { ...@@ -60,6 +60,8 @@ public function testMediaAccess() {
$this->drupalGet('media/' . $media->id()); $this->drupalGet('media/' . $media->id());
$this->assertCacheContext('user.permissions'); $this->assertCacheContext('user.permissions');
$assert_session->statusCodeEquals(403); $assert_session->statusCodeEquals(403);
$access_result = $media->access('view', NULL, TRUE);
$this->assertSame("The 'view media' permission is required and the media item must be published.", $access_result->getReason());
$this->grantPermissions($role, ['view media']); $this->grantPermissions($role, ['view media']);
$this->drupalGet('media/' . $media->id()); $this->drupalGet('media/' . $media->id());
$this->assertCacheContext('user.permissions'); $this->assertCacheContext('user.permissions');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment