Islandora / openseadragon

Drupal Field Formatter for OpenSeadragon
https://www.drupal.org/project/openseadragon
GNU General Public License v2.0
4 stars 15 forks source link

Fix/file access #42

Closed adam-vessey closed 2 years ago

adam-vessey commented 2 years ago

GitHub Issue: https://github.com/Islandora/documentation/issues/2134

What does this Pull Request do?

Check for file access before adding items to be rendered to which the user may not have access, preventing the display of broken elements.

What's new?

File access checks with more cache maintenance (#41 makes it even better; otherwise, caching should pretty much be disabled for these elements due to adding something which doesn't implement the interface as a "cacheable dependency"... but this is better in terms of cache maintenance) performed such that items are better invalidated.

How should this be tested?

Use some mechanism (e.g., embargoes to apply file access controls, and ensure that single page viewers should follow suit (multi-page handled in https://github.com/Islandora/islandora/pull/884).

For testing, adding a small hook_file_access() blurb to your code somewhere is probably easiest, such as:

function islandora_file_access($entity, $op) {
  if ($op == 'view') {
    if (in_array($entity->id(), [
      # These are file IDs to test being restricted: change as necessary to target the files
      # being shown in your environment. May also have to clear cache when changed?
      1,
      2,
      3,
    ])) {
      return AccessResult::forbidden('No touchy.')->addCacheableDependency($entity);
    }
  }
  return AccessResult::neutral()->addCacheableDependency($entity);
}

Additional Notes:

Any additional information that you think would be helpful when reviewing this PR.

Interested parties

Tag (@ mention) interested parties or, if unsure, @Islandora/8-x-committers

jordandukart commented 2 years ago

Looks sound to me.

rosiel commented 2 years ago

Do you have time to merge in or rebase upstream, for the new testing matrix?

adam-vessey commented 2 years ago

@rosiel : Yeah, can do so shortly. In another meeting at the moment.: Rolling now.

alxp commented 2 years ago

Before checking out PR branch:

Verified that I am able to see an image in OpenSeaDragon when it has been denied looking at the file directly.

Screen Shot 2022-08-11 at 12 26 22 AM

After checking out PR branch:

The file is displayed in Mirador.

Screen Shot 2022-08-11 at 12 26 03 AM

So this PR does what it says, but there's more work to do in another module. Lol.

:+1: