hydra-access-controls 7.2.0 → 7.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 44aafdf338a4b52e0e6167731b143c972e0128a2
4
- data.tar.gz: 7b38311e025e77f318acc5e5b8e5bcb150a7d841
3
+ metadata.gz: a5d5102b10b6d153f696ab99a80b4a7e6997b908
4
+ data.tar.gz: c609a6d44d6143918a340708aacd31b4ed2b41c4
5
5
  SHA512:
6
- metadata.gz: fa1f2d942f030d3a3bd4b2d9cc004fc7f6b34503ae10b93f9c75f770ec24571e0a821185eb293ca594409bf70333d35c178f42f8a1de9aef825c79425845e79b
7
- data.tar.gz: b2cf0122a5823a1321f3c0df3a0726c36449dcd78a566377cf1c203df892b4925da19a64159e672384edbaa0e04e1b92617f27497dfac1ff5be944cf49428eec
6
+ metadata.gz: 965849b283e9754b4f2248a5c0d409622921b21cde480755e34efbcb7f9fa31d324d640855064d0d8bc672cbc630139f23905c645f83996dff7a9a40b068e55f
7
+ data.tar.gz: cd37db01c12f66a4c1563a71c26f92f5420e4a84ea00274d23bf6ef0f2eb52a727b87c01685db5f49c4e3eb0b2caef9306cb50a772ef0abb9612e6a08293b413
@@ -2,9 +2,12 @@ module Hydra
2
2
  module AccessControls
3
3
  module Embargoable
4
4
  extend ActiveSupport::Concern
5
- include Hydra::AccessControls::WithAccessRight
6
5
 
7
6
  included do
7
+ include Hydra::AccessControls::WithAccessRight
8
+ # We include EmbargoableMethods so that it can override the methods included above,
9
+ # and doesn't create a ActiveSupport::Concern::MultipleIncludedBlocks
10
+ include EmbargoableMethods
8
11
  validates :embargo_release_date, :lease_expiration_date, :'hydra/future_date' => true
9
12
 
10
13
  has_attributes :visibility_during_embargo, :visibility_after_embargo, :embargo_release_date,
@@ -14,144 +17,146 @@ module Hydra
14
17
  has_attributes :embargo_history, :lease_history, datastream: 'rightsMetadata', multiple:true
15
18
  end
16
19
 
17
- def under_embargo?
18
- rightsMetadata.under_embargo?
19
- end
20
-
21
- def active_lease?
22
- rightsMetadata.active_lease?
23
- end
20
+ module EmbargoableMethods
21
+ def under_embargo?
22
+ rightsMetadata.under_embargo?
23
+ end
24
24
 
25
- # If changing away from embargo or lease, this will deactivate the lease/embargo before proceeding.
26
- # The lease_visibility! and embargo_visibility! methods rely on this to deactivate the lease when applicable.
27
- def visibility=(value)
28
- # If changing from embargo or lease, deactivate the lease/embargo and wipe out the associated metadata before proceeding
29
- if !embargo_release_date.nil?
30
- deactivate_embargo! unless value == visibility_during_embargo
25
+ def active_lease?
26
+ rightsMetadata.active_lease?
31
27
  end
32
- if !lease_expiration_date.nil?
33
- deactivate_lease! unless value == visibility_during_lease
28
+
29
+ # If changing away from embargo or lease, this will deactivate the lease/embargo before proceeding.
30
+ # The lease_visibility! and embargo_visibility! methods rely on this to deactivate the lease when applicable.
31
+ def visibility=(value)
32
+ # If changing from embargo or lease, deactivate the lease/embargo and wipe out the associated metadata before proceeding
33
+ if !embargo_release_date.nil?
34
+ deactivate_embargo! unless value == visibility_during_embargo
35
+ end
36
+ if !lease_expiration_date.nil?
37
+ deactivate_lease! unless value == visibility_during_lease
38
+ end
39
+ super
34
40
  end
35
- super
36
- end
37
41
 
38
- def apply_embargo(release_date, visibility_during=nil, visibility_after=nil)
39
- self.embargo_release_date = release_date
40
- self.visibility_during_embargo = visibility_during unless visibility_during.nil?
41
- self.visibility_after_embargo = visibility_after unless visibility_after.nil?
42
- embargo_visibility!
43
- end
42
+ def apply_embargo(release_date, visibility_during=nil, visibility_after=nil)
43
+ self.embargo_release_date = release_date
44
+ self.visibility_during_embargo = visibility_during unless visibility_during.nil?
45
+ self.visibility_after_embargo = visibility_after unless visibility_after.nil?
46
+ embargo_visibility!
47
+ end
44
48
 
45
- def deactivate_embargo!
46
- return unless embargo_release_date
47
- embargo_state = under_embargo? ? "active" : "expired"
48
- embargo_record = embargo_history_message(embargo_state, Date.today, embargo_release_date, visibility_during_embargo, visibility_after_embargo)
49
- self.embargo_release_date = nil
50
- self.visibility_during_embargo = nil
51
- self.visibility_after_embargo = nil
52
- self.embargo_history += [embargo_record]
53
- end
49
+ def deactivate_embargo!
50
+ return unless embargo_release_date
51
+ embargo_state = under_embargo? ? "active" : "expired"
52
+ embargo_record = embargo_history_message(embargo_state, Date.today, embargo_release_date, visibility_during_embargo, visibility_after_embargo)
53
+ self.embargo_release_date = nil
54
+ self.visibility_during_embargo = nil
55
+ self.visibility_after_embargo = nil
56
+ self.embargo_history += [embargo_record]
57
+ end
54
58
 
55
- def validate_embargo
56
- if embargo_release_date
57
- if under_embargo?
58
- expected_visibility = visibility_during_embargo
59
- failure_message = "An embargo is in effect for this object until #{embargo_release_date}. Until that time the "
59
+ def validate_embargo
60
+ if embargo_release_date
61
+ if under_embargo?
62
+ expected_visibility = visibility_during_embargo
63
+ failure_message = "An embargo is in effect for this object until #{embargo_release_date}. Until that time the "
64
+ else
65
+ expected_visibility = visibility_after_embargo
66
+ failure_message = "The embargo expired on #{embargo_release_date}. The "
67
+ end
68
+ if visibility == expected_visibility
69
+ return true
70
+ else
71
+ failure_message << "visibility should be #{expected_visibility} but it is currently #{visibility}. Call embargo_visibility! on this object to repair."
72
+ self.errors[:embargo] << failure_message
73
+ return false
74
+ end
60
75
  else
61
- expected_visibility = visibility_after_embargo
62
- failure_message = "The embargo expired on #{embargo_release_date}. The "
63
- end
64
- if visibility == expected_visibility
65
76
  return true
66
- else
67
- failure_message << "visibility should be #{expected_visibility} but it is currently #{visibility}. Call embargo_visibility! on this object to repair."
68
- self.errors[:embargo] << failure_message
69
- return false
70
77
  end
71
- else
72
- return true
73
78
  end
74
- end
75
79
 
76
- # Set the current visibility to match what is described in the embargo.
77
- def embargo_visibility!
78
- if embargo_release_date
79
- if under_embargo?
80
- self.visibility_during_embargo = visibility_during_embargo ? visibility_during_embargo : Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
81
- self.visibility_after_embargo = visibility_after_embargo ? visibility_after_embargo : Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED
82
- self.visibility = visibility_during_embargo
83
- else
84
- self.visibility = visibility_after_embargo ? visibility_after_embargo : Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED
80
+ # Set the current visibility to match what is described in the embargo.
81
+ def embargo_visibility!
82
+ if embargo_release_date
83
+ if under_embargo?
84
+ self.visibility_during_embargo = visibility_during_embargo ? visibility_during_embargo : Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
85
+ self.visibility_after_embargo = visibility_after_embargo ? visibility_after_embargo : Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED
86
+ self.visibility = visibility_during_embargo
87
+ else
88
+ self.visibility = visibility_after_embargo ? visibility_after_embargo : Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED
89
+ end
85
90
  end
86
91
  end
87
- end
88
92
 
89
- def validate_lease
90
- if lease_expiration_date
91
- if active_lease?
92
- expected_visibility = visibility_during_lease
93
- failure_message = "A lease is in effect for this object until #{lease_expiration_date}. Until that time the "
93
+ def validate_lease
94
+ if lease_expiration_date
95
+ if active_lease?
96
+ expected_visibility = visibility_during_lease
97
+ failure_message = "A lease is in effect for this object until #{lease_expiration_date}. Until that time the "
98
+ else
99
+ expected_visibility = visibility_after_lease
100
+ failure_message = "The lease expired on #{lease_expiration_date}. The "
101
+ end
102
+ if visibility == expected_visibility
103
+ return true
104
+ else
105
+ failure_message << "visibility should be #{expected_visibility} but it is currently #{visibility}. Call lease_visibility! on this object to repair."
106
+ self.errors[:lease] << failure_message
107
+ return false
108
+ end
94
109
  else
95
- expected_visibility = visibility_after_lease
96
- failure_message = "The lease expired on #{lease_expiration_date}. The "
97
- end
98
- if visibility == expected_visibility
99
110
  return true
100
- else
101
- failure_message << "visibility should be #{expected_visibility} but it is currently #{visibility}. Call lease_visibility! on this object to repair."
102
- self.errors[:lease] << failure_message
103
- return false
104
111
  end
105
- else
106
- return true
107
112
  end
108
- end
109
113
 
110
- def apply_lease(release_date, visibility_during=nil, visibility_after=nil)
111
- self.lease_expiration_date = release_date
112
- self.visibility_during_lease = visibility_during unless visibility_during.nil?
113
- self.visibility_after_lease = visibility_after unless visibility_after.nil?
114
- self.lease_visibility!
115
- end
114
+ def apply_lease(release_date, visibility_during=nil, visibility_after=nil)
115
+ self.lease_expiration_date = release_date
116
+ self.visibility_during_lease = visibility_during unless visibility_during.nil?
117
+ self.visibility_after_lease = visibility_after unless visibility_after.nil?
118
+ self.lease_visibility!
119
+ end
116
120
 
117
- def deactivate_lease!
118
- return unless lease_expiration_date
119
- lease_state = active_lease? ? "active" : "expired"
120
- lease_record = lease_history_message(lease_state, Date.today, lease_expiration_date, visibility_during_lease, visibility_after_lease)
121
- self.lease_expiration_date = nil
122
- self.visibility_during_lease = nil
123
- self.visibility_after_lease = nil
124
- self.lease_history += [lease_record]
125
- end
121
+ def deactivate_lease!
122
+ return unless lease_expiration_date
123
+ lease_state = active_lease? ? "active" : "expired"
124
+ lease_record = lease_history_message(lease_state, Date.today, lease_expiration_date, visibility_during_lease, visibility_after_lease)
125
+ self.lease_expiration_date = nil
126
+ self.visibility_during_lease = nil
127
+ self.visibility_after_lease = nil
128
+ self.lease_history += [lease_record]
129
+ end
126
130
 
127
- # Set the current visibility to match what is described in the lease.
128
- def lease_visibility!
129
- if lease_expiration_date
130
- if active_lease?
131
- self.visibility_during_lease = visibility_during_lease ? visibility_during_lease : Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED
132
- self.visibility_after_lease = visibility_after_lease ? visibility_after_lease : Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
133
- self.visibility = visibility_during_lease
134
- else
135
- self.visibility = visibility_after_lease ? visibility_after_lease : Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
131
+ # Set the current visibility to match what is described in the lease.
132
+ def lease_visibility!
133
+ if lease_expiration_date
134
+ if active_lease?
135
+ self.visibility_during_lease = visibility_during_lease ? visibility_during_lease : Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED
136
+ self.visibility_after_lease = visibility_after_lease ? visibility_after_lease : Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
137
+ self.visibility = visibility_during_lease
138
+ else
139
+ self.visibility = visibility_after_lease ? visibility_after_lease : Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
140
+ end
136
141
  end
137
142
  end
138
- end
139
143
 
140
- protected
144
+ protected
141
145
 
142
- # Create the log message used when deactivating an embargo
143
- # This method may be overriden in order to transform the values of the passed parameters.
144
- def embargo_history_message(state, deactivate_date, release_date, visibility_during, visibility_after)
145
- I18n.t 'hydra.embargo.history_message', state: state, deactivate_date: deactivate_date, release_date: release_date,
146
- visibility_during: visibility_during, visibility_after: visibility_after
147
- end
146
+ # Create the log message used when deactivating an embargo
147
+ # This method may be overriden in order to transform the values of the passed parameters.
148
+ def embargo_history_message(state, deactivate_date, release_date, visibility_during, visibility_after)
149
+ I18n.t 'hydra.embargo.history_message', state: state, deactivate_date: deactivate_date, release_date: release_date,
150
+ visibility_during: visibility_during, visibility_after: visibility_after
151
+ end
148
152
 
149
- # Create the log message used when deactivating a lease
150
- # This method may be overriden in order to transform the values of the passed parameters.
151
- def lease_history_message(state, deactivate_date, expiration_date, visibility_during, visibility_after)
152
- I18n.t 'hydra.lease.history_message', state: state, deactivate_date: deactivate_date, expiration_date: expiration_date,
153
- visibility_during: visibility_during, visibility_after: visibility_after
154
- end
153
+ # Create the log message used when deactivating a lease
154
+ # This method may be overriden in order to transform the values of the passed parameters.
155
+ def lease_history_message(state, deactivate_date, expiration_date, visibility_during, visibility_after)
156
+ I18n.t 'hydra.lease.history_message', state: state, deactivate_date: deactivate_date, expiration_date: expiration_date,
157
+ visibility_during: visibility_during, visibility_after: visibility_after
158
+ end
159
+ end
155
160
  end
156
161
  end
157
162
  end
@@ -3,9 +3,9 @@ module Hydra
3
3
  module Permissions
4
4
  extend ActiveSupport::Concern
5
5
  extend Deprecation
6
- include Hydra::AccessControls::Visibility
7
6
 
8
7
  included do
8
+ include Hydra::AccessControls::Visibility
9
9
  has_metadata "rightsMetadata", type: Hydra::Datastream::RightsMetadata
10
10
  end
11
11
 
@@ -2,7 +2,10 @@ module Hydra
2
2
  module AccessControls
3
3
  module WithAccessRight
4
4
  extend ActiveSupport::Concern
5
- include Hydra::AccessControls::Permissions
5
+
6
+ included do
7
+ include Hydra::AccessControls::Permissions
8
+ end
6
9
 
7
10
  delegate :open_access?, :open_access_with_embargo_release_date?,
8
11
  :authenticated_only_access?, :private_access?, to: :access_rights
@@ -7,8 +7,8 @@ describe Hydra::AccessControls::Embargoable do
7
7
  def save(returning_value = true)
8
8
  valid? && run_callbacks(:save) && !!returning_value
9
9
  end
10
-
11
- include Hydra::AccessControls::Embargoable
10
+
11
+ include Hydra::AccessControls::Embargoable
12
12
  }
13
13
  }
14
14
 
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.2.0
4
+ version: 7.2.1
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-07-18 00:00:00.000000000 Z
13
+ date: 2014-09-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -236,7 +236,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
236
236
  version: '0'
237
237
  requirements: []
238
238
  rubyforge_project:
239
- rubygems_version: 2.2.2
239
+ rubygems_version: 2.4.1
240
240
  signing_key:
241
241
  specification_version: 4
242
242
  summary: Access controls for project hydra