hydra-access-controls 7.1.0.rc1 → 7.1.0.rc2

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: cb1a2767144b61de76cedcc965dcd1d88bd12f46
4
- data.tar.gz: 16e60959b2f2782197a0833d365fa5ae815c19ba
3
+ metadata.gz: f11322c08f169903ee4db5becd7ab8228fee5536
4
+ data.tar.gz: 149d2abb10a3f1e812d4b914c42bee38451fb58e
5
5
  SHA512:
6
- metadata.gz: 37b630c64ad0407ac2bd7f61dc690a543c746aad151a81d24e931c62dfe06343dd65cefa559b637702d3111fb670ec05f8273c4a1c08f73bf1d4e295e11c8bea
7
- data.tar.gz: ad5aad6fbeaa457286db70a4d40e606b3b600d915eeca2fddd1cdf9979b44bad5f46825ff33ba38fba9725c065cb82a22cebbaa4b1030f9bda358093e123ce99
6
+ metadata.gz: b354963b372381e532658382bd583feb9e3cfeba345f4eed6fedf404e72bebf209d0f8d86062c2b4fd2d056a68eb416efdd389aee5bdde8c426597ee1f6ae10c
7
+ data.tar.gz: d7a24c9ddcc075d5beb6bc1251623ba34525c351ea75bb0ccafbf9269cf5eebc153f7e3e83d9b058b3e016f8bcac44c33a4d6506b61d664aa865fa4e1128636b
@@ -7,8 +7,7 @@ module Hydra
7
7
 
8
8
  # The values that get drawn to the page
9
9
  VISIBILITY_TEXT_VALUE_PUBLIC = 'open'.freeze
10
- VISIBILITY_TEXT_VALUE_EMBARGO = 'open_with_embargo_release_date'.freeze
11
- #VISIBILITY_TEXT_VALUE_EMBARGO = 'embargo'.freeze # << !! Will change to this in next major release !!
10
+ VISIBILITY_TEXT_VALUE_EMBARGO = 'embargo'.freeze
12
11
  VISIBILITY_TEXT_VALUE_LEASE = 'lease'.freeze
13
12
  VISIBILITY_TEXT_VALUE_AUTHENTICATED = 'authenticated'.freeze
14
13
  VISIBILITY_TEXT_VALUE_PRIVATE = 'restricted'.freeze
@@ -7,20 +7,19 @@ module Hydra
7
7
  included do
8
8
  validates :embargo_release_date, :'hydra/future_date' => true
9
9
 
10
- has_attributes :visibility_during_embargo, :visibility_after_embargo,
10
+ has_attributes :visibility_during_embargo, :visibility_after_embargo, :embargo_release_date,
11
11
  :visibility_during_lease, :visibility_after_lease, :lease_expiration_date,
12
- :embargo_release_date,
13
12
  datastream: 'rightsMetadata', multiple: false
14
13
 
15
14
  has_attributes :embargo_history, :lease_history, datastream: 'rightsMetadata', multiple:true
16
15
  end
17
16
 
18
17
  def under_embargo?
19
- @under_embargo ||= rightsMetadata.under_embargo?
18
+ rightsMetadata.under_embargo?
20
19
  end
21
20
 
22
21
  def active_lease?
23
- @active_lease ||= rightsMetadata.active_lease?
22
+ rightsMetadata.active_lease?
24
23
  end
25
24
 
26
25
  # If changing away from embargo or lease, this will deactivate the lease/embargo before proceeding.
@@ -40,12 +39,12 @@ module Hydra
40
39
  self.embargo_release_date = release_date
41
40
  self.visibility_during_embargo = visibility_during unless visibility_during.nil?
42
41
  self.visibility_after_embargo = visibility_after unless visibility_after.nil?
43
- self.embargo_visibility!
42
+ embargo_visibility!
44
43
  end
45
44
 
46
45
  def deactivate_embargo!
47
46
  embargo_state = under_embargo? ? "active" : "expired"
48
- embargo_record = "An #{embargo_state} embargo was deactivated on #{Date.today}. Its release date was #{embargo_release_date}. Visibility during embargo was #{visibility_during_embargo} and intended visibility after embargo was #{visibility_after_embargo}"
47
+ embargo_record = embargo_history_message(embargo_state, Date.today, embargo_release_date, visibility_during_embargo, visibility_after_embargo)
49
48
  self.embargo_release_date = nil
50
49
  self.visibility_during_embargo = nil
51
50
  self.visibility_after_embargo = nil
@@ -73,6 +72,7 @@ module Hydra
73
72
  end
74
73
  end
75
74
 
75
+ # Set the current visibility to match what is described in the embargo.
76
76
  def embargo_visibility!
77
77
  if embargo_release_date
78
78
  if under_embargo?
@@ -115,13 +115,14 @@ module Hydra
115
115
 
116
116
  def deactivate_lease!
117
117
  lease_state = active_lease? ? "active" : "expired"
118
- lease_record = "An #{lease_state} lease was deactivated on #{Date.today}. Its release date was #{lease_expiration_date}. Visibility during the lease was #{visibility_during_lease} and intended visibility after lease was #{visibility_after_lease}."
118
+ lease_record = lease_history_message(lease_state, Date.today, lease_expiration_date, visibility_during_lease, visibility_after_lease)
119
119
  self.lease_expiration_date = nil
120
120
  self.visibility_during_lease = nil
121
121
  self.visibility_after_lease = nil
122
122
  self.lease_history += [lease_record]
123
123
  end
124
124
 
125
+ # Set the current visibility to match what is described in the lease.
125
126
  def lease_visibility!
126
127
  if lease_expiration_date
127
128
  if active_lease?
@@ -134,6 +135,21 @@ module Hydra
134
135
  end
135
136
  end
136
137
 
138
+ protected
139
+
140
+ # Create the log message used when deactivating an embargo
141
+ # This method may be overriden in order to transform the values of the passed parameters.
142
+ def embargo_history_message(state, deactivate_date, release_date, visibility_during, visibility_after)
143
+ I18n.t 'hydra.embargo.history_message', state: state, deactivate_date: deactivate_date, release_date: release_date,
144
+ visibility_during: visibility_during, visibility_after: visibility_after
145
+ end
146
+
147
+ # Create the log message used when deactivating a lease
148
+ # This method may be overriden in order to transform the values of the passed parameters.
149
+ def lease_history_message(state, deactivate_date, expiration_date, visibility_during, visibility_after)
150
+ I18n.t 'hydra.lease.history_message', state: state, deactivate_date: deactivate_date, expiration_date: expiration_date,
151
+ visibility_during: visibility_during, visibility_after: visibility_after
152
+ end
137
153
  end
138
154
  end
139
155
  end
@@ -0,0 +1,6 @@
1
+ en:
2
+ hydra:
3
+ embargo:
4
+ history_message: 'An %{state} embargo was deactivated on %{deactivate_date}. Its release date was %{release_date}. Visibility during embargo was %{visibility_during} and intended visibility after embargo was %{visibility_after}'
5
+ lease:
6
+ history_message: 'An %{state} lease was deactivated on %{deactivate_date}. Its expiration date was %{expiration_date}. Visibility during the lease was %{visibility_during} and intended visibility after the lease was %{visibility_after}'
@@ -20,6 +20,7 @@ Gem::Specification.new do |gem|
20
20
 
21
21
  gem.add_dependency 'activesupport'
22
22
  gem.add_dependency "active-fedora", '~> 7.0.0'
23
+ gem.add_dependency "om", '~> 3.0', '>= 3.0.7'
23
24
  gem.add_dependency 'cancancan'
24
25
  gem.add_dependency 'deprecation'
25
26
  gem.add_dependency "blacklight", '~> 5.3'
@@ -61,16 +61,16 @@ module Hydra
61
61
 
62
62
  t.license(:ref=>[:copyright])
63
63
 
64
- t.visibility_during_embargo ref: [:embargo, :machine, :visibility_during]
65
- t.visibility_after_embargo ref: [:embargo, :machine, :visibility_after]
66
- t.visibility_during_lease ref: [:lease, :machine, :visibility_during]
67
- t.visibility_after_lease ref: [:lease, :machine, :visibility_after]
68
- t.embargo_history ref: [:embargo, :human_readable]
69
- t.lease_history ref: [:lease, :human_readable]
70
- t.embargo_release_date ref: [:embargo, :machine, :date], type: :time
71
- t.embargo_deactivation_date ref: [:embargo, :machine, :date_deactivated]
72
- t.lease_expiration_date ref: [:lease, :machine, :date], type: :time
73
- t.lease_deactivation_date ref: [:lease, :machine, :date_deactivated]
64
+ t.visibility_during_embargo proxy: [:embargo, :machine, :visibility_during]
65
+ t.visibility_after_embargo proxy: [:embargo, :machine, :visibility_after]
66
+ t.visibility_during_lease proxy: [:lease, :machine, :visibility_during]
67
+ t.visibility_after_lease proxy: [:lease, :machine, :visibility_after]
68
+ t.embargo_history proxy: [:embargo, :human_readable]
69
+ t.lease_history proxy: [:lease, :human_readable]
70
+ t.embargo_release_date proxy: [:embargo, :machine, :date], type: :time
71
+ t.embargo_deactivation_date proxy: [:embargo, :machine, :date_deactivated]
72
+ t.lease_expiration_date proxy: [:lease, :machine, :date], type: :time
73
+ t.lease_deactivation_date proxy: [:lease, :machine, :date_deactivated]
74
74
 
75
75
  end
76
76
 
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  ENV["environment"] ||= "test"
2
2
 
3
3
  require 'rspec/mocks'
4
- require 'rspec/autorun'
4
+ require 'rspec/its'
5
5
  require 'hydra-access-controls'
6
6
 
7
7
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
@@ -1,3 +1,6 @@
1
+ # Rails normally loads the locales of engines for us.
2
+ I18n.load_path << 'config/locale/hydra-access-controls.en.yml'
3
+
1
4
  module Rails
2
5
  def self.env
3
6
  ENV['environment']
@@ -48,16 +48,38 @@ describe Hydra::AccessControls::Embargoable do
48
48
  expect(subject.visibility_after_embargo).to eq Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED
49
49
  end
50
50
  end
51
+
51
52
  context 'deactivate_embargo!' do
52
- it "should remove the associated embargo information and record it in the object's embargo history" do
53
- subject.embargo_release_date = past_date.to_s
53
+ before do
54
54
  subject.visibility_during_embargo = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
55
55
  subject.visibility_after_embargo = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
56
- subject.deactivate_embargo!
57
- expect(subject.embargo_release_date).to be_nil
58
- expect(subject.visibility_during_embargo).to be_nil
59
- expect(subject.visibility_after_embargo).to be_nil
60
- expect(subject.embargo_history.last).to include("An expired embargo was deactivated on #{Date.today}.")
56
+ subject.embargo_release_date = release_date
57
+ end
58
+
59
+ context "when the embargo is expired" do
60
+ let(:release_date) { past_date.to_s }
61
+
62
+ it "should remove the associated embargo information and record it in the object's embargo history" do
63
+ subject.deactivate_embargo!
64
+ expect(subject.embargo_release_date).to be_nil
65
+ expect(subject.visibility_during_embargo).to be_nil
66
+ expect(subject.visibility_after_embargo).to be_nil
67
+ expect(subject.embargo_history.last).to include("An expired embargo was deactivated on #{Date.today}.")
68
+ end
69
+ end
70
+
71
+ context "when the embargo is active" do
72
+ let(:release_date) { future_date.to_s }
73
+
74
+ it "should remove the associated embargo information and record it in the object's embargo history" do
75
+ expect {
76
+ subject.deactivate_embargo!
77
+ }.to change { subject.under_embargo? }.from(true).to(false)
78
+ expect(subject.embargo_release_date).to be_nil
79
+ expect(subject.visibility_during_embargo).to be_nil
80
+ expect(subject.visibility_after_embargo).to be_nil
81
+ expect(subject.embargo_history.last).to include("An active embargo was deactivated on #{Date.today}.")
82
+ end
61
83
  end
62
84
  end
63
85
 
@@ -78,15 +100,35 @@ describe Hydra::AccessControls::Embargoable do
78
100
  end
79
101
 
80
102
  context 'deactivate_lease!' do
81
- it "should remove the associated embargo information and record it in the object's embargo history" do
82
- subject.lease_expiration_date = past_date.to_s
103
+ before do
104
+ subject.lease_expiration_date = expiration_date
83
105
  subject.visibility_during_lease = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
84
106
  subject.visibility_after_lease = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
85
- subject.deactivate_lease!
86
- expect(subject.lease_expiration_date).to be_nil
87
- expect(subject.visibility_during_lease).to be_nil
88
- expect(subject.visibility_after_lease).to be_nil
89
- expect(subject.lease_history.last).to include("An expired lease was deactivated on #{Date.today}.")
107
+ end
108
+
109
+ context "when the lease is expired" do
110
+ let(:expiration_date) { past_date.to_s }
111
+
112
+ it "should remove the associated lease information and record it in the object's lease history" do
113
+ subject.deactivate_lease!
114
+ expect(subject.lease_expiration_date).to be_nil
115
+ expect(subject.visibility_during_lease).to be_nil
116
+ expect(subject.visibility_after_lease).to be_nil
117
+ expect(subject.lease_history.last).to include("An expired lease was deactivated on #{Date.today}.")
118
+ end
119
+ end
120
+ context "when the lease is active" do
121
+ let(:expiration_date) { future_date.to_s }
122
+
123
+ it "should remove the associated lease information and record it in the object's lease history" do
124
+ expect {
125
+ subject.deactivate_lease!
126
+ }.to change { subject.active_lease? }.from(true).to(false)
127
+ expect(subject.lease_expiration_date).to be_nil
128
+ expect(subject.visibility_during_lease).to be_nil
129
+ expect(subject.visibility_after_lease).to be_nil
130
+ expect(subject.lease_history.last).to include("An active lease was deactivated on #{Date.today}.")
131
+ end
90
132
  end
91
133
  end
92
134
 
@@ -1,23 +1,17 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
- require "nokogiri"
3
2
 
4
3
  describe Hydra::Datastream::RightsMetadata do
5
-
6
- before(:each) do
7
- # The way RubyDora loads objects prevents us from stubbing the fedora connection :(
8
- # ActiveFedora::RubydoraConnection.stubs(:instance).returns(stub_everything())
9
- obj = ActiveFedora::Base.new
10
- @sample = Hydra::Datastream::RightsMetadata.new(obj.inner_object, nil)
11
- @sample.stub(:content).and_return('')
12
- end
13
4
 
5
+ let(:obj) { ActiveFedora::Base.new }
6
+ let(:sample) { Hydra::Datastream::RightsMetadata.new(obj.inner_object, nil) }
7
+
14
8
  describe "license" do
15
9
  before do
16
- @sample.license.title = "Creative Commons Attribution 3.0 Unported License."
17
- @sample.license.description = "This Creative Commons license lets others distribute, remix, tweak, and build upon your work, even commercially, as long as they credit you for the original creation. This is the most accommodating of licenses offered. Recommended for maximum dissemination and use of licensed materials."
18
- @sample.license.url = "http://creativecommons.org/licenses/by/3.0/"
10
+ sample.license.title = "Creative Commons Attribution 3.0 Unported License."
11
+ sample.license.description = "This Creative Commons license lets others distribute, remix, tweak, and build upon your work, even commercially, as long as they credit you for the original creation. This is the most accommodating of licenses offered. Recommended for maximum dissemination and use of licensed materials."
12
+ sample.license.url = "http://creativecommons.org/licenses/by/3.0/"
19
13
  end
20
- subject { @sample.license}
14
+ subject { sample.license}
21
15
  its(:title) {should == ["Creative Commons Attribution 3.0 Unported License."] }
22
16
  its(:description) { should == ["This Creative Commons license lets others distribute, remix, tweak, and build upon your work, even commercially, as long as they credit you for the original creation. This is the most accommodating of licenses offered. Recommended for maximum dissemination and use of licensed materials."] }
23
17
  its(:url) {should == ["http://creativecommons.org/licenses/by/3.0/"] }
@@ -25,131 +19,131 @@ describe Hydra::Datastream::RightsMetadata do
25
19
  it "should be accessable as a term path" do
26
20
  # This enables us to use:
27
21
  # delegate :license_title, :to=>'rightsMetadata', :at=>[:license, :title]
28
- @sample.term_values(:license, :title).should == ["Creative Commons Attribution 3.0 Unported License."]
22
+ sample.term_values(:license, :title).should == ["Creative Commons Attribution 3.0 Unported License."]
29
23
  end
30
24
  end
31
25
 
32
26
  describe "permissions" do
33
27
  describe "setter" do
34
28
  it "should set person permissions" do
35
- @sample.permissions = {"person"=>{"maria"=>"read","marcus"=>"discover"}}
29
+ sample.permissions = {"person"=>{"maria"=>"read","marcus"=>"discover"}}
36
30
  end
37
31
  it "should set group permissions" do
38
- @sample.permissions = {"group"=>{"librarians"=>"read","students"=>"discover"}}
32
+ sample.permissions = {"group"=>{"librarians"=>"read","students"=>"discover"}}
39
33
  end
40
34
  it "should create/update/delete permissions for the given user/group" do
41
- @sample.class.terminology.xpath_for(:access, :person, "person_123").should == '//oxns:access/oxns:machine/oxns:person[contains(., "person_123")]'
35
+ sample.class.terminology.xpath_for(:access, :person, "person_123").should == '//oxns:access/oxns:machine/oxns:person[contains(., "person_123")]'
42
36
 
43
- person_123_perms_xpath = @sample.class.terminology.xpath_for(:access, :person, "person_123")
44
- group_zzz_perms_xpath = @sample.class.terminology.xpath_for(:access, :group, "group_zzz")
37
+ person_123_perms_xpath = sample.class.terminology.xpath_for(:access, :person, "person_123")
38
+ group_zzz_perms_xpath = sample.class.terminology.xpath_for(:access, :group, "group_zzz")
45
39
 
46
- @sample.find_by_terms(person_123_perms_xpath).should be_empty
47
- @sample.permissions({"person"=>"person_123"}, "edit").should == "edit"
48
- @sample.permissions({"group"=>"group_zzz"}, "edit").should == "edit"
40
+ sample.find_by_terms(person_123_perms_xpath).should be_empty
41
+ sample.permissions({"person"=>"person_123"}, "edit").should == "edit"
42
+ sample.permissions({"group"=>"group_zzz"}, "edit").should == "edit"
49
43
 
50
- @sample.find_by_terms(person_123_perms_xpath).first.ancestors("access").first.attributes["type"].text.should == "edit"
51
- @sample.find_by_terms(group_zzz_perms_xpath).first.ancestors("access").first.attributes["type"].text.should == "edit"
44
+ sample.find_by_terms(person_123_perms_xpath).first.ancestors("access").first.attributes["type"].text.should == "edit"
45
+ sample.find_by_terms(group_zzz_perms_xpath).first.ancestors("access").first.attributes["type"].text.should == "edit"
52
46
 
53
- @sample.permissions({"person"=>"person_123"}, "read")
54
- @sample.permissions({"group"=>"group_zzz"}, "read")
55
- @sample.find_by_terms(person_123_perms_xpath).length.should == 1
47
+ sample.permissions({"person"=>"person_123"}, "read")
48
+ sample.permissions({"group"=>"group_zzz"}, "read")
49
+ sample.find_by_terms(person_123_perms_xpath).length.should == 1
56
50
 
57
- @sample.find_by_terms(person_123_perms_xpath).first.ancestors("access").first.attributes["type"].text.should == "read"
58
- @sample.find_by_terms(group_zzz_perms_xpath).first.ancestors("access").first.attributes["type"].text.should == "read"
51
+ sample.find_by_terms(person_123_perms_xpath).first.ancestors("access").first.attributes["type"].text.should == "read"
52
+ sample.find_by_terms(group_zzz_perms_xpath).first.ancestors("access").first.attributes["type"].text.should == "read"
59
53
 
60
- @sample.permissions({"person"=>"person_123"}, "none").should == "none"
61
- @sample.permissions({"group"=>"group_zzz"}, "none").should == "none"
62
- @sample.find_by_terms(person_123_perms_xpath).should be_empty
63
- @sample.find_by_terms(person_123_perms_xpath).should be_empty
54
+ sample.permissions({"person"=>"person_123"}, "none").should == "none"
55
+ sample.permissions({"group"=>"group_zzz"}, "none").should == "none"
56
+ sample.find_by_terms(person_123_perms_xpath).should be_empty
57
+ sample.find_by_terms(person_123_perms_xpath).should be_empty
64
58
  end
65
59
  it "should remove existing permissions (leaving only one permission level per user/group)" do
66
- person_123_perms_xpath = @sample.class.terminology.xpath_for(:access, :person, "person_123")
67
- group_zzz_perms_xpath = @sample.class.terminology.xpath_for(:access, :group, "group_zzz")
60
+ person_123_perms_xpath = sample.class.terminology.xpath_for(:access, :person, "person_123")
61
+ group_zzz_perms_xpath = sample.class.terminology.xpath_for(:access, :group, "group_zzz")
68
62
 
69
- @sample.find_by_terms(person_123_perms_xpath).length.should == 0
70
- @sample.find_by_terms(group_zzz_perms_xpath).length.should == 0
71
- @sample.permissions({"person"=>"person_123"}, "read")
72
- @sample.permissions({"group"=>"group_zzz"}, "read")
73
- @sample.find_by_terms(person_123_perms_xpath).length.should == 1
74
- @sample.find_by_terms(group_zzz_perms_xpath).length.should == 1
63
+ sample.find_by_terms(person_123_perms_xpath).length.should == 0
64
+ sample.find_by_terms(group_zzz_perms_xpath).length.should == 0
65
+ sample.permissions({"person"=>"person_123"}, "read")
66
+ sample.permissions({"group"=>"group_zzz"}, "read")
67
+ sample.find_by_terms(person_123_perms_xpath).length.should == 1
68
+ sample.find_by_terms(group_zzz_perms_xpath).length.should == 1
75
69
 
76
- @sample.permissions({"person"=>"person_123"}, "edit")
77
- @sample.permissions({"group"=>"group_zzz"}, "edit")
78
- @sample.find_by_terms(person_123_perms_xpath).length.should == 1
79
- @sample.find_by_terms(group_zzz_perms_xpath).length.should == 1
70
+ sample.permissions({"person"=>"person_123"}, "edit")
71
+ sample.permissions({"group"=>"group_zzz"}, "edit")
72
+ sample.find_by_terms(person_123_perms_xpath).length.should == 1
73
+ sample.find_by_terms(group_zzz_perms_xpath).length.should == 1
80
74
  end
81
75
  it "should not impact other users permissions" do
82
- @sample.permissions({"person"=>"person_123"}, "read")
83
- @sample.permissions({"person"=>"person_789"}, "edit")
76
+ sample.permissions({"person"=>"person_123"}, "read")
77
+ sample.permissions({"person"=>"person_789"}, "edit")
84
78
 
85
- @sample.permissions({"person"=>"person_123"}).should == "read"
86
- @sample.permissions({"person"=>"person_456"}, "read")
87
- @sample.permissions({"person"=>"person_123"}).should == "read"
88
- @sample.permissions({"person"=>"person_456"}).should == "read"
89
- @sample.permissions({"person"=>"person_789"}).should == "edit"
79
+ sample.permissions({"person"=>"person_123"}).should == "read"
80
+ sample.permissions({"person"=>"person_456"}, "read")
81
+ sample.permissions({"person"=>"person_123"}).should == "read"
82
+ sample.permissions({"person"=>"person_456"}).should == "read"
83
+ sample.permissions({"person"=>"person_789"}).should == "edit"
90
84
 
91
85
 
92
86
  end
93
87
  end
94
88
  describe "getter" do
95
89
  it "should return permissions level for the given user/group" do
96
- @sample.permissions({"person"=>"person_123"}, "edit")
97
- @sample.permissions({"group"=>"group_zzz"}, "discover")
98
- @sample.permissions({"person"=>"person_123"}).should == "edit"
99
- @sample.permissions({"group"=>"group_zzz"}).should == "discover"
100
- @sample.permissions({"group"=>"foo_people"}).should == "none"
90
+ sample.permissions({"person"=>"person_123"}, "edit")
91
+ sample.permissions({"group"=>"group_zzz"}, "discover")
92
+ sample.permissions({"person"=>"person_123"}).should == "edit"
93
+ sample.permissions({"group"=>"group_zzz"}).should == "discover"
94
+ sample.permissions({"group"=>"foo_people"}).should == "none"
101
95
  end
102
96
  end
103
97
  end
104
98
  describe "groups" do
105
99
  it "should return a hash of all groups with permissions set, along with their permission levels" do
106
- @sample.permissions({"group"=>"group_zzz"}, "edit")
107
- @sample.permissions({"group"=>"public"}, "discover")
100
+ sample.permissions({"group"=>"group_zzz"}, "edit")
101
+ sample.permissions({"group"=>"public"}, "discover")
108
102
 
109
- #@sample.groups.should == {"group_zzz"=>"edit", "public"=>"discover"}
110
- @sample.groups.should == {"public"=>"discover", "group_zzz"=>"edit"}
103
+ #sample.groups.should == {"group_zzz"=>"edit", "public"=>"discover"}
104
+ sample.groups.should == {"public"=>"discover", "group_zzz"=>"edit"}
111
105
  end
112
106
  end
113
107
  describe "individuals" do
114
108
  it "should return a hash of all individuals with permissions set, along with their permission levels" do
115
- @sample.permissions({"person"=>"person_123"}, "read")
116
- @sample.permissions({"person"=>"person_456"}, "edit")
117
- expect(@sample.users).to eq("person_123"=>"read", "person_456"=>"edit")
109
+ sample.permissions({"person"=>"person_123"}, "read")
110
+ sample.permissions({"person"=>"person_456"}, "edit")
111
+ expect(sample.users).to eq("person_123"=>"read", "person_456"=>"edit")
118
112
  end
119
113
  end
120
114
 
121
115
  describe "update_permissions" do
122
116
  it "should accept a hash of groups and persons, updating their permissions accordingly" do
123
- @sample.should_receive(:permissions).with({"group" => "group1"}, "discover")
124
- @sample.should_receive(:permissions).with({"group" => "group2"}, "edit")
125
- @sample.should_receive(:permissions).with({"person" => "person1"}, "read")
126
- @sample.should_receive(:permissions).with({"person" => "person2"}, "discover")
117
+ sample.should_receive(:permissions).with({"group" => "group1"}, "discover")
118
+ sample.should_receive(:permissions).with({"group" => "group2"}, "edit")
119
+ sample.should_receive(:permissions).with({"person" => "person1"}, "read")
120
+ sample.should_receive(:permissions).with({"person" => "person2"}, "discover")
127
121
 
128
- @sample.update_permissions( {"group"=>{"group1"=>"discover","group2"=>"edit"}, "person"=>{"person1"=>"read","person2"=>"discover"}} )
122
+ sample.update_permissions( {"group"=>{"group1"=>"discover","group2"=>"edit"}, "person"=>{"person1"=>"read","person2"=>"discover"}} )
129
123
  end
130
124
  end
131
125
 
132
126
  describe "clear_permissions!" do
133
127
  before do
134
- @sample.permissions({"person"=>"person_123"}, "read")
135
- @sample.permissions({"person"=>"person_456"}, "edit")
136
- @sample.permissions({"person"=>"person_789"}, "discover")
137
- @sample.permissions({"group"=>"group_123"}, "read")
138
- @sample.permissions({"group"=>"group_456"}, "edit")
139
- @sample.permissions({"group"=>"group_789"}, "discover")
128
+ sample.permissions({"person"=>"person_123"}, "read")
129
+ sample.permissions({"person"=>"person_456"}, "edit")
130
+ sample.permissions({"person"=>"person_789"}, "discover")
131
+ sample.permissions({"group"=>"group_123"}, "read")
132
+ sample.permissions({"group"=>"group_456"}, "edit")
133
+ sample.permissions({"group"=>"group_789"}, "discover")
140
134
  end
141
135
  it "clears permissions" do
142
- @sample.clear_permissions!
143
- expect(@sample.users).to eq({})
144
- expect(@sample.groups).to eq({})
136
+ sample.clear_permissions!
137
+ expect(sample.users).to eq({})
138
+ expect(sample.groups).to eq({})
145
139
  end
146
140
  end
147
141
 
148
142
  describe "to_solr" do
149
143
  it "should populate solr doc with the correct fields" do
150
144
  params = {[:edit_access, :person]=>"Lil Kim", [:edit_access, :group]=>["group1","group2"], [:discover_access, :group]=>["public"],[:discover_access, :person]=>["Joe Schmoe"]}
151
- @sample.update_values(params)
152
- solr_doc = @sample.to_solr
145
+ sample.update_values(params)
146
+ solr_doc = sample.to_solr
153
147
 
154
148
  solr_doc["edit_access_person_ssim"].should == ["Lil Kim"]
155
149
  solr_doc["edit_access_group_ssim"].sort.should == ["group1", "group2"]
@@ -169,111 +163,139 @@ describe Hydra::Datastream::RightsMetadata do
169
163
  end
170
164
 
171
165
  it "should solrize embargo information if set" do
172
- @sample.embargo_release_date = DateTime.parse("2010-12-01T23:59:59+0")
173
- solr_doc = @sample.to_solr
166
+ sample.embargo_release_date = DateTime.parse("2010-12-01T23:59:59+0")
167
+ solr_doc = sample.to_solr
174
168
  expect(solr_doc["embargo_release_date_dtsi"]).to eq "2010-12-01T23:59:59Z"
175
169
  end
176
170
 
177
171
  it "should solrize lease information if set" do
178
- @sample.lease_expiration_date = DateTime.parse("2010-12-01T23:59:59Z")
179
- solr_doc = @sample.to_solr
172
+ sample.lease_expiration_date = DateTime.parse("2010-12-01T23:59:59Z")
173
+ solr_doc = sample.to_solr
180
174
  expect(solr_doc["lease_expiration_date_dtsi"]).to eq "2010-12-01T23:59:59Z"
181
175
  end
182
176
  end
183
177
 
184
- #
185
- # Embargo
186
- #
187
- describe "embargo_release_date=" do
188
- it "should update the appropriate node with the value passed" do
189
- @sample.embargo_release_date = Date.parse("2010-12-01")
190
- expect(@sample.embargo_release_date).to eq [Date.parse("2010-12-01").to_time.utc]
191
- end
192
- it "should accept a nil value after having a date value" do
193
- @sample.embargo_release_date = Date.parse("2010-12-01")
194
- @sample.embargo_release_date = nil
195
- expect(@sample.embargo_release_date).to be_empty
196
- end
197
- end
178
+ describe "embargo" do
179
+ describe "embargo_release_date=" do
180
+ it "should update the appropriate node with the value passed" do
181
+ sample.embargo_release_date = Date.parse("2010-12-01")
182
+ expect(sample.embargo_release_date).to eq [Date.parse("2010-12-01").to_time.utc]
183
+ end
198
184
 
199
- describe "embargo_release_date" do
200
- it "should return solr formatted date" do
201
- @sample.embargo_release_date = DateTime.parse("2010-12-01T23:59:59Z")
202
- expect(@sample.embargo_release_date).to eq [DateTime.parse("2010-12-01T23:59:59Z")]
185
+ it "should accept a nil value after having a date value" do
186
+ sample.embargo_release_date = Date.parse("2010-12-01")
187
+ sample.embargo_release_date = nil
188
+ expect(sample.embargo_release_date).to be_empty
189
+ end
203
190
  end
204
- end
205
191
 
206
- describe "under_embargo?" do
207
- it "should return true if the current date is before the embargo release date" do
208
- @sample.embargo_release_date=Date.today+1.month
209
- expect(@sample).to be_under_embargo
210
- end
211
- it "should return false if the current date is after the embargo release date" do
212
- @sample.embargo_release_date=Date.today-1.month
213
- expect(@sample).to_not be_under_embargo
214
- end
215
- it "should return false if there is no embargo date" do
216
- @sample.embargo_release_date = nil
217
- expect(@sample).to_not be_under_embargo
218
- end
219
- end
220
- describe "visibility during/after embargo" do
221
- it "should track visibility values and index them into solr" do
222
- expect(@sample.visibility_during_embargo).to be_empty
223
- expect(@sample.visibility_after_embargo).to be_empty
224
- @sample.visibility_during_embargo = "private"
225
- @sample.visibility_after_embargo = "restricted"
226
- expect(@sample.visibility_during_embargo).to eq ["private"]
227
- expect(@sample.visibility_after_embargo).to eq ["restricted"]
228
- solr_doc = @sample.to_solr
229
- expect(solr_doc["visibility_during_embargo_ssim"]).to eq ["private"]
230
- expect(solr_doc["visibility_after_embargo_ssim"]).to eq ["restricted"]
192
+ describe "embargo_release_date" do
193
+ it "should return solr formatted date" do
194
+ sample.embargo_release_date = DateTime.parse("2010-12-01T23:59:59Z")
195
+ expect(sample.embargo_release_date).to eq [DateTime.parse("2010-12-01T23:59:59Z")]
196
+ end
231
197
  end
232
- end
233
198
 
234
- #
235
- # Leases
236
- #
237
- describe "lease_expiration_date=" do
238
- it "should update the appropriate node with the value passed" do
239
- @sample.lease_expiration_date = "2010-12-01"
240
- expect(@sample.lease_expiration_date).to eq [Date.parse("2010-12-01").to_time.utc]
199
+ describe "under_embargo?" do
200
+ it "should return true if the current date is before the embargo release date" do
201
+ sample.embargo_release_date=Date.today+1.month
202
+ expect(sample).to be_under_embargo
203
+ end
204
+
205
+ it "should return false if the current date is after the embargo release date" do
206
+ sample.embargo_release_date=Date.today-1.month
207
+ expect(sample).to_not be_under_embargo
208
+ end
209
+
210
+ it "should return false if there is no embargo date" do
211
+ sample.embargo_release_date = nil
212
+ expect(sample).to_not be_under_embargo
213
+ end
241
214
  end
242
- it "should only accept valid date values" do
243
215
 
216
+ describe "visibility during/after embargo" do
217
+ it "should track visibility values and index them into solr" do
218
+ expect(sample.visibility_during_embargo).to be_empty
219
+ expect(sample.visibility_after_embargo).to be_empty
220
+ sample.visibility_during_embargo = "private"
221
+ sample.visibility_after_embargo = "restricted"
222
+ expect(sample.visibility_during_embargo).to eq ["private"]
223
+ expect(sample.visibility_after_embargo).to eq ["restricted"]
224
+ solr_doc = sample.to_solr
225
+ expect(solr_doc["visibility_during_embargo_ssim"]).to eq ["private"]
226
+ expect(solr_doc["visibility_after_embargo_ssim"]).to eq ["restricted"]
227
+ end
228
+
229
+ it "has the correct xpath" do
230
+ expect(sample.visibility_during_embargo.xpath).to eq "//oxns:embargo/oxns:machine/oxns:visibility[@scope=\"during\"]"
231
+ expect(sample.visibility_after_embargo.xpath).to eq "//oxns:embargo/oxns:machine/oxns:visibility[@scope=\"after\"]"
232
+ end
244
233
  end
245
- it "should accept a nil value after having a date value" do
246
- @sample.lease_expiration_date = "2010-12-01"
247
- @sample.lease_expiration_date = nil
248
- expect(@sample.lease_expiration_date).to be_empty
234
+
235
+ describe 'embargo_history' do
236
+ subject { sample.embargo_history }
237
+ it "has the correct xpath" do
238
+ expect(subject.xpath).to eq '//oxns:embargo/oxns:human'
239
+ end
249
240
  end
250
241
  end
251
242
 
252
- describe "active_lease?" do
253
- it "should return true if the current date is after the lease expiration date" do
254
- @sample.lease_expiration_date = Date.today-1.month
255
- expect(@sample).to_not be_active_lease
243
+ describe "leases" do
244
+
245
+ describe "lease_expiration_date=" do
246
+ it "should update the appropriate node with the value passed" do
247
+ sample.lease_expiration_date = "2010-12-01"
248
+ expect(sample.lease_expiration_date).to eq [Date.parse("2010-12-01").to_time.utc]
249
+ end
250
+ it "should only accept valid date values" do
251
+
252
+ end
253
+ it "should accept a nil value after having a date value" do
254
+ sample.lease_expiration_date = "2010-12-01"
255
+ sample.lease_expiration_date = nil
256
+ expect(sample.lease_expiration_date).to be_empty
257
+ end
256
258
  end
257
- it "should return false if the current date is before the lease expiration date" do
258
- @sample.lease_expiration_date = Date.today+1.month
259
- expect(@sample).to be_active_lease
259
+
260
+ describe "active_lease?" do
261
+ it "should return true if the current date is after the lease expiration date" do
262
+ sample.lease_expiration_date = Date.today-1.month
263
+ expect(sample).to_not be_active_lease
264
+ end
265
+ it "should return false if the current date is before the lease expiration date" do
266
+ sample.lease_expiration_date = Date.today+1.month
267
+ expect(sample).to be_active_lease
268
+ end
269
+ it "should return false if there is no lease expiration date" do
270
+ sample.lease_expiration_date = nil
271
+ expect(sample).to_not be_active_lease
272
+ end
260
273
  end
261
- it "should return false if there is no lease expiration date" do
262
- @sample.lease_expiration_date = nil
263
- expect(@sample).to_not be_active_lease
274
+
275
+ describe "visibility during/after lease" do
276
+ it "should track visibility values and index them into solr" do
277
+ expect(sample.visibility_during_lease).to be_empty
278
+ expect(sample.visibility_after_lease).to be_empty
279
+ sample.visibility_during_lease = "restricted"
280
+ sample.visibility_after_lease = "private"
281
+ expect(sample.visibility_during_lease).to eq ["restricted"]
282
+ expect(sample.visibility_after_lease).to eq ["private"]
283
+ solr_doc = sample.to_solr
284
+ expect(solr_doc["visibility_during_lease_ssim"]).to eq ["restricted"]
285
+ expect(solr_doc["visibility_after_lease_ssim"]).to eq ["private"]
286
+ end
287
+
288
+ it "has the correct xpath" do
289
+ expect(sample.visibility_during_lease.xpath).to eq "//oxns:lease/oxns:machine/oxns:visibility[@scope=\"during\"]"
290
+ expect(sample.visibility_after_lease.xpath).to eq "//oxns:lease/oxns:machine/oxns:visibility[@scope=\"after\"]"
291
+ end
264
292
  end
265
- end
266
- describe "visibility during/after lease" do
267
- it "should track visibility values and index them into solr" do
268
- expect(@sample.visibility_during_lease).to be_empty
269
- expect(@sample.visibility_after_lease).to be_empty
270
- @sample.visibility_during_lease = "restricted"
271
- @sample.visibility_after_lease = "private"
272
- expect(@sample.visibility_during_lease).to eq ["restricted"]
273
- expect(@sample.visibility_after_lease).to eq ["private"]
274
- solr_doc = @sample.to_solr
275
- expect(solr_doc["visibility_during_lease_ssim"]).to eq ["restricted"]
276
- expect(solr_doc["visibility_after_lease_ssim"]).to eq ["private"]
293
+
294
+ describe 'lease_history' do
295
+ subject { sample.lease_history }
296
+ it "has the correct xpath" do
297
+ expect(subject.xpath).to eq '//oxns:lease/oxns:human'
298
+ end
277
299
  end
278
300
  end
279
301
  end
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.rc1
4
+ version: 7.1.0.rc2
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-05 00:00:00.000000000 Z
13
+ date: 2014-06-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -40,6 +40,26 @@ dependencies:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
42
  version: 7.0.0
43
+ - !ruby/object:Gem::Dependency
44
+ name: om
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '3.0'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 3.0.7
53
+ type: :runtime
54
+ prerelease: false
55
+ version_requirements: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '3.0'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 3.0.7
43
63
  - !ruby/object:Gem::Dependency
44
64
  name: cancancan
45
65
  requirement: !ruby/object:Gem::Requirement
@@ -147,6 +167,7 @@ files:
147
167
  - app/services/hydra/lease_service.rb
148
168
  - app/validators/hydra/future_date_validator.rb
149
169
  - config/fedora.yml
170
+ - config/locale/hydra-access-controls.en.yml
150
171
  - config/solr.yml
151
172
  - hydra-access-controls.gemspec
152
173
  - lib/active_fedora/accessible_by.rb