hydra 10.0.0 → 10.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/doc/Dive-into-Hydra.md +60 -57
- data/doc/For-Developers.md +0 -1
- data/doc/Hackfest-ideas.md +18 -0
- data/doc/Home.md +3 -1
- data/doc/Hydra-Recipes.md +5 -1
- data/doc/LDP-Containers-for-the-perplexed.md +119 -0
- data/doc/Lesson---Adding-attached-files.md +83 -0
- data/doc/Lesson---Build-a-Codex-model-with-XML.md +272 -0
- data/doc/Lesson---Build-a-book-model-with-RDF.md +250 -0
- data/doc/Lesson---Define-Relationships-Between-Objects.md +125 -0
- data/doc/{Lesson:-Generate-Rails-Scaffolding-for-Creating-and-Editing-Books.md → Lesson---Generate-Rails-Scaffolding-for-Creating-and-Editing-Books.md} +57 -50
- data/doc/Lesson---Start-FCRepo-and-Solr.md +76 -0
- data/doc/{Lesson:-add-the-Hydra-dependencies.md → Lesson---add-the-Hydra-dependencies.md} +3 -3
- data/doc/{Lesson:-generate-a-rails-application.md → Lesson---generate-a-rails-application.md} +78 -91
- data/doc/Lesson---make-blacklight-return-search-results.md +71 -0
- data/doc/Lesson---start-the-application-&-search-for-results.md +55 -0
- data/doc/Recipe:-Add-full-text-indexing-to-your-app.md +27 -0
- data/doc/Using-rdf:resource-within-your-models.md +43 -0
- data/hydra.gemspec +1 -1
- data/lib/hydra/version.rb +1 -1
- data/script/grant_revoke_gem_authority.rb +1 -1
- metadata +18 -17
- data/doc/Lesson:-Define-Relationships-Between-Objects.md +0 -131
- data/doc/Lesson:-Reading-Hydra-rightsMetadata-XML.md +0 -87
- data/doc/Lesson:-Use-Hydra-Access-Controls-to-Control-Access-to-Blacklight-show-Pages.md +0 -37
- data/doc/Lesson:-Using-Hydra-Access-Controls-and-CanCan-to-conditionally-render-part-of-a-page.md +0 -29
- data/doc/Lesson:-adding-content-datastreams.md +0 -57
- data/doc/Lesson:-build-a-book-model.md +0 -265
- data/doc/Lesson:-install-hydra-jetty.md +0 -148
- data/doc/Lesson:-make-blacklight-return-search-results.md +0 -69
- data/doc/Lesson:-set-up-your-Rails-Application-to-use-rspec.md +0 -41
- data/doc/Lesson:-start-the-application-&-search-for-results.md +0 -29
data/hydra.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |gem|
|
|
24
24
|
gem.license = 'APACHE2'
|
25
25
|
|
26
26
|
gem.add_dependency 'fcrepo_wrapper', '~> 0.5.1'
|
27
|
-
gem.add_dependency 'solr_wrapper', '~> 0.
|
27
|
+
gem.add_dependency 'solr_wrapper', '~> 0.15.0'
|
28
28
|
gem.add_dependency 'active-fedora', '~> 10.0.0'
|
29
29
|
gem.add_dependency 'hydra-head', '~> 10.0.0'
|
30
30
|
gem.add_dependency 'rails', '~> 4.2'
|
data/lib/hydra/version.rb
CHANGED
@@ -34,7 +34,7 @@ KNOWN_COMMITTER_EMAIL_ADDRESSES = {
|
|
34
34
|
'jkeck' => "jessie.keck@gmail.com",
|
35
35
|
'coblej' => "jim.coble@duke.edu",
|
36
36
|
'jpstroop' => "jpstroop@gmail.com",
|
37
|
-
'jcoyne' => "
|
37
|
+
'jcoyne' => "digger250@gmail.com",
|
38
38
|
'mjgiarlo' => "leftwing@alumni.rutgers.edu",
|
39
39
|
'mark-dce' => "mark@curationexperts.com",
|
40
40
|
'mbklein' => "mbklein@gmail.com",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hydra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 10.0.
|
4
|
+
version: 10.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Friesen
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-08-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fcrepo_wrapper
|
@@ -31,14 +31,14 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: 0.
|
34
|
+
version: 0.15.0
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: 0.
|
41
|
+
version: 0.15.0
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: active-fedora
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -229,30 +229,31 @@ files:
|
|
229
229
|
- doc/Dive-into-Hydra.md
|
230
230
|
- doc/Filtering-search-results-with-hydra-access-controls.md
|
231
231
|
- doc/For-Developers.md
|
232
|
+
- doc/Hackfest-ideas.md
|
232
233
|
- doc/Home.md
|
233
234
|
- doc/Hydra-Recipes.md
|
234
235
|
- doc/Indexing-non-English-content.md
|
235
|
-
- doc/
|
236
|
-
- doc/Lesson
|
237
|
-
- doc/Lesson
|
238
|
-
- doc/Lesson
|
239
|
-
- doc/Lesson
|
240
|
-
- doc/Lesson
|
241
|
-
- doc/Lesson
|
242
|
-
- doc/Lesson
|
243
|
-
- doc/Lesson
|
244
|
-
- doc/Lesson
|
245
|
-
- doc/Lesson
|
246
|
-
- doc/Lesson:-set-up-your-Rails-Application-to-use-rspec.md
|
247
|
-
- doc/Lesson:-start-the-application-&-search-for-results.md
|
236
|
+
- doc/LDP-Containers-for-the-perplexed.md
|
237
|
+
- doc/Lesson---Adding-attached-files.md
|
238
|
+
- doc/Lesson---Build-a-Codex-model-with-XML.md
|
239
|
+
- doc/Lesson---Build-a-book-model-with-RDF.md
|
240
|
+
- doc/Lesson---Define-Relationships-Between-Objects.md
|
241
|
+
- doc/Lesson---Generate-Rails-Scaffolding-for-Creating-and-Editing-Books.md
|
242
|
+
- doc/Lesson---Start-FCRepo-and-Solr.md
|
243
|
+
- doc/Lesson---add-the-Hydra-dependencies.md
|
244
|
+
- doc/Lesson---generate-a-rails-application.md
|
245
|
+
- doc/Lesson---make-blacklight-return-search-results.md
|
246
|
+
- doc/Lesson---start-the-application-&-search-for-results.md
|
248
247
|
- doc/Migrating-to-Hydra-6.2.md
|
249
248
|
- doc/Migration-Notes.md
|
250
249
|
- doc/Models---Defining-a-Custom-Hydra-Model.textile
|
251
250
|
- doc/Rake-Tasks-in-Hydra-Head.textile
|
251
|
+
- doc/Recipe:-Add-full-text-indexing-to-your-app.md
|
252
252
|
- doc/Reference.textile
|
253
253
|
- doc/Solr-Schema.rdoc
|
254
254
|
- doc/Tools-for-Developing-and-Testing-your-Application.textile
|
255
255
|
- doc/Use-HTTP-POST-for-Solr-requests.md
|
256
|
+
- doc/Using-rdf:resource-within-your-models.md
|
256
257
|
- doc/YOUR-Hydra-Application---Initial-Modifications.textile
|
257
258
|
- hydra.gemspec
|
258
259
|
- lib/generators/hydra/install_generator.rb
|
@@ -1,131 +0,0 @@
|
|
1
|
-
# Goals
|
2
|
-
* Set up Models to represent relationships between different types of objects
|
3
|
-
* Create and modify relationships between objects
|
4
|
-
|
5
|
-
# Explanation
|
6
|
-
Now that we have created a model for Books, we will create a separate model for Pages and set a relationship between the two models indicating that any Book can have many Pages and Pages know what Book they belong to.
|
7
|
-
|
8
|
-
The syntax for declaring relationships between ActiveFedora models is the same syntax used by ActiveRecord. It's called the ActiveModel syntax. Underneath the hood, the two libraries implement relationships in very different ways. ActiveRecord uses relational database techniques like foreign keys and join tables while ActiveFedora puts this information into RDF relationships in the RELS-EXT datastreams of your Fedora objects. In both cases you can use the ActiveRecord methods to handle relationships.
|
9
|
-
|
10
|
-
# Steps
|
11
|
-
|
12
|
-
### Step 1: Create an OM Terminology for Page metadata
|
13
|
-
|
14
|
-
Next we're going to add a Page model. We'll start by creating another simple metadata datastream. This time open ```app/models/datastreams/page_metadata.rb``` and add this content:
|
15
|
-
```ruby
|
16
|
-
class Datastreams::PageMetadata < ActiveFedora::OmDatastream
|
17
|
-
|
18
|
-
set_terminology do |t|
|
19
|
-
t.root(path: "fields")
|
20
|
-
t.number index_as: :stored_searchable, type: :integer
|
21
|
-
t.text index_as: :stored_searchable
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.xml_template
|
26
|
-
Nokogiri::XML.parse("<fields/>")
|
27
|
-
end
|
28
|
-
|
29
|
-
def prefix
|
30
|
-
'' # add a prefix for solr index terms if you need to namespace identical terms in multiple data streams
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
```
|
36
|
-
|
37
|
-
### Step 2: Create a Page model and make Pages aware of which Book they belong to
|
38
|
-
|
39
|
-
Then we'll build a Page model that uses the datastream. Open ```app/models/page.rb``` and paste this in:
|
40
|
-
|
41
|
-
```ruby
|
42
|
-
class Page < ActiveFedora::Base
|
43
|
-
has_metadata 'descMetadata', type: Datastreams::PageMetadata
|
44
|
-
|
45
|
-
belongs_to :book, :property=> :is_part_of
|
46
|
-
|
47
|
-
has_attributes :number, datastream: 'descMetadata', multiple: false
|
48
|
-
has_attributes :text, datastream: 'descMetadata', multiple: false
|
49
|
-
|
50
|
-
end
|
51
|
-
```
|
52
|
-
|
53
|
-
This is very similar to how our Book class looks, with the exception of the line ```belongs_to :book```. This establishes a relationship between the book and page model nearly the same as you would do with ActiveRecord. In ActiveFedora, we have to add the :property attribute as well. Relationships are stored as RDF within the RELS-EXT datastream. The :property is actually an RDF predicate.
|
54
|
-
|
55
|
-
### Step 3: Make Books aware of their Pages
|
56
|
-
|
57
|
-
Let's edit the Book class in ```app/models/book.rb``` and add the other half of the relationship:
|
58
|
-
|
59
|
-
```ruby
|
60
|
-
# within app/models/book.rb
|
61
|
-
has_many :pages, :property=> :is_part_of
|
62
|
-
```
|
63
|
-
|
64
|
-
### Step 4: In the Console, manipulate relationships between Book and Page objects
|
65
|
-
|
66
|
-
Save your changes and then reopen the rails console. Now we ought to be able to create some associations.
|
67
|
-
|
68
|
-
```ruby
|
69
|
-
b = Book.find("changeme:1")
|
70
|
-
=> #<Book pid:"changeme:1", title:"Anna Karenina", author:"Tolstoy, Leo">
|
71
|
-
p = Page.new(number: 1, text: "Happy families are all alike; every unhappy family is unhappy in its own way.")
|
72
|
-
=> #<Page pid:"", number:1, text:"Happy families are all alike; every unhappy family is unhappy in its own way.">
|
73
|
-
p.book = b
|
74
|
-
=> #<Book pid:"changeme:1", title:"Anna Karenina", author:"Tolstoy, Leo">
|
75
|
-
p.save
|
76
|
-
=> true
|
77
|
-
b.reload
|
78
|
-
=> #<Book pid:"changeme:1", title:"Anna Karenina", author:"Tolstoy, Leo">
|
79
|
-
b.pages
|
80
|
-
=> [#<Page pid:"changeme:2", number:1, text:"Happy families are all alike; every unhappy family is unhappy in its own way.">]
|
81
|
-
```
|
82
|
-
|
83
|
-
### Step 5: Look at the RDF (if you want to)
|
84
|
-
|
85
|
-
**Note:** If you don't know what RDF is and don't care to know, you can skip this step.
|
86
|
-
|
87
|
-
Let's look at the RDF that active-fedora uses to represent these relationships. This metadata is written into the RELS-EXT datastream of your objects. To see that content, either output it on the command line like this:
|
88
|
-
|
89
|
-
```ruby
|
90
|
-
puts p.datastreams["RELS-EXT"].to_rels_ext
|
91
|
-
```
|
92
|
-
Alternatively, look at the datastream in your browser at [http://localhost:8983/fedora/objects/changeme:2/datastreams/RELS-EXT/content](http://localhost:8983/fedora/objects/changeme:2/datastreams/RELS-EXT/content) (You might need to change the pid in the URL if your page's pid isn't changeme:2)
|
93
|
-
|
94
|
-
Either way, you should see RDF that looks like this:
|
95
|
-
|
96
|
-
```text
|
97
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
98
|
-
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:ns0="info:fedora/fedora-system:def/model#" xmlns:ns1="info:fedora/fedora-system:def/relations-external#">
|
99
|
-
<rdf:Description rdf:about="info:fedora/changeme:2">
|
100
|
-
<ns0:hasModel rdf:resource="info:fedora/afmodel:Page"/>
|
101
|
-
<ns1:isPartOf rdf:resource="info:fedora/changeme:1"/>
|
102
|
-
</rdf:Description>
|
103
|
-
</rdf:RDF>
|
104
|
-
```
|
105
|
-
|
106
|
-
As you can see, it is creating rdf assertions of `info:fedora/fedora-system:def/relations-external#isPartOf` `info:fedora/changeme:1` and `info:fedora/fedora-system:def/model#hasModel` `info:fedora/afmodel:Page`.
|
107
|
-
|
108
|
-
The model assertion is created automatically based on the name of your ActiveFedora model (in this case, Page), but how did ActiveFedora know to use the predicate `info:fedora/fedora-system:def/relations-external#isPartOf` when your `belongs_to` specified a property called :is_part_of?
|
109
|
-
|
110
|
-
In other words, how did we get from
|
111
|
-
|
112
|
-
```ruby
|
113
|
-
belongs_to :book, :property=> :is_part_of
|
114
|
-
```
|
115
|
-
|
116
|
-
to ``info:fedora/fedora-system:def/relations-external#isPartOf`?
|
117
|
-
|
118
|
-
The answer is that active-fedora has a config file that it uses to look up RDF predicates based on the property name you specify in your model. By default, these predicates are read from the active-fedora gem, but you can override them by creating your own copy in config/predicate_mappings.yml in your own application. To see the default mappings, look at active-fedora's default [predicate mappings YAML file] (https://github.com/projecthydra/active_fedora/blob/master/config/predicate_mappings.yml) on github.
|
119
|
-
|
120
|
-
### Step 6: Commit your changes
|
121
|
-
|
122
|
-
Now that we've added page relationships, it's a great time to commit to git:
|
123
|
-
|
124
|
-
```text
|
125
|
-
git add .
|
126
|
-
git commit -m "Created a book page model with relationship to the book model"
|
127
|
-
```
|
128
|
-
|
129
|
-
# Next Step
|
130
|
-
Go on to **BONUS** [[Lesson: Adding Content Datastreams]] or
|
131
|
-
explore other [Dive into Hydra](Dive into Hydra#Bonus) tutorial bonus lessons.
|
@@ -1,87 +0,0 @@
|
|
1
|
-
This Tutorial is known to work with hydra-head version 6.0.0..
|
2
|
-
_Please update this wiki to reflect any other versions that have been tested._
|
3
|
-
|
4
|
-
# Steps
|
5
|
-
|
6
|
-
Given a book whose permissions look like this:
|
7
|
-
```text
|
8
|
-
puts book.permissions
|
9
|
-
{:type=>"group", :access=>"discover", :name=>"group2"}
|
10
|
-
{:type=>"group", :access=>"read", :name=>"group3"}
|
11
|
-
{:type=>"group", :access=>"read", :name=>"group9"}
|
12
|
-
{:type=>"group", :access=>"read", :name=>"group8"}
|
13
|
-
{:type=>"user", :access=>"read", :name=>"user3"}
|
14
|
-
{:type=>"user", :access=>"edit", :name=>"bob1"}
|
15
|
-
{:type=>"user", :access=>"edit", :name=>"sally2"}
|
16
|
-
```
|
17
|
-
|
18
|
-
The permissions will be written into the rightsMetadata datstream like so
|
19
|
-
```xml
|
20
|
-
puts book.rightsMetadata.to_xml
|
21
|
-
<rightsMetadata xmlns="http://hydra-collab.stanford.edu/schemas/rightsMetadata/v1" version="0.1">
|
22
|
-
<copyright>
|
23
|
-
<human type="title"/>
|
24
|
-
<human type="description"/>
|
25
|
-
<machine type="uri"/>
|
26
|
-
</copyright>
|
27
|
-
<access type="discover">
|
28
|
-
<human/>
|
29
|
-
<machine>
|
30
|
-
<group>group2</group>
|
31
|
-
</machine>
|
32
|
-
</access>
|
33
|
-
<access type="read">
|
34
|
-
<human/>
|
35
|
-
<machine>
|
36
|
-
<group>group3</group>
|
37
|
-
<group>group9</group>
|
38
|
-
<group>group8</group>
|
39
|
-
<person>user3</person>
|
40
|
-
</machine>
|
41
|
-
</access>
|
42
|
-
<access type="edit">
|
43
|
-
<human/>
|
44
|
-
<machine>
|
45
|
-
<person>bob1</person>
|
46
|
-
<person>sally2</person>
|
47
|
-
</machine>
|
48
|
-
</access>
|
49
|
-
<embargo>
|
50
|
-
<human/>
|
51
|
-
<machine/>
|
52
|
-
</embargo>
|
53
|
-
</rightsMetadata>
|
54
|
-
```
|
55
|
-
|
56
|
-
If we remove the nodes that aren't relevant to this lesson, the XML looks like this:
|
57
|
-
|
58
|
-
```xml
|
59
|
-
<rightsMetadata xmlns="http://hydra-collab.stanford.edu/schemas/rightsMetadata/v1" version="0.1">
|
60
|
-
<access type="discover">
|
61
|
-
<machine>
|
62
|
-
<group>group2</group>
|
63
|
-
</machine>
|
64
|
-
</access>
|
65
|
-
<access type="read">
|
66
|
-
<machine>
|
67
|
-
<group>group3</group>
|
68
|
-
<group>group9</group>
|
69
|
-
<group>group8</group>
|
70
|
-
<person>user3</person>
|
71
|
-
</machine>
|
72
|
-
</access>
|
73
|
-
<access type="edit">
|
74
|
-
<machine>
|
75
|
-
<person>bob1</person>
|
76
|
-
<person>sally2</person>
|
77
|
-
</machine>
|
78
|
-
</access>
|
79
|
-
</rightsMetadata>
|
80
|
-
```
|
81
|
-
|
82
|
-
As you can see, group ids are put into `<group>` nodes and user ids are put into `<person>` nodes. The type of access being granted is decided by the @type attribute on the `<access>` nodes.
|
83
|
-
|
84
|
-
The intermediary `<machine>` node is meant to allow you to insert human-readable information into the 'access/human' node while inserting the machine-readable assertions into 'access/machine' node.
|
85
|
-
|
86
|
-
# Next Step
|
87
|
-
Go on to [[Lesson: Indexing Hydra Rights Metadata into Solr]] or return to the [[Access Controls with Hydra]] tutorial.
|
@@ -1,37 +0,0 @@
|
|
1
|
-
This Tutorial is known to work with hydra-head version 6.0.0.
|
2
|
-
_Please update this wiki to reflect any other versions that have been tested._
|
3
|
-
|
4
|
-
# Goals
|
5
|
-
|
6
|
-
# Explanation
|
7
|
-
|
8
|
-
# Steps
|
9
|
-
|
10
|
-
### Step 1: Enforce Show permissions on Blacklight search results
|
11
|
-
|
12
|
-
When we turned off access controls as part of the [[Dive into Hydra]] tutorial, we commented out two lines. The first line was turning on gated discovery. We covered that in the previous lesson. The other line was telling Blacklight to prevent unauthorized access to `show` views for items from your searches. Let's enable that filter and see what it does.
|
13
|
-
|
14
|
-
Open app/controllers/catalog_controller.rb and find these lines
|
15
|
-
```ruby
|
16
|
-
# These before_filters apply the hydra access controls
|
17
|
-
# before_filter :enforce_show_permissions, :only=>:show
|
18
|
-
```
|
19
|
-
|
20
|
-
Uncomment the line with the `before_filter`
|
21
|
-
```ruby
|
22
|
-
# These before_filters apply the hydra access controls
|
23
|
-
before_filter :enforce_show_permissions, :only=>:show
|
24
|
-
```
|
25
|
-
|
26
|
-
### Step 2: Test the enforcement of Show permissions on Blacklight search results
|
27
|
-
|
28
|
-
In your browser, log into the application as yourself, run a search, and click on the link to a book that you only have `discover` access to. Depending on what experiments you've done based on the previous lesson, you might have to go into the `rails console` and either create a new book that you have discover access to or modify an existing book to give you discover access.
|
29
|
-
|
30
|
-
You should have been redirected back to the search results page with a message reading _"You do not have sufficient access privileges to read this document, which has been marked private."_
|
31
|
-
|
32
|
-
**Note:** For this example, it's important that you to _only_ have discover access (not `read` or `edit`) and that none of the groups you belong to have `read` or `edit` access either. If you or one of your groups has `read` or `edit` access then you will see the book's `show` page instead of being redirected by the access controls.
|
33
|
-
|
34
|
-
In the `rails console`, grant yourself 'read' or 'edit' access to the book and save the book. Then in the browser you will be able to visit the `show` page for that book instead of being redirected like before.
|
35
|
-
|
36
|
-
# Next Step
|
37
|
-
Go on to [[Lesson: Use Hydra Access Controls and CanCan to decide whether to render a page]] or return to the [[Access Controls with Hydra]] tutorial.
|
data/doc/Lesson:-Using-Hydra-Access-Controls-and-CanCan-to-conditionally-render-part-of-a-page.md
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
This Tutorial is known to work with hydra-head version 6.0.0.
|
2
|
-
_Please update this wiki to reflect any other versions that have been tested._
|
3
|
-
|
4
|
-
# Goals
|
5
|
-
|
6
|
-
# Explanation
|
7
|
-
|
8
|
-
# Steps
|
9
|
-
|
10
|
-
### Step: Use `can?` to conditionally render html on a page
|
11
|
-
|
12
|
-
In `app/views/books/show.html.erb` find the code that's displaying the "Edit" and "Back" links at the bottom of the page.
|
13
|
-
```erb
|
14
|
-
<%= link_to 'Edit', edit_book_path(@book) %> |
|
15
|
-
<%= link_to 'Back', books_path %>
|
16
|
-
```
|
17
|
-
|
18
|
-
Use an `if ... end` clause to only show the "Edit" link if the current user has permission to edit the current book.
|
19
|
-
```erb
|
20
|
-
<%- if can?(:edit, @book) %>
|
21
|
-
<%= link_to 'Edit', edit_book_path(@book) %> |
|
22
|
-
<%- end %>
|
23
|
-
<%= link_to 'Back', books_path %>
|
24
|
-
```
|
25
|
-
|
26
|
-
Now go into the `rails console` and give yourself `edit` access to one book but only `read` access for another. Look at the show views for the two books. You should see the "Edit" link on the book that you have permission to edit and you should not see the "Edit" link for the book that you do not have permission to edit.
|
27
|
-
|
28
|
-
# Next Step
|
29
|
-
Return to the [[Access Controls with Hydra]] tutorial.
|
@@ -1,57 +0,0 @@
|
|
1
|
-
# Goals
|
2
|
-
* Add "file-bearing" Datastreams to models and objects
|
3
|
-
* See where files are stored in Fedora objects and how to retrieve them
|
4
|
-
|
5
|
-
# Explanation
|
6
|
-
|
7
|
-
So far, we've only added datastreams that bear metadata. Let's add a datastream that has some content to it. For example, this could be a content datastream in our book model that is an image of the book's cover, or a datastream added to the page model that is an image or pdf of that actual page.
|
8
|
-
|
9
|
-
In this case, we'll add a file datastream where we can store a pdf of a page.
|
10
|
-
|
11
|
-
# Steps
|
12
|
-
|
13
|
-
### Step 1: Add a "pageContent" file datastream to the Page model
|
14
|
-
|
15
|
-
In our Page model ```app/models/page.rb```, we'll add the following line underneath our descMetadata datastream:
|
16
|
-
|
17
|
-
```ruby
|
18
|
-
has_file_datastream "pageContent"
|
19
|
-
```
|
20
|
-
|
21
|
-
Now we have a datastream called "pageContent" that can hold any kind of file we wish to add to it.
|
22
|
-
|
23
|
-
### Step 2: In the console, add a file to a Page object and save it
|
24
|
-
|
25
|
-
To add the file to one of our page objects, open up the console again:
|
26
|
-
|
27
|
-
```ruby
|
28
|
-
> p = Page.find("changeme:2")
|
29
|
-
=> #<Page pid:"changeme:2", number:[1], text:["Happy families are all alike; every unhappy family is unhappy in its own way."]>
|
30
|
-
> p.datastreams.keys
|
31
|
-
=> ["DC", "RELS-EXT", "descMetadata", "pageContent"]
|
32
|
-
```
|
33
|
-
|
34
|
-
Now you're ready to add the file. Choose a file on your computer that you want to add as the "pageContent". In the lines below we're pretending that the path to the file is "/Users/adamw/Desktop/page1.pdf". Replace that with the correct local path for the file you want to use.
|
35
|
-
|
36
|
-
```ruby
|
37
|
-
> p.pageContent.content = File.open("../AK Page 4.pdf")
|
38
|
-
=> #<File:../AK Page 4.pdf>
|
39
|
-
> p.save
|
40
|
-
=> true
|
41
|
-
```
|
42
|
-
|
43
|
-
### Step 3: See where the file Datastream was saved in Fedora
|
44
|
-
|
45
|
-
Now if you go to [[http://localhost:8983/fedora/objects/changeme:2/datastreams]], you'll see the pageContent datastream in Fedora. Following the links to it will allow us to view or download the file we've added.
|
46
|
-
|
47
|
-
### Step 4: Commit your changes
|
48
|
-
|
49
|
-
Now that we've added a content datastream, it's a great time to commit to git:
|
50
|
-
|
51
|
-
```bash
|
52
|
-
git add .
|
53
|
-
git commit -m "Created a content datastream"
|
54
|
-
```
|
55
|
-
|
56
|
-
# Next Step
|
57
|
-
Proceed to **BONUS** [[Lesson: Generate Rails Scaffolding for Creating and Editing Books]] or explore other [Dive into Hydra](Dive into Hydra#bonus) tutorial bonus lessons.
|