hydra-access-controls 7.1.0 → 7.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d571199bff2f9ddd36d310d407cf91ca6ae8ee39
4
- data.tar.gz: f0b1fbb7e08b80ca95f65f7482b88a4663d845ee
3
+ metadata.gz: 44aafdf338a4b52e0e6167731b143c972e0128a2
4
+ data.tar.gz: 7b38311e025e77f318acc5e5b8e5bcb150a7d841
5
5
  SHA512:
6
- metadata.gz: ff1a99172103f63cb660eec1df2b1cce4e9b5b69fac5c3a76d6c26dd3c1db95726a4f3b7125b8a1361d8a60042169bc0e91d45ac6ddddda978d58a603eafebec
7
- data.tar.gz: f28021dffed759533327bc3a360d1f5b208779fa639f4137b27258154b9afcb2b831dbc1b1dd9e10bf0ed87bf8a8d0b39af7b898f86d12a39f2ce717045ec7ab
6
+ metadata.gz: fa1f2d942f030d3a3bd4b2d9cc004fc7f6b34503ae10b93f9c75f770ec24571e0a821185eb293ca594409bf70333d35c178f42f8a1de9aef825c79425845e79b
7
+ data.tar.gz: b2cf0122a5823a1321f3c0df3a0726c36449dcd78a566377cf1c203df892b4925da19a64159e672384edbaa0e04e1b92617f27497dfac1ff5be944cf49428eec
@@ -43,6 +43,7 @@ module Hydra
43
43
  end
44
44
 
45
45
  def deactivate_embargo!
46
+ return unless embargo_release_date
46
47
  embargo_state = under_embargo? ? "active" : "expired"
47
48
  embargo_record = embargo_history_message(embargo_state, Date.today, embargo_release_date, visibility_during_embargo, visibility_after_embargo)
48
49
  self.embargo_release_date = nil
@@ -114,6 +115,7 @@ module Hydra
114
115
  end
115
116
 
116
117
  def deactivate_lease!
118
+ return unless lease_expiration_date
117
119
  lease_state = active_lease? ? "active" : "expired"
118
120
  lease_record = lease_history_message(lease_state, Date.today, lease_expiration_date, visibility_during_lease, visibility_after_lease)
119
121
  self.lease_expiration_date = nil
@@ -19,7 +19,7 @@ Gem::Specification.new do |gem|
19
19
  gem.required_ruby_version = '>= 1.9.3'
20
20
 
21
21
  gem.add_dependency 'activesupport'
22
- gem.add_dependency "active-fedora", '~> 7.0.0'
22
+ gem.add_dependency "active-fedora", '~> 7.0'
23
23
  gem.add_dependency "om", '~> 3.0', '>= 3.0.7'
24
24
  gem.add_dependency 'cancancan'
25
25
  gem.add_dependency 'deprecation'
@@ -48,7 +48,7 @@ module Hydra
48
48
 
49
49
 
50
50
  def hydra_default_permissions
51
- logger.debug("Usergroups are " + user_groups.inspect)
51
+ Rails.logger.debug("Usergroups are " + user_groups.inspect)
52
52
  self.ability_logic.each do |method|
53
53
  send(method)
54
54
  end
@@ -102,15 +102,15 @@ module Hydra
102
102
  protected
103
103
 
104
104
  def test_edit(pid)
105
- logger.debug("[CANCAN] Checking edit permissions for user: #{current_user.user_key} with groups: #{user_groups.inspect}")
105
+ Rails.logger.debug("[CANCAN] Checking edit permissions for user: #{current_user.user_key} with groups: #{user_groups.inspect}")
106
106
  group_intersection = user_groups & edit_groups(pid)
107
107
  result = !group_intersection.empty? || edit_users(pid).include?(current_user.user_key)
108
- logger.debug("[CANCAN] decision: #{result}")
108
+ Rails.logger.debug("[CANCAN] decision: #{result}")
109
109
  result
110
110
  end
111
111
 
112
112
  def test_read(pid)
113
- logger.debug("[CANCAN] Checking read permissions for user: #{current_user.user_key} with groups: #{user_groups.inspect}")
113
+ Rails.logger.debug("[CANCAN] Checking read permissions for user: #{current_user.user_key} with groups: #{user_groups.inspect}")
114
114
  group_intersection = user_groups & read_groups(pid)
115
115
  result = !group_intersection.empty? || read_users(pid).include?(current_user.user_key)
116
116
  result
@@ -120,7 +120,7 @@ module Hydra
120
120
  doc = permissions_doc(pid)
121
121
  return [] if doc.nil?
122
122
  eg = doc[self.class.edit_group_field] || []
123
- logger.debug("[CANCAN] edit_groups: #{eg.inspect}")
123
+ Rails.logger.debug("[CANCAN] edit_groups: #{eg.inspect}")
124
124
  return eg
125
125
  end
126
126
 
@@ -129,7 +129,7 @@ module Hydra
129
129
  doc = permissions_doc(pid)
130
130
  return [] if doc.nil?
131
131
  rg = edit_groups(pid) | (doc[self.class.read_group_field] || [])
132
- logger.debug("[CANCAN] read_groups: #{rg.inspect}")
132
+ Rails.logger.debug("[CANCAN] read_groups: #{rg.inspect}")
133
133
  return rg
134
134
  end
135
135
 
@@ -137,7 +137,7 @@ module Hydra
137
137
  doc = permissions_doc(pid)
138
138
  return [] if doc.nil?
139
139
  ep = doc[self.class.edit_user_field] || []
140
- logger.debug("[CANCAN] edit_users: #{ep.inspect}")
140
+ Rails.logger.debug("[CANCAN] edit_users: #{ep.inspect}")
141
141
  return ep
142
142
  end
143
143
 
@@ -146,7 +146,7 @@ module Hydra
146
146
  doc = permissions_doc(pid)
147
147
  return [] if doc.nil?
148
148
  rp = edit_users(pid) | (doc[self.class.read_user_field] || [])
149
- logger.debug("[CANCAN] read_users: #{rp.inspect}")
149
+ Rails.logger.debug("[CANCAN] read_users: #{rp.inspect}")
150
150
  return rp
151
151
  end
152
152
 
@@ -68,7 +68,7 @@ module Hydra
68
68
  when :policy_class
69
69
  self.policy_class = value
70
70
  when :owner
71
- logger.warn "':owner' is no longer a valid configuration for Hydra. Please remove it from your configuration."
71
+ Rails.logger.warn "':owner' is no longer a valid configuration for Hydra. Please remove it from your configuration."
72
72
  else
73
73
  raise "Unknown key `#{key.inspect}`"
74
74
  end
@@ -97,11 +97,9 @@ module Hydra
97
97
  xml.machine
98
98
  }
99
99
  xml.embargo{
100
- xml.human
101
100
  xml.machine
102
101
  }
103
102
  xml.lease{
104
- xml.human
105
103
  xml.machine
106
104
  }
107
105
  }
@@ -53,10 +53,10 @@ module Hydra::PolicyAwareAbility
53
53
  if policy_pid.nil?
54
54
  return false
55
55
  else
56
- logger.debug("[CANCAN] -policy- Does the POLICY #{policy_pid} provide EDIT permissions for #{current_user.user_key}?")
56
+ Rails.logger.debug("[CANCAN] -policy- Does the POLICY #{policy_pid} provide EDIT permissions for #{current_user.user_key}?")
57
57
  group_intersection = user_groups & edit_groups_from_policy( policy_pid )
58
58
  result = !group_intersection.empty? || edit_users_from_policy( policy_pid ).include?(current_user.user_key)
59
- logger.debug("[CANCAN] -policy- decision: #{result}")
59
+ Rails.logger.debug("[CANCAN] -policy- decision: #{result}")
60
60
  return result
61
61
  end
62
62
  end
@@ -67,10 +67,10 @@ module Hydra::PolicyAwareAbility
67
67
  if policy_pid.nil?
68
68
  return false
69
69
  else
70
- logger.debug("[CANCAN] -policy- Does the POLICY #{policy_pid} provide READ permissions for #{current_user.user_key}?")
70
+ Rails.logger.debug("[CANCAN] -policy- Does the POLICY #{policy_pid} provide READ permissions for #{current_user.user_key}?")
71
71
  group_intersection = user_groups & read_groups_from_policy( policy_pid )
72
72
  result = !group_intersection.empty? || read_users_from_policy( policy_pid ).include?(current_user.user_key)
73
- logger.debug("[CANCAN] -policy- decision: #{result}")
73
+ Rails.logger.debug("[CANCAN] -policy- decision: #{result}")
74
74
  result
75
75
  end
76
76
  end
@@ -80,7 +80,7 @@ module Hydra::PolicyAwareAbility
80
80
  policy_permissions = policy_permissions_doc(policy_pid)
81
81
  edit_group_field = Hydra.config[:permissions][:inheritable][:edit][:group]
82
82
  eg = ((policy_permissions == nil || policy_permissions.fetch(edit_group_field,nil) == nil) ? [] : policy_permissions.fetch(edit_group_field,nil))
83
- logger.debug("[CANCAN] -policy- edit_groups: #{eg.inspect}")
83
+ Rails.logger.debug("[CANCAN] -policy- edit_groups: #{eg.inspect}")
84
84
  return eg
85
85
  end
86
86
 
@@ -90,7 +90,7 @@ module Hydra::PolicyAwareAbility
90
90
  policy_permissions = policy_permissions_doc(policy_pid)
91
91
  read_group_field = Hydra.config[:permissions][:inheritable][:read][:group]
92
92
  rg = edit_groups_from_policy(policy_pid) | ((policy_permissions == nil || policy_permissions.fetch(read_group_field,nil) == nil) ? [] : policy_permissions.fetch(read_group_field,nil))
93
- logger.debug("[CANCAN] -policy- read_groups: #{rg.inspect}")
93
+ Rails.logger.debug("[CANCAN] -policy- read_groups: #{rg.inspect}")
94
94
  return rg
95
95
  end
96
96
 
@@ -104,7 +104,7 @@ module Hydra::PolicyAwareAbility
104
104
  policy_permissions = policy_permissions_doc(policy_pid)
105
105
  edit_user_field = Hydra.config[:permissions][:inheritable][:edit][:individual]
106
106
  eu = ((policy_permissions == nil || policy_permissions.fetch(edit_user_field,nil) == nil) ? [] : policy_permissions.fetch(edit_user_field,nil))
107
- logger.debug("[CANCAN] -policy- edit_users: #{eu.inspect}")
107
+ Rails.logger.debug("[CANCAN] -policy- edit_users: #{eu.inspect}")
108
108
  return eu
109
109
  end
110
110
 
@@ -119,7 +119,7 @@ module Hydra::PolicyAwareAbility
119
119
  policy_permissions = policy_permissions_doc(policy_pid)
120
120
  read_user_field = Hydra.config[:permissions][:inheritable][:read][:individual]
121
121
  ru = edit_users_from_policy(policy_pid) | ((policy_permissions == nil || policy_permissions.fetch(read_user_field, nil) == nil) ? [] : policy_permissions.fetch(read_user_field, nil))
122
- logger.debug("[CANCAN] -policy- read_users: #{ru.inspect}")
122
+ Rails.logger.debug("[CANCAN] -policy- read_users: #{ru.inspect}")
123
123
  return ru
124
124
  end
125
125
 
@@ -18,7 +18,6 @@ end
18
18
 
19
19
 
20
20
  require 'support/rails'
21
- Object.logger = Logger.new(File.expand_path('../test.log', __FILE__))
22
21
 
23
22
  # Since we're not doing a Rails Engine test, we have to load these classes manually:
24
23
  require_relative '../app/models/role_mapper'
@@ -2,15 +2,22 @@
2
2
  I18n.load_path << 'config/locales/hydra-access-controls.en.yml'
3
3
 
4
4
  module Rails
5
- def self.env
6
- ENV['environment']
7
- end
5
+ class << self
6
+ def env
7
+ ENV['environment']
8
+ end
8
9
 
9
- def self.version
10
- "0.0.0"
11
- #"hydra-access-controls mock rails"
12
- end
13
- def self.root
14
- 'spec/support'
10
+ def version
11
+ "0.0.0"
12
+ #"hydra-access-controls mock rails"
13
+ end
14
+
15
+ def root
16
+ 'spec/support'
17
+ end
18
+
19
+ def logger
20
+ @@logger ||= Logger.new(File.expand_path('../../test.log', __FILE__)).tap { |logger| logger.level = Logger::WARN }
21
+ end
15
22
  end
16
23
  end
@@ -12,6 +12,8 @@ describe Hydra::AccessControlsEnforcement do
12
12
 
13
13
  def session
14
14
  end
15
+
16
+ delegate :logger, to: :Rails
15
17
  end
16
18
  end
17
19
  subject { MockController.new }
@@ -23,14 +25,14 @@ describe Hydra::AccessControlsEnforcement do
23
25
  end
24
26
  context "Given I am not logged in" do
25
27
  before do
26
- subject.stub(:current_user).and_return(User.new(:new_record=>true))
28
+ allow(subject).to receive(:current_user).and_return(User.new(:new_record=>true))
27
29
  subject.send(:apply_gated_discovery, @solr_parameters, @user_parameters)
28
30
  end
29
31
  it "Then I should be treated as a member of the 'public' group" do
30
32
  expect(@solr_parameters[:fq].first).to eq 'edit_access_group_ssim:public OR discover_access_group_ssim:public OR read_access_group_ssim:public'
31
33
  end
32
34
  it "Then I should not be treated as a member of the 'registered' group" do
33
- @solr_parameters[:fq].first.should_not match(/registered/)
35
+ expect(@solr_parameters[:fq].first).to_not match(/registered/)
34
36
  end
35
37
  it "Then I should not have individual or group permissions"
36
38
  it "Should changed based on the discovery_perissions" do
@@ -38,7 +40,7 @@ describe Hydra::AccessControlsEnforcement do
38
40
  discovery_permissions = ["read","edit"]
39
41
  subject.send(:apply_gated_discovery, @solr_parameters, @user_parameters)
40
42
  ["edit","read"].each do |type|
41
- @solr_parameters[:fq].first.should match(/#{type}_access_group_ssim\:public/)
43
+ expect(@solr_parameters[:fq].first).to match(/#{type}_access_group_ssim\:public/)
42
44
  end
43
45
  end
44
46
  end
@@ -46,27 +48,27 @@ describe Hydra::AccessControlsEnforcement do
46
48
  before do
47
49
  @user = FactoryGirl.build(:martia_morocco)
48
50
  @user.new_record = false
49
- User.stub(:find_by_user_key).and_return(@user)
51
+ allow(User).to receive(:find_by_user_key).and_return(@user)
50
52
  # This is a pretty fragile way to stub it...
51
- RoleMapper.stub(:byname).and_return(@user.user_key=>["faculty", "africana-faculty"])
52
- subject.stub(:current_user).and_return(@user)
53
+ allow(RoleMapper).to receive(:byname).and_return(@user.user_key=>["faculty", "africana-faculty"])
54
+ allow(subject).to receive(:current_user).and_return(@user)
53
55
  subject.send(:apply_gated_discovery, @solr_parameters, @user_parameters)
54
56
  end
55
57
  it "Then I should be treated as a member of the 'public' and 'registered' groups" do
56
58
  ["discover","edit","read"].each do |type|
57
- @solr_parameters[:fq].first.should match(/#{type}_access_group_ssim\:public/)
58
- @solr_parameters[:fq].first.should match(/#{type}_access_group_ssim\:registered/)
59
+ expect(@solr_parameters[:fq].first).to match(/#{type}_access_group_ssim\:public/)
60
+ expect(@solr_parameters[:fq].first).to match(/#{type}_access_group_ssim\:registered/)
59
61
  end
60
62
  end
61
63
  it "Then I should see assets that I have discover, read, or edit access to" do
62
64
  ["discover","edit","read"].each do |type|
63
- @solr_parameters[:fq].first.should match(/#{type}_access_person_ssim\:#{@user.user_key}/)
65
+ expect(@solr_parameters[:fq].first).to match(/#{type}_access_person_ssim\:#{@user.user_key}/)
64
66
  end
65
67
  end
66
68
  it "Then I should see assets that my groups have discover, read, or edit access to" do
67
69
  ["faculty", "africana-faculty"].each do |group_id|
68
70
  ["discover","edit","read"].each do |type|
69
- @solr_parameters[:fq].first.should match(/#{type}_access_group_ssim\:#{group_id}/)
71
+ expect(@solr_parameters[:fq].first).to match(/#{type}_access_group_ssim\:#{group_id}/)
70
72
  end
71
73
  end
72
74
  end
@@ -76,7 +78,7 @@ describe Hydra::AccessControlsEnforcement do
76
78
  subject.send(:apply_gated_discovery, @solr_parameters, @user_parameters)
77
79
  ["faculty", "africana-faculty"].each do |group_id|
78
80
  ["edit","read"].each do |type|
79
- @solr_parameters[:fq].first.should match(/#{type}_access_group_ssim\:#{group_id}/)
81
+ expect(@solr_parameters[:fq].first).to match(/#{type}_access_group_ssim\:#{group_id}/)
80
82
  end
81
83
  end
82
84
  end
@@ -86,72 +88,73 @@ describe Hydra::AccessControlsEnforcement do
86
88
  describe "enforce_show_permissions" do
87
89
  it "should allow a user w/ edit permissions to view an embargoed object" do
88
90
  user = User.new :uid=>'testuser@example.com'
89
- RoleMapper.stub(:roles).with(user).and_return(["archivist"])
90
- subject.stub(:current_user).and_return(user)
91
- subject.stub(:can?).with(:read, nil).and_return(true)
91
+ allow(RoleMapper).to receive(:roles).with(user).and_return(["archivist"])
92
+ allow(subject).to receive(:current_user).and_return(user)
93
+ allow(subject).to receive(:can?).with(:read, nil).and_return(true)
92
94
  stub_doc = Hydra::PermissionsSolrDocument.new({"edit_access_person_ssim"=>["testuser@example.com"], "embargo_release_date_dtsi"=>(Date.parse(Time.now.to_s)+2).to_s})
93
95
 
94
96
  subject.params = {}
95
- subject.should_receive(:can?).with(:edit, stub_doc).and_return(true)
96
- subject.current_ability.should_receive(:get_permissions_solr_response_for_doc_id).and_return(stub_doc)
97
- expect {subject.send(:enforce_show_permissions, {}) }.not_to raise_error Hydra::AccessDenied
97
+ expect(subject).to receive(:can?).with(:edit, stub_doc).and_return(true)
98
+ expect(subject).to receive(:can?).with(:read, stub_doc).and_return(true)
99
+ expect(subject.current_ability).to receive(:get_permissions_solr_response_for_doc_id).and_return(stub_doc)
100
+ expect { subject.send(:enforce_show_permissions, {}) }.not_to raise_error
98
101
  end
99
102
  it "should prevent a user w/o edit permissions from viewing an embargoed object" do
100
103
  user = User.new :uid=>'testuser@example.com'
101
- RoleMapper.stub(:roles).with(user).and_return([])
102
- subject.stub(:current_user).and_return(user)
103
- subject.stub(:can?).with(:read, nil).and_return(true)
104
+ allow(RoleMapper).to receive(:roles).with(user).and_return([])
105
+ allow(subject).to receive(:current_user).and_return(user)
106
+ allow(subject).to receive(:can?).with(:read, nil).and_return(true)
104
107
  subject.params = {}
105
108
  stub_doc = Hydra::PermissionsSolrDocument.new({"edit_access_person_ssim"=>["testuser@example.com"], "embargo_release_date_dtsi"=>(Date.parse(Time.now.to_s)+2).to_s})
106
- subject.current_ability.should_receive(:get_permissions_solr_response_for_doc_id).and_return(stub_doc)
107
- subject.should_receive(:can?).with(:edit, stub_doc).and_return(false)
108
- lambda {subject.send(:enforce_show_permissions, {})}.should raise_error Hydra::AccessDenied, "This item is under embargo. You do not have sufficient access privileges to read this document."
109
+ expect(subject.current_ability).to receive(:get_permissions_solr_response_for_doc_id).and_return(stub_doc)
110
+ expect(subject).to receive(:can?).with(:edit, stub_doc).and_return(false)
111
+ expect {subject.send(:enforce_show_permissions, {})}.to raise_error Hydra::AccessDenied, "This item is under embargo. You do not have sufficient access privileges to read this document."
109
112
  end
110
113
  end
111
114
  describe "apply_gated_discovery" do
112
115
  before(:each) do
113
116
  @stub_user = User.new :uid=>'archivist1@example.com'
114
- RoleMapper.stub(:roles).with(@stub_user).and_return(["archivist","researcher"])
115
- subject.stub(:current_user).and_return(@stub_user)
117
+ allow(RoleMapper).to receive(:roles).with(@stub_user).and_return(["archivist","researcher"])
118
+ allow(subject).to receive(:current_user).and_return(@stub_user)
116
119
  @solr_parameters = {}
117
120
  @user_parameters = {}
118
121
  end
119
122
  it "should set query fields for the user id checking against the discover, access, read fields" do
120
123
  subject.send(:apply_gated_discovery, @solr_parameters, @user_parameters)
121
124
  ["discover","edit","read"].each do |type|
122
- @solr_parameters[:fq].first.should match(/#{type}_access_person_ssim\:#{@stub_user.user_key}/)
125
+ expect(@solr_parameters[:fq].first).to match(/#{type}_access_person_ssim\:#{@stub_user.user_key}/)
123
126
  end
124
127
  end
125
128
  it "should set query fields for all roles the user is a member of checking against the discover, access, read fields" do
126
129
  subject.send(:apply_gated_discovery, @solr_parameters, @user_parameters)
127
130
  ["discover","edit","read"].each do |type|
128
- @solr_parameters[:fq].first.should match(/#{type}_access_group_ssim\:archivist/)
129
- @solr_parameters[:fq].first.should match(/#{type}_access_group_ssim\:researcher/)
131
+ expect(@solr_parameters[:fq].first).to match(/#{type}_access_group_ssim\:archivist/)
132
+ expect(@solr_parameters[:fq].first).to match(/#{type}_access_group_ssim\:researcher/)
130
133
  end
131
134
  end
132
135
 
133
136
  it "should escape slashes in the group names" do
134
- RoleMapper.stub(:roles).with(@stub_user).and_return(["abc/123","cde/567"])
137
+ allow(RoleMapper).to receive(:roles).with(@stub_user).and_return(["abc/123","cde/567"])
135
138
  subject.send(:apply_gated_discovery, @solr_parameters, @user_parameters)
136
139
  ["discover","edit","read"].each do |type|
137
- @solr_parameters[:fq].first.should match(/#{type}_access_group_ssim\:abc\\\/123/)
138
- @solr_parameters[:fq].first.should match(/#{type}_access_group_ssim\:cde\\\/567/)
140
+ expect(@solr_parameters[:fq].first).to match(/#{type}_access_group_ssim\:abc\\\/123/)
141
+ expect(@solr_parameters[:fq].first).to match(/#{type}_access_group_ssim\:cde\\\/567/)
139
142
  end
140
143
  end
141
144
  it "should escape spaces in the group names" do
142
- RoleMapper.stub(:roles).with(@stub_user).and_return(["abc 123","cd/e 567"])
145
+ allow(RoleMapper).to receive(:roles).with(@stub_user).and_return(["abc 123","cd/e 567"])
143
146
  subject.send(:apply_gated_discovery, @solr_parameters, @user_parameters)
144
147
  ["discover","edit","read"].each do |type|
145
- @solr_parameters[:fq].first.should match(/#{type}_access_group_ssim\:abc\\ 123/)
146
- @solr_parameters[:fq].first.should match(/#{type}_access_group_ssim\:cd\\\/e\\ 567/)
148
+ expect(@solr_parameters[:fq].first).to match(/#{type}_access_group_ssim\:abc\\ 123/)
149
+ expect(@solr_parameters[:fq].first).to match(/#{type}_access_group_ssim\:cd\\\/e\\ 567/)
147
150
  end
148
151
  end
149
152
  it "should escape colons in the group names" do
150
- RoleMapper.stub(:roles).with(@stub_user).and_return(["abc:123","cde:567"])
153
+ allow(RoleMapper).to receive(:roles).with(@stub_user).and_return(["abc:123","cde:567"])
151
154
  subject.send(:apply_gated_discovery, @solr_parameters, @user_parameters)
152
155
  ["discover","edit","read"].each do |type|
153
- @solr_parameters[:fq].first.should match(/#{type}_access_group_ssim\:abc\\:123/)
154
- @solr_parameters[:fq].first.should match(/#{type}_access_group_ssim\:cde\\:567/)
156
+ expect(@solr_parameters[:fq].first).to match(/#{type}_access_group_ssim\:abc\\:123/)
157
+ expect(@solr_parameters[:fq].first).to match(/#{type}_access_group_ssim\:cde\\:567/)
155
158
  end
156
159
  end
157
160
  end
@@ -160,19 +163,19 @@ describe Hydra::AccessControlsEnforcement do
160
163
  describe "when the user is a guest user (user key nil)" do
161
164
  before do
162
165
  stub_user = User.new
163
- subject.stub(:current_user).and_return(stub_user)
166
+ allow(subject).to receive(:current_user).and_return(stub_user)
164
167
  end
165
168
  it "should not create filters" do
166
- subject.send(:apply_user_permissions, ["edit","discover","read"]).should == []
169
+ expect(subject.send(:apply_user_permissions, ["edit","discover","read"])).to eq []
167
170
  end
168
171
  end
169
172
  describe "when the user is a guest user (user key empty string)" do
170
173
  before do
171
174
  stub_user = User.new :uid=>''
172
- subject.stub(:current_user).and_return(stub_user)
175
+ allow(subject).to receive(:current_user).and_return(stub_user)
173
176
  end
174
177
  it "should not create filters" do
175
- subject.send(:apply_user_permissions, ["edit","discover","read"]).should == []
178
+ expect(subject.send(:apply_user_permissions, ["edit","discover","read"])).to eq []
176
179
  end
177
180
  end
178
181
  end
@@ -73,7 +73,8 @@ describe Hydra::AccessControls::Embargoable do
73
73
  expect(subject.embargo_release_date).to be_nil
74
74
  expect(subject.visibility_during_embargo).to be_nil
75
75
  expect(subject.visibility_after_embargo).to be_nil
76
- expect(subject.embargo_history.last).to include("An expired embargo was deactivated on #{Date.today}.")
76
+ expect(subject.embargo_history.size).to eq 1
77
+ expect(subject.embargo_history.first).to include("An expired embargo was deactivated on #{Date.today}.")
77
78
  end
78
79
  end
79
80
 
@@ -87,7 +88,17 @@ describe Hydra::AccessControls::Embargoable do
87
88
  expect(subject.embargo_release_date).to be_nil
88
89
  expect(subject.visibility_during_embargo).to be_nil
89
90
  expect(subject.visibility_after_embargo).to be_nil
90
- expect(subject.embargo_history.last).to include("An active embargo was deactivated on #{Date.today}.")
91
+ expect(subject.embargo_history.size).to eq 1
92
+ expect(subject.embargo_history.first).to include("An active embargo was deactivated on #{Date.today}.")
93
+ end
94
+ end
95
+
96
+ context "when there is no embargo" do
97
+ let(:release_date) { nil }
98
+
99
+ it "should not do anything" do
100
+ subject.deactivate_embargo!
101
+ expect(subject.embargo_history).to eq []
91
102
  end
92
103
  end
93
104
  end
@@ -123,9 +134,11 @@ describe Hydra::AccessControls::Embargoable do
123
134
  expect(subject.lease_expiration_date).to be_nil
124
135
  expect(subject.visibility_during_lease).to be_nil
125
136
  expect(subject.visibility_after_lease).to be_nil
126
- expect(subject.lease_history.last).to include("An expired lease was deactivated on #{Date.today}.")
137
+ expect(subject.lease_history.size).to eq 1
138
+ expect(subject.lease_history.first).to include("An expired lease was deactivated on #{Date.today}.")
127
139
  end
128
140
  end
141
+
129
142
  context "when the lease is active" do
130
143
  let(:expiration_date) { future_date.to_s }
131
144
 
@@ -136,7 +149,17 @@ describe Hydra::AccessControls::Embargoable do
136
149
  expect(subject.lease_expiration_date).to be_nil
137
150
  expect(subject.visibility_during_lease).to be_nil
138
151
  expect(subject.visibility_after_lease).to be_nil
139
- expect(subject.lease_history.last).to include("An active lease was deactivated on #{Date.today}.")
152
+ expect(subject.lease_history.size).to eq 1
153
+ expect(subject.lease_history.first).to include("An active lease was deactivated on #{Date.today}.")
154
+ end
155
+ end
156
+
157
+ context "when there is no lease" do
158
+ let(:expiration_date) { nil }
159
+
160
+ it "should not do anything" do
161
+ subject.deactivate_lease!
162
+ expect(subject.lease_history).to eq []
140
163
  end
141
164
  end
142
165
  end
@@ -13,6 +13,8 @@ describe Hydra::PolicyAwareAccessControlsEnforcement do
13
13
 
14
14
  def session
15
15
  end
16
+
17
+ delegate :logger, to: :Rails
16
18
  end
17
19
 
18
20
  @sample_policies = []
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-access-controls
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.1.0
4
+ version: 7.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-06-23 00:00:00.000000000 Z
13
+ date: 2014-07-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -32,14 +32,14 @@ dependencies:
32
32
  requirements:
33
33
  - - "~>"
34
34
  - !ruby/object:Gem::Version
35
- version: 7.0.0
35
+ version: '7.0'
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
- version: 7.0.0
42
+ version: '7.0'
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: om
45
45
  requirement: !ruby/object:Gem::Requirement