projecthydra/hydra-head — pull request #116 by dchandekstark (2013-10-17 16:07:11+00:00)
Title: Push DownloadBehavior authz to Ability

The purpose of this commit is to push the authorization embedded in Hydra::Controller::DownloadBehavior to the Ability class while maintaining backward compatibility.

This has been accomplished by:

- Adding a before_filter `:authorize_download!` which calls CanCan's `authorize!` method, passing `:download` as the ability and the ActiveFedora datastream to download as the object.
- Removing the authorization logic from DownloadBehavior#show, which now simply calls `send_content`.
- Adding a `download_permissions` method to `Hydra::Ability` and and its ability_logic initialization chain. The new method defines the `:download` ability on `ActiveFedora::Datastream`. The default behavior replicates the current behavior of DownloadBehavior, which is to permit download if the user has read permission on the datastream's object.
- Deprecating the `can_download?` method of DownloadBehavior

In addition, the unused parameter of the `send_content` method of DownloadBehavior has been deprecated. (It was also internally renamed from `asset` to `asset_` to avoid confusion with the `asset` method.)

The DownloadBehavior test related to authorization has been removed, since this is now delegated to Ability.