hydra-head 4.0.3 → 4.1.0
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.
- data/.gitignore +1 -0
- data/HISTORY.textile +17 -2
- data/app/assets/stylesheets/hydra/html_refactor.css +3 -30
- data/app/assets/stylesheets/hydra/styles.css +6 -64
- data/app/controllers/downloads_controller.rb +1 -1
- data/app/controllers/hydra/assets_controller.rb +10 -1
- data/app/controllers/hydra/contributors_controller.rb +15 -1
- data/app/controllers/hydra/file_assets_controller.rb +1 -1
- data/app/controllers/hydra/permissions_controller.rb +14 -0
- data/app/helpers/hydra/article_metadata_helper_behavior.rb +14 -1
- data/app/helpers/hydra/downloads_helper_behavior.rb +6 -0
- data/app/helpers/hydra/facets_helper_behavior.rb +7 -0
- data/app/helpers/hydra/generic_content_objects_helper_behavior.rb +6 -0
- data/app/helpers/hydra/hydra_assets_helper_behavior.rb +10 -0
- data/app/helpers/hydra/hydra_fedora_metadata_helper_behavior.rb +31 -0
- data/app/helpers/hydra/hydra_helper_behavior.rb +18 -7
- data/app/helpers/hydra/hydra_uploader_helper_behavior.rb +5 -0
- data/app/helpers/hydra/inline_editable_metadata_helper_behavior.rb +6 -0
- data/app/helpers/hydra/javascript_includes_helper_behavior.rb +7 -0
- data/app/helpers/hydra/personalization_helper_behavior.rb +5 -0
- data/app/helpers/hydra/release_process_helper_behavior.rb +5 -0
- data/app/models/generic_content.rb +3 -0
- data/app/models/generic_image.rb +3 -0
- data/app/models/superuser.rb +4 -2
- data/app/models/user_attribute.rb +7 -2
- data/app/views/_add_assets_links.html.erb +4 -4
- data/app/views/catalog/_index_partials/_default.html.erb +2 -2
- data/app/views/catalog/show.html.erb +1 -1
- data/app/views/generic_contents/_index.html.erb +2 -2
- data/app/views/generic_images/_edit.html.erb +1 -1
- data/app/views/generic_images/_index.html.erb +2 -2
- data/app/views/hydra/file_assets/_file_assets_form.html.erb +1 -1
- data/app/views/hydra/file_assets/_index.html.erb +2 -2
- data/app/views/hydra/file_assets/_result.html.erb +1 -1
- data/app/views/layouts/hydra-head.html.erb +4 -1
- data/app/views/mods_assets/_index_list.html.erb +1 -1
- data/app/views/mods_assets/_index_table.html.erb +2 -2
- data/app/views/mods_assets/_show.html.erb +1 -1
- data/app/views/mods_assets/_show_file_assets.html.erb +1 -1
- data/config/jetty.yml +1 -1
- data/config/locales/hydra.en.yml +7 -0
- data/config/solr.yml +1 -1
- data/config/solr_mappings.yml +2 -2
- data/hydra-head.gemspec +5 -4
- data/lib/generators/hydra/head_generator.rb +6 -5
- data/lib/generators/hydra/templates/config/fedora.yml +1 -1
- data/lib/generators/hydra/templates/config/solr.yml +1 -1
- data/lib/hydra-head/version.rb +1 -1
- data/lib/hydra.rb +13 -11
- data/lib/hydra/assets.rb +5 -135
- data/lib/hydra/catalog.rb +6 -44
- data/lib/hydra/controller.rb +10 -27
- data/lib/hydra/controller/assets_controller_behavior.rb +142 -0
- data/lib/hydra/controller/catalog_controller_behavior.rb +56 -0
- data/lib/hydra/controller/controller_behavior.rb +59 -0
- data/lib/hydra/controller/file_assets_behavior.rb +142 -0
- data/lib/hydra/controller/repository_controller_behavior.rb +119 -0
- data/lib/hydra/controller/upload_behavior.rb +139 -0
- data/lib/hydra/file_assets.rb +3 -138
- data/lib/hydra/file_assets_helper.rb +6 -133
- data/lib/hydra/generic_content.rb +15 -0
- data/lib/hydra/generic_image.rb +10 -0
- data/lib/hydra/global_configurable.rb +46 -0
- data/lib/hydra/model_methods.rb +3 -3
- data/lib/hydra/model_mixins.rb +1 -1
- data/lib/hydra/model_mixins/solr_document_extension.rb +24 -0
- data/lib/hydra/repository_controller.rb +4 -95
- data/lib/hydra/ui/controller.rb +1 -2
- data/lib/hydra/user.rb +13 -1
- data/lib/railties/hydra-fixtures.rake +1 -1
- data/tasks/hydra-head.rake +2 -0
- data/{app/models → test_support/etc}/common_metadata_asset.rb +1 -2
- data/test_support/features/mods_asset_show.feature +1 -1
- data/test_support/features/support/env.rb +2 -0
- data/test_support/features/support/paths.rb +2 -0
- data/test_support/spec/controllers/catalog_controller_spec.rb +8 -0
- data/test_support/spec/controllers/catalog_controller_viewing_context_spec.rb +10 -1
- data/test_support/spec/controllers/catalog_valid_html_spec.rb +8 -0
- data/test_support/spec/controllers/contributors_controller_spec.rb +10 -0
- data/test_support/spec/controllers/file_assets_controller_spec.rb +15 -3
- data/test_support/spec/controllers/hydra-assets_controller_spec.rb +11 -1
- data/test_support/spec/controllers/hydra_controller_spec.rb +15 -4
- data/test_support/spec/controllers/permissions_controller_spec.rb +8 -0
- data/test_support/spec/helpers/access_controls_enforcement_spec.rb +1 -2
- data/test_support/spec/helpers/file_assets_helper_spec.rb +1 -1
- data/test_support/spec/helpers/generic_content_objects_helper_spec.rb +10 -1
- data/test_support/spec/helpers/hydra-repository_controller_spec.rb +1 -1
- data/test_support/spec/helpers/hydra_assets_helper_spec.rb +8 -0
- data/test_support/spec/helpers/hydra_fedora_metadata_helper_spec.rb +11 -0
- data/test_support/spec/helpers/hydra_helper_spec.rb +18 -0
- data/test_support/spec/helpers/hydra_model_methods_spec.rb +0 -12
- data/test_support/spec/helpers/hydra_uploader_helper_spec.rb +8 -0
- data/test_support/spec/helpers/javascript_includes_helper_spec.rb +9 -1
- data/test_support/spec/lib/catalog_spec.rb +10 -3
- data/test_support/spec/lib/global_configurable_spec.rb +98 -0
- data/test_support/spec/lib/model_methods_spec.rb +29 -0
- data/test_support/spec/models/generic_content_spec.rb +11 -0
- data/test_support/spec/models/generic_image_spec.rb +15 -0
- data/test_support/spec/models/user_spec.rb +25 -0
- metadata +39 -37
- data/app/models/ability.rb +0 -5
- data/app/models/hydra/ability.rb +0 -137
- data/app/models/hydra/datastream/common_mods_index_methods.rb +0 -47
- data/app/models/hydra/datastream/mods_article.rb +0 -530
- data/app/models/hydra/datastream/mods_dataset.rb +0 -173
- data/app/models/hydra/datastream/mods_generic_content.rb +0 -498
- data/app/models/hydra/datastream/mods_image.rb +0 -497
- data/app/models/hydra/datastream/rights_metadata.rb +0 -191
- data/app/models/hydra/role_mapper_behavior.rb +0 -33
- data/app/models/role_mapper.rb +0 -6
- data/lib/hydra/access_controls_enforcement.rb +0 -237
- data/lib/hydra/access_controls_evaluation.rb +0 -38
- data/lib/hydra/common_mods_index_methods.rb +0 -46
- data/lib/hydra/model_mixins/mods_object.rb +0 -17
- data/lib/hydra/model_mixins/rights_metadata.rb +0 -357
- data/lib/hydra/mods_article.rb +0 -535
- data/lib/hydra/mods_dataset.rb +0 -177
- data/lib/hydra/mods_generic_content.rb +0 -500
- data/lib/hydra/mods_image.rb +0 -500
- data/lib/uva/mods_index_methods.rb +0 -30
- data/test_support/spec/lib/common_mods_index_methods_spec.rb +0 -26
- data/test_support/spec/models/ability_spec.rb +0 -40
- data/test_support/spec/models/hydra_rights_metadata_spec.rb +0 -175
- data/test_support/spec/models/role_mapper_spec.rb +0 -22
- data/test_support/spec/unit/rights_metadata_spec.rb +0 -80
@@ -1,191 +0,0 @@
|
|
1
|
-
module Hydra
|
2
|
-
module Datastream
|
3
|
-
# Implements Hydra RightsMetadata XML terminology for asserting access permissions
|
4
|
-
class RightsMetadata < ActiveFedora::NokogiriDatastream
|
5
|
-
|
6
|
-
set_terminology do |t|
|
7
|
-
t.root(:path=>"rightsMetadata", :xmlns=>"http://hydra-collab.stanford.edu/schemas/rightsMetadata/v1", :schema=>"http://github.com/projecthydra/schemas/tree/v1/rightsMetadata.xsd")
|
8
|
-
t.copyright {
|
9
|
-
t.machine {
|
10
|
-
t.uvalicense
|
11
|
-
t.cclicense
|
12
|
-
t.license
|
13
|
-
}
|
14
|
-
t.human_readable(:path=>"human")
|
15
|
-
t.license(:proxy=>[:machine, :license ])
|
16
|
-
t.cclicense(:proxy=>[:machine, :cclicense ])
|
17
|
-
}
|
18
|
-
t.access {
|
19
|
-
t.human_readable(:path=>"human")
|
20
|
-
t.machine {
|
21
|
-
t.group
|
22
|
-
t.person
|
23
|
-
}
|
24
|
-
t.person(:proxy=>[:machine, :person])
|
25
|
-
t.group(:proxy=>[:machine, :group])
|
26
|
-
# accessor :access_person, :term=>[:access, :machine, :person]
|
27
|
-
}
|
28
|
-
t.discover_access(:ref=>[:access], :attributes=>{:type=>"discover"})
|
29
|
-
t.read_access(:ref=>[:access], :attributes=>{:type=>"read"})
|
30
|
-
t.edit_access(:ref=>[:access], :attributes=>{:type=>"edit"})
|
31
|
-
# A bug in OM prevnts us from declaring proxy terms at the root of a Terminology
|
32
|
-
# t.access_person(:proxy=>[:access,:machine,:person])
|
33
|
-
# t.access_group(:proxy=>[:access,:machine,:group])
|
34
|
-
|
35
|
-
t.embargo {
|
36
|
-
t.human_readable(:path=>"human")
|
37
|
-
t.machine{
|
38
|
-
t.date(:type =>"release")
|
39
|
-
}
|
40
|
-
t.embargo_release_date(:proxy => [:machine, :date])
|
41
|
-
}
|
42
|
-
end
|
43
|
-
|
44
|
-
# Generates an empty Mods Article (used when you call ModsArticle.new without passing in existing xml)
|
45
|
-
def self.xml_template
|
46
|
-
builder = Nokogiri::XML::Builder.new do |xml|
|
47
|
-
xml.rightsMetadata(:version=>"0.1", "xmlns"=>"http://hydra-collab.stanford.edu/schemas/rightsMetadata/v1") {
|
48
|
-
xml.copyright {
|
49
|
-
xml.human
|
50
|
-
xml.machine {
|
51
|
-
xml.uvalicense "no"
|
52
|
-
}
|
53
|
-
}
|
54
|
-
xml.access(:type=>"discover") {
|
55
|
-
xml.human
|
56
|
-
xml.machine
|
57
|
-
}
|
58
|
-
xml.access(:type=>"read") {
|
59
|
-
xml.human
|
60
|
-
xml.machine
|
61
|
-
}
|
62
|
-
xml.access(:type=>"edit") {
|
63
|
-
xml.human
|
64
|
-
xml.machine
|
65
|
-
}
|
66
|
-
xml.embargo{
|
67
|
-
xml.human
|
68
|
-
xml.machine
|
69
|
-
}
|
70
|
-
}
|
71
|
-
end
|
72
|
-
return builder.doc
|
73
|
-
end
|
74
|
-
|
75
|
-
# Returns the permissions for the selected person/group
|
76
|
-
# If new_access_level is provided, updates the selected person/group access_level to the one specified
|
77
|
-
# A new_access_level of "none" will remove all access_levels for the selected person/group
|
78
|
-
# @param [Hash] selector hash in format {type => identifier}
|
79
|
-
# @param new_access_level (default nil)
|
80
|
-
# @return Hash in format {type => access_level}.
|
81
|
-
#
|
82
|
-
# ie.
|
83
|
-
# permissions({:person=>"person123"})
|
84
|
-
# => {"person123"=>"edit"}
|
85
|
-
# permissions({:person=>"person123"}, "read")
|
86
|
-
# => {"person123"=>"read"}
|
87
|
-
# permissions({:person=>"person123"})
|
88
|
-
# => {"person123"=>"read"}
|
89
|
-
def permissions(selector, new_access_level=nil)
|
90
|
-
type = selector.keys.first.to_sym
|
91
|
-
actor = selector.values.first
|
92
|
-
if new_access_level.nil?
|
93
|
-
xpath = self.class.terminology.xpath_for(:access, type, actor)
|
94
|
-
nodeset = self.find_by_terms(xpath)
|
95
|
-
if nodeset.empty?
|
96
|
-
return "none"
|
97
|
-
else
|
98
|
-
return nodeset.first.ancestors("access").first.attributes["type"].text
|
99
|
-
end
|
100
|
-
else
|
101
|
-
remove_all_permissions(selector)
|
102
|
-
unless new_access_level == "none"
|
103
|
-
access_type_symbol = "#{new_access_level}_access".to_sym
|
104
|
-
result = self.update_values([access_type_symbol, type] => {"-1"=>actor})
|
105
|
-
end
|
106
|
-
self.dirty = true
|
107
|
-
return new_access_level
|
108
|
-
end
|
109
|
-
|
110
|
-
end
|
111
|
-
|
112
|
-
# Reports on which groups have which permissions
|
113
|
-
# @return Hash in format {group_name => group_permissions, group_name => group_permissions}
|
114
|
-
def groups
|
115
|
-
return quick_search_by_type(:group)
|
116
|
-
end
|
117
|
-
|
118
|
-
# Reports on which groups have which permissions
|
119
|
-
# @return Hash in format {person_name => person_permissions, person_name => person_permissions}
|
120
|
-
def individuals
|
121
|
-
return quick_search_by_type(:person)
|
122
|
-
end
|
123
|
-
|
124
|
-
# Updates permissions for all of the persons and groups in a hash
|
125
|
-
# @param params ex. {"group"=>{"group1"=>"discover","group2"=>"edit"}, "person"=>{"person1"=>"read","person2"=>"discover"}}
|
126
|
-
# Currently restricts actor type to group or person. Any others will be ignored
|
127
|
-
def update_permissions(params)
|
128
|
-
params.fetch("group", {}).each_pair {|group_id, access_level| self.permissions({"group"=>group_id}, access_level)}
|
129
|
-
params.fetch("person", {}).each_pair {|group_id, access_level| self.permissions({"person"=>group_id}, access_level)}
|
130
|
-
end
|
131
|
-
|
132
|
-
# @param [Symbol] type (either :group or :person)
|
133
|
-
# @return
|
134
|
-
# This method limits the response to known access levels. Probably runs a bit faster than .permissions().
|
135
|
-
def quick_search_by_type(type)
|
136
|
-
result = {}
|
137
|
-
[{:discover_access=>"discover"},{:read_access=>"read"},{:edit_access=>"edit"}].each do |access_levels_hash|
|
138
|
-
access_level = access_levels_hash.keys.first
|
139
|
-
access_level_name = access_levels_hash.values.first
|
140
|
-
self.find_by_terms(*[access_level, type]).each do |entry|
|
141
|
-
result[entry.text] = access_level_name
|
142
|
-
end
|
143
|
-
end
|
144
|
-
return result
|
145
|
-
end
|
146
|
-
|
147
|
-
attr_reader :embargo_release_date
|
148
|
-
def embargo_release_date=(release_date)
|
149
|
-
release_date = release_date.to_s if release_date.is_a? Date
|
150
|
-
begin
|
151
|
-
Date.parse(release_date)
|
152
|
-
rescue
|
153
|
-
return "INVALID DATE"
|
154
|
-
end
|
155
|
-
self.update_values({[:embargo,:machine,:date]=>release_date})
|
156
|
-
end
|
157
|
-
def embargo_release_date(opts={})
|
158
|
-
embargo_release_date = self.find_by_terms(*[:embargo,:machine,:date]).first ? self.find_by_terms(*[:embargo,:machine,:date]).first.text : nil
|
159
|
-
if embargo_release_date.present? && opts[:format] && opts[:format] == :solr_date
|
160
|
-
embargo_release_date << "T23:59:59Z"
|
161
|
-
end
|
162
|
-
embargo_release_date
|
163
|
-
end
|
164
|
-
def under_embargo?
|
165
|
-
(embargo_release_date && Date.today < embargo_release_date.to_date) ? true : false
|
166
|
-
end
|
167
|
-
|
168
|
-
def to_solr(solr_doc=Hash.new)
|
169
|
-
super(solr_doc)
|
170
|
-
::Solrizer::Extractor.insert_solr_field_value(solr_doc, "embargo_release_date_dt", embargo_release_date(:format=>:solr_date)) if embargo_release_date
|
171
|
-
solr_doc
|
172
|
-
end
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
private
|
179
|
-
# Purge all access given group/person
|
180
|
-
def remove_all_permissions(selector)
|
181
|
-
return unless ng_xml
|
182
|
-
type = selector.keys.first.to_sym
|
183
|
-
actor = selector.values.first
|
184
|
-
xpath = self.class.terminology.xpath_for(:access, type, actor)
|
185
|
-
nodes_to_purge = self.find_by_terms(xpath)
|
186
|
-
nodes_to_purge.each {|node| node.remove}
|
187
|
-
end
|
188
|
-
|
189
|
-
end
|
190
|
-
end
|
191
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# this code will be moved/renamed to Hydra::AccessControl::RoleMapperBehavior (with the appropriate namespace changes) in Hydra 5.0
|
2
|
-
require 'yaml'
|
3
|
-
module Hydra::RoleMapperBehavior
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
|
6
|
-
module ClassMethods
|
7
|
-
def role_names
|
8
|
-
map.keys
|
9
|
-
end
|
10
|
-
def roles(username)
|
11
|
-
byname[username]||[]
|
12
|
-
end
|
13
|
-
|
14
|
-
def whois(r)
|
15
|
-
map[r]||[]
|
16
|
-
end
|
17
|
-
|
18
|
-
def map
|
19
|
-
@map ||= YAML.load(File.open(File.join(Rails.root, "config/role_map_#{Rails.env}.yml")))
|
20
|
-
end
|
21
|
-
|
22
|
-
|
23
|
-
def byname
|
24
|
-
return @byname if @byname
|
25
|
-
m = Hash.new{|h,k| h[k]=[]}
|
26
|
-
@byname = map.inject(m) do|memo, (role,usernames)|
|
27
|
-
((usernames if usernames.respond_to?(:each)) || [usernames]).each { |x| memo[x]<<role}
|
28
|
-
memo
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
data/app/models/role_mapper.rb
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
# RoleMapper This is used by AccessControlsEnforcement to get users' Roles (used in access permissions)
|
2
|
-
# If you are using something like Shibboleth or LDAP to get users' Roles, you should override this Class.
|
3
|
-
# Your override should include a Module that implements the same behaviors as Hydra::RoleMapperBehavior
|
4
|
-
class RoleMapper
|
5
|
-
include Hydra::RoleMapperBehavior
|
6
|
-
end
|
@@ -1,237 +0,0 @@
|
|
1
|
-
# will move to lib/hydra/access_control folder/namespace in release 5.x
|
2
|
-
module Hydra::AccessControlsEnforcement
|
3
|
-
|
4
|
-
def self.included(klass)
|
5
|
-
klass.send(:include, Hydra::AccessControlsEvaluation)
|
6
|
-
end
|
7
|
-
|
8
|
-
#
|
9
|
-
# Access Controls Enforcement Filters
|
10
|
-
#
|
11
|
-
|
12
|
-
# Controller "before" filter that delegates enforcement based on the controller action
|
13
|
-
# Action-specific implementations are enforce_index_permissions, enforce_show_permissions, etc.
|
14
|
-
# @param [Hash] opts (optional, not currently used)
|
15
|
-
#
|
16
|
-
# @example
|
17
|
-
# class CatalogController < ApplicationController
|
18
|
-
# before_filter :enforce_access_controls
|
19
|
-
# end
|
20
|
-
def enforce_access_controls(opts={})
|
21
|
-
controller_action = params[:action].to_s
|
22
|
-
controller_action = "edit" if params[:action] == "destroy"
|
23
|
-
delegate_method = "enforce_#{controller_action}_permissions"
|
24
|
-
if self.respond_to?(delegate_method.to_sym, true)
|
25
|
-
self.send(delegate_method.to_sym)
|
26
|
-
else
|
27
|
-
true
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
|
32
|
-
#
|
33
|
-
# Solr integration
|
34
|
-
#
|
35
|
-
|
36
|
-
# returns a params hash with the permissions info for a single solr document
|
37
|
-
# If the id arg is nil, then the value is fetched from params[:id]
|
38
|
-
# This method is primary called by the get_permissions_solr_response_for_doc_id method.
|
39
|
-
# Modeled on Blacklight::SolrHelper.solr_doc_params
|
40
|
-
# @param [String] id of the documetn to retrieve
|
41
|
-
def permissions_solr_doc_params(id=nil)
|
42
|
-
id ||= params[:id]
|
43
|
-
# just to be consistent with the other solr param methods:
|
44
|
-
{
|
45
|
-
:qt => :permissions,
|
46
|
-
:id => id # this assumes the document request handler will map the 'id' param to the unique key field
|
47
|
-
}
|
48
|
-
end
|
49
|
-
|
50
|
-
# a solr query method
|
51
|
-
# retrieve a solr document, given the doc id
|
52
|
-
# Modeled on Blacklight::SolrHelper.get_permissions_solr_response_for_doc_id
|
53
|
-
# @param [String] id of the documetn to retrieve
|
54
|
-
# @param [Hash] extra_controller_params (optional)
|
55
|
-
def get_permissions_solr_response_for_doc_id(id=nil, extra_controller_params={})
|
56
|
-
raise Blacklight::Exceptions::InvalidSolrID.new("The application is trying to retrieve permissions without specifying an asset id") if id.nil?
|
57
|
-
solr_response = Blacklight.solr.find permissions_solr_doc_params(id).merge(extra_controller_params)
|
58
|
-
raise Blacklight::Exceptions::InvalidSolrID.new("The solr permissions search handler didn't return anything for id \"#{id}\"") if solr_response.docs.empty?
|
59
|
-
document = SolrDocument.new(solr_response.docs.first, solr_response)
|
60
|
-
[solr_response, document]
|
61
|
-
end
|
62
|
-
|
63
|
-
# Loads permissions info into @permissions_solr_response and @permissions_solr_document
|
64
|
-
def load_permissions_from_solr(id=params[:id], extra_controller_params={})
|
65
|
-
unless !@permissions_solr_document.nil? && !@permissions_solr_response.nil?
|
66
|
-
@permissions_solr_response, @permissions_solr_document = get_permissions_solr_response_for_doc_id(id, extra_controller_params)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
private
|
71
|
-
|
72
|
-
# If someone hits the show action while their session's viewing_context is in edit mode,
|
73
|
-
# this will redirect them to the edit action.
|
74
|
-
# If they do not have sufficient privileges to edit documents, it will silently switch their session to browse mode.
|
75
|
-
def enforce_viewing_context_for_show_requests
|
76
|
-
if params[:viewing_context] == "browse"
|
77
|
-
session[:viewing_context] = params[:viewing_context]
|
78
|
-
elsif session[:viewing_context] == "edit"
|
79
|
-
if can? :edit, params[:id]
|
80
|
-
logger.debug("enforce_viewing_context_for_show_requests redirecting to edit")
|
81
|
-
if params[:files]
|
82
|
-
redirect_to :action=>:edit, :files=>true
|
83
|
-
else
|
84
|
-
redirect_to :action=>:edit
|
85
|
-
end
|
86
|
-
else
|
87
|
-
session[:viewing_context] = "browse"
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
#
|
93
|
-
# Action-specific enforcement
|
94
|
-
#
|
95
|
-
|
96
|
-
# Controller "before" filter for enforcing access controls on show actions
|
97
|
-
# @param [Hash] opts (optional, not currently used)
|
98
|
-
def enforce_show_permissions(opts={})
|
99
|
-
load_permissions_from_solr
|
100
|
-
unless @permissions_solr_document['access_t'] && (@permissions_solr_document['access_t'].first == "public" || @permissions_solr_document['access_t'].first == "Public")
|
101
|
-
if @permissions_solr_document["embargo_release_date_dt"]
|
102
|
-
embargo_date = Date.parse(@permissions_solr_document["embargo_release_date_dt"].split(/T/)[0])
|
103
|
-
if embargo_date > Date.parse(Time.now.to_s)
|
104
|
-
### Assuming we're using devise and have only one authentication key
|
105
|
-
unless current_user && can?(:edit, params[:id])
|
106
|
-
flash[:alert] = "This item is under embargo. You do not have sufficient access privileges to read this document."
|
107
|
-
redirect_to(:action=>'index', :q=>nil, :f=>nil) and return false
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
unless can? :read, params[:id]
|
112
|
-
flash[:alert]= "You do not have sufficient access privileges to read this document, which has been marked private."
|
113
|
-
redirect_to(:action => 'index', :q => nil , :f => nil) and return false
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
# Controller "before" filter for enforcing access controls on edit actions
|
119
|
-
# @param [Hash] opts (optional, not currently used)
|
120
|
-
def enforce_edit_permissions(opts={})
|
121
|
-
logger.debug("Enforcing edit permissions")
|
122
|
-
load_permissions_from_solr
|
123
|
-
if !can? :edit, params[:id]
|
124
|
-
session[:viewing_context] = "browse"
|
125
|
-
flash[:notice] = "You do not have sufficient privileges to edit this document. You have been redirected to the read-only view."
|
126
|
-
redirect_to :action=>:show
|
127
|
-
else
|
128
|
-
session[:viewing_context] = "edit"
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
## proxies to enforce_edit_permssions. This method is here for you to override
|
133
|
-
def enforce_update_permissions(opts={})
|
134
|
-
enforce_edit_permissions(opts)
|
135
|
-
end
|
136
|
-
|
137
|
-
## proxies to enforce_edit_permssions. This method is here for you to override
|
138
|
-
def enforce_delete_permissions(opts={})
|
139
|
-
enforce_edit_permissions(opts)
|
140
|
-
end
|
141
|
-
|
142
|
-
# Controller "before" filter for enforcing access controls on index actions
|
143
|
-
# Currently does nothing, instead relies on
|
144
|
-
# @param [Hash] opts (optional, not currently used)
|
145
|
-
def enforce_index_permissions(opts={})
|
146
|
-
# Do nothing. Relies on enforce_search_permissions being included in the Controller's solr_search_params_logic
|
147
|
-
return true
|
148
|
-
end
|
149
|
-
|
150
|
-
#
|
151
|
-
# Solr query modifications
|
152
|
-
#
|
153
|
-
|
154
|
-
# Set solr_parameters to enforce appropriate permissions
|
155
|
-
# * Applies a lucene query to the solr :q parameter for gated discovery
|
156
|
-
# * Uses public_qt search handler if user does not have "read" permissions
|
157
|
-
# @param solr_parameters the current solr parameters
|
158
|
-
# @param user_parameters the current user-subitted parameters
|
159
|
-
#
|
160
|
-
# @example This method should be added to your Catalog Controller's solr_search_params_logic
|
161
|
-
# class CatalogController < ApplicationController
|
162
|
-
# include Hydra::Catalog
|
163
|
-
# CatalogController.solr_search_params_logic << :add_access_controls_to_solr_params
|
164
|
-
# end
|
165
|
-
def add_access_controls_to_solr_params(solr_parameters, user_parameters)
|
166
|
-
apply_gated_discovery(solr_parameters, user_parameters)
|
167
|
-
end
|
168
|
-
|
169
|
-
|
170
|
-
# Which permission levels (logical OR) will grant you the ability to discover documents in a search.
|
171
|
-
# Override this method if you want it to be something other than the default
|
172
|
-
def discovery_permissions
|
173
|
-
["edit","discover","read"]
|
174
|
-
end
|
175
|
-
|
176
|
-
# Contrller before filter that sets up access-controlled lucene query in order to provide gated discovery behavior
|
177
|
-
# @param solr_parameters the current solr parameters
|
178
|
-
# @param user_parameters the current user-subitted parameters
|
179
|
-
def apply_gated_discovery(solr_parameters, user_parameters)
|
180
|
-
solr_parameters[:fq] ||= []
|
181
|
-
# Grant access to public content
|
182
|
-
permission_types = discovery_permissions
|
183
|
-
user_access_filters = []
|
184
|
-
|
185
|
-
permission_types.each do |type|
|
186
|
-
user_access_filters << "#{type}_access_group_t:public"
|
187
|
-
end
|
188
|
-
|
189
|
-
# Grant access based on user id & role
|
190
|
-
unless current_user.nil?
|
191
|
-
# for roles
|
192
|
-
::RoleMapper.roles(user_key).each_with_index do |role, i|
|
193
|
-
permission_types.each do |type|
|
194
|
-
user_access_filters << "#{type}_access_group_t:#{role}"
|
195
|
-
end
|
196
|
-
end
|
197
|
-
# for individual person access
|
198
|
-
permission_types.each do |type|
|
199
|
-
user_access_filters << "#{type}_access_person_t:#{user_key}"
|
200
|
-
end
|
201
|
-
if Deprecation.silence(Hydra::SuperuserAttributes) { current_user.is_being_superuser?(session) }
|
202
|
-
permission_types.each do |type|
|
203
|
-
user_access_filters << "#{type}_access_person_t:[* TO *]"
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
# Enforcing Embargo at Query time has been disabled.
|
208
|
-
# If you want to do this, set up your own solr_search_params before_filter that injects the appropriate :fq constraints for a field that expresses your objects' embargo status.
|
209
|
-
#
|
210
|
-
# include docs in results if the embargo date is NOT in the future OR if the current user is depositor
|
211
|
-
# embargo_query = "(NOT embargo_release_date_dt:[NOW TO *]) OR depositor_t:#{user_key}"
|
212
|
-
# embargo_query = "(NOT embargo_release_date_dt:[NOW TO *]) OR (embargo_release_date_dt:[NOW TO *] AND depositor_t:#{user_key}) AND NOT (NOT depositor_t:#{user_key} AND embargo_release_date_dt:[NOW TO *])"
|
213
|
-
# solr_parameters[:fq] << embargo_query
|
214
|
-
end
|
215
|
-
solr_parameters[:fq] << user_access_filters.join(" OR ")
|
216
|
-
logger.debug("Solr parameters: #{ solr_parameters.inspect }")
|
217
|
-
end
|
218
|
-
|
219
|
-
|
220
|
-
# proxy for {enforce_index_permissions}
|
221
|
-
def enforce_search_permissions
|
222
|
-
enforce_index_permissions
|
223
|
-
end
|
224
|
-
|
225
|
-
# proxy for {enforce_show_permissions}
|
226
|
-
def enforce_read_permissions
|
227
|
-
enforce_show_permissions
|
228
|
-
end
|
229
|
-
|
230
|
-
# This filters out objects that you want to exclude from search results. By default it only excludes FileAssets
|
231
|
-
# @param solr_parameters the current solr parameters
|
232
|
-
# @param user_parameters the current user-subitted parameters
|
233
|
-
def exclude_unwanted_models(solr_parameters, user_parameters)
|
234
|
-
solr_parameters[:fq] ||= []
|
235
|
-
solr_parameters[:fq] << "-has_model_s:\"info:fedora/afmodel:FileAsset\""
|
236
|
-
end
|
237
|
-
end
|