-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathaccess_controls_enforcement.rb
47 lines (39 loc) · 1.42 KB
/
access_controls_enforcement.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
module Hydra::AccessControlsEnforcement
extend ActiveSupport::Concern
include Blacklight::AccessControls::Enforcement
def current_ability
@current_ability || (scope.current_ability if scope&.respond_to?(:current_ability))
end
def with_ability(ability)
params_will_change!
@current_ability = ability
self
end
def with_discovery_permissions(permissions)
params_will_change!
@discovery_permissions = Array(permissions)
self
end
protected
def under_embargo?
load_permissions_from_solr
embargo_key = Hydra.config.permissions.embargo.release_date
if @permissions_solr_document[embargo_key]
embargo_date = Date.parse(@permissions_solr_document[embargo_key].split(/T/)[0])
return embargo_date > Date.parse(Time.now.to_s)
end
false
end
# Which permission levels (logical OR) will grant you the ability to discover documents in a search.
# Overrides blacklight-access_controls method.
def discovery_permissions
@discovery_permissions ||= ["edit","discover","read"]
end
# Find the name of the solr field for this type of permission.
# e.g. "read_access_group_ssim" or "discover_access_person_ssim".
# Used by blacklight-access_controls.
def solr_field_for(permission_type, permission_category)
permissions = Hydra.config.permissions[permission_type.to_sym]
permission_category == 'group' ? permissions.group : permissions.individual
end
end