commit 52ceb062e00c9264083a9e215cfaa3c4f07fed4e Author: Bart Feenstra Date: Tue Jan 14 10:09:10 2014 +0100 foo diff --git a/core/modules/file/lib/Drupal/file/Entity/File.php b/core/modules/file/lib/Drupal/file/Entity/File.php index 816435b..f6616b9 100644 --- a/core/modules/file/lib/Drupal/file/Entity/File.php +++ b/core/modules/file/lib/Drupal/file/Entity/File.php @@ -21,6 +21,7 @@ * id = "file", * label = @Translation("File"), * controllers = { + * "access" = "Drupal\file\FileAccessController", * "storage" = "Drupal\file\FileStorageController", * "view_builder" = "Drupal\Core\Entity\EntityViewBuilder" * }, diff --git a/core/modules/file/lib/Drupal/file/FileAccessController.php b/core/modules/file/lib/Drupal/file/FileAccessController.php new file mode 100644 index 0000000..87267d4 --- /dev/null +++ b/core/modules/file/lib/Drupal/file/FileAccessController.php @@ -0,0 +1,34 @@ +getFileUri()) == 'public')) { + return TRUE; + } + else { + return parent::checkAccess($entity, $operation, $langcode, $account); + } + } + +} diff --git a/core/modules/rest/lib/Drupal/rest/Tests/FileTest.php b/core/modules/rest/lib/Drupal/rest/Tests/FileTest.php new file mode 100644 index 0000000..46ad058 --- /dev/null +++ b/core/modules/rest/lib/Drupal/rest/Tests/FileTest.php @@ -0,0 +1,62 @@ + 'File resource', + 'description' => 'Test special cases for file entities.', + 'group' => 'REST', + ); + } + + /** + * Enables file specific REST API configuration and authentication. + * + * @param string $method + * The HTTP method to be tested. + * @param string $operation + * The operation, one of 'view', 'create', 'update' or 'delete'. + */ + protected function enableFileConfiguration($method, $operation) { + $this->enableService('entity:file', $method); + $permissions = $this->entityPermissions('file', $operation); + $permissions[] = 'restful ' . strtolower($method) . ' entity:file'; + $account = $this->drupalCreateUser($permissions); + $this->drupalLogin($account); + } + + /** + * Tests access to REST resources of public files. + */ + public function testFiles() { + $this->enableFileConfiguration('GET', 'view'); + /** @var \Drupal\file\FileInterface $file */ + $file = $this->entityCreate('file'); + $file->setFileUri('public://'); + $file->save(); + $this->httpRequest('entity/file/' . $file->id(), 'GET', NULL, $this->defaultMimeType); + $this->assertResponse(200); + } + +}