Issue #2832574 by marcoscano, dawehner, hansfn: Grant "view media" permission by default to all users
parent
2cf0f374a3
commit
a3e56b1752
|
@ -5,6 +5,8 @@
|
|||
* Install, uninstall and update hooks for Media module.
|
||||
*/
|
||||
|
||||
use \Drupal\user\RoleInterface;
|
||||
|
||||
/**
|
||||
* Implements hook_install().
|
||||
*/
|
||||
|
@ -17,6 +19,12 @@ function media_install() {
|
|||
foreach ($files as $file) {
|
||||
file_unmanaged_copy($file->uri, $destination, FILE_EXISTS_ERROR);
|
||||
}
|
||||
|
||||
// Grant the "view media" permission to all users by default.
|
||||
if (\Drupal::moduleHandler()->moduleExists('user')) {
|
||||
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['view media']);
|
||||
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['view media']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -56,6 +56,7 @@ class MediaAccessTest extends MediaFunctionalTestBase {
|
|||
$role = Role::load(RoleInterface::AUTHENTICATED_ID);
|
||||
|
||||
// Test 'view media' permission.
|
||||
user_role_revoke_permissions($role->id(), ['view media']);
|
||||
$this->drupalGet('media/' . $media->id());
|
||||
$this->assertCacheContext('user.permissions');
|
||||
$assert_session->statusCodeEquals(403);
|
||||
|
|
|
@ -5,8 +5,6 @@ namespace Drupal\Tests\media\Functional;
|
|||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\media\Entity\Media;
|
||||
use Drupal\system\Tests\Entity\EntityWithUriCacheTagsTestBase;
|
||||
use Drupal\user\Entity\Role;
|
||||
use Drupal\user\RoleInterface;
|
||||
|
||||
/**
|
||||
* Tests the media entity's cache tags.
|
||||
|
@ -25,19 +23,6 @@ class MediaCacheTagsTest extends EntityWithUriCacheTagsTestBase {
|
|||
'media_test_source',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Give anonymous users permission to view media, so that we can
|
||||
// verify the cache tags of cached versions of media items.
|
||||
$user_role = Role::load(RoleInterface::ANONYMOUS_ID);
|
||||
$user_role->grantPermission('view media');
|
||||
$user_role->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue