Skip to content

Lesson Create a Model that can track rightsMetadata

Michael Bond edited this page Sep 23, 2015 · 2 revisions

This Tutorial is known to work with hydra-head version 6.4.0.
Please update this wiki to reflect any other versions that have been tested.

Goals

Explanation

Steps

Step 1: Add the Datastream to your Model

Add this line to an ActiveFedora model

include Hydra::AccessControls::Permissions

By convention, the include statements should be at the very beginning of your class definition, so if you're using the Book model from Dive into Hydra it might look like this with the above line added

class Book < ActiveFedora::Base
  # This is the include statement
  include Hydra::AccessControls::Permissions

  has_metadata 'descMetadata', type: BookMetadata

  delegate :title, to: 'descMetadata'
  delegate :author, to: 'descMetadata'

end

Including Hydra::AccessControls::Permissions will automatically call has_metadata "rightsMetadata", :type => Hydra::Datastream::RightsMetadata to define the rightsMetadata datastream.

Save the file.

Step 2: Confirm that it worked

Restart the rails console and run

book = Book.new
book.rightsMetadata.class
 => Hydra::Datastream::RightsMetadata 
book.permissions
 => [] 

As you can see, rightsMetadata is a Hydra::Datastream::RightsMetadata Datastream and the methods provided by Hydra::AccessControls::Permissions, such as .permissions have been mixed into the Book model. Now you're ready to use these things to assert permissions on objects.

Next Step

Go on to Lesson: Set permissions on an object or return to the Access Controls with Hydra tutorial.

Clone this wiki locally