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

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: 08285f91280c40edeb4fc605b7d953b44a70d1f5
4
- data.tar.gz: 9f59a3412954e6e8f615bea4fa597e1017fa2158
3
+ metadata.gz: 4cbc85eecc7904f7f1b66f74700dd8598641be95
4
+ data.tar.gz: 11830ae7b14a2ecd73c6110e39fec83f51de8be0
5
5
  SHA512:
6
- metadata.gz: 93a2d9fe2e17186dbbd219ac14db54aa89056ea45bcbbdba01b91b93a9a8fe4bf05cb41a6a0c82ee927b3b3cf2f926d60e7e9c9a28f5cf1896fc5a71a46f363a
7
- data.tar.gz: c5d34233e4e9f2732636c1bdc5ce7cc66f6b97130c453081eb22fceff5a5dd2b6f0799f74bb7d8d0a1f403f8f7ea368c3f4af94f12020640bb30d4ff5a30d7cf
6
+ metadata.gz: 46f10df766dff5c1ebd73093e5db030eb46cb7400689c96f55463c56beb00bcd590c7d8b4329e79761b1035446cd23fa9b8a379008fb79319410d9d87b2ce8c3
7
+ data.tar.gz: 520bee3b4bfbcbceac1652864c724043e2926c4a63ce3872501328784dca91d8633a7a957927f3e8e81fb02a2b4c5e36015296c1f7fd748cf5000b891f6b5787
@@ -45,6 +45,8 @@ module Hydra
45
45
  has_visibility_text_for?(VISIBILITY_TEXT_VALUE_AUTHENTICATED)
46
46
  end
47
47
 
48
+ alias :authenticated_only_access? :authenticated_only?
49
+
48
50
  def private?
49
51
  return false if open_access?
50
52
  return false if authenticated_only?
@@ -52,6 +54,8 @@ module Hydra
52
54
  true
53
55
  end
54
56
 
57
+ alias :private_access? :private?
58
+
55
59
  private
56
60
 
57
61
  def persisted_open_access_permission?
@@ -75,7 +79,7 @@ module Hydra
75
79
  visibility == text
76
80
  end
77
81
  def has_permission_text_for?(text)
78
- !!permissions.detect { |perm| perm[:name] == text }
82
+ !!permissions.detect { |perm| perm.name == text }
79
83
  end
80
84
  end
81
85
  end
@@ -19,12 +19,12 @@ 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", '~> 6.1'
22
+ gem.add_dependency "active-fedora", '>= 6.6.0.rc1'
23
23
  gem.add_dependency 'cancan'
24
24
  gem.add_dependency 'deprecation'
25
25
  gem.add_dependency 'blacklight', '~> 4.0'
26
26
 
27
- gem.add_development_dependency("rake")
27
+ gem.add_development_dependency "rake"
28
28
  gem.add_development_dependency 'rspec'
29
29
 
30
30
 
@@ -4,20 +4,20 @@ class Hydra::AdminPolicy < ActiveFedora::Base
4
4
  # include Hydra::ModelMethods
5
5
 
6
6
  # Uses the Hydra Rights Metadata Schema for tracking access permissions & copyright
7
- has_metadata :name => "defaultRights", :type => Hydra::Datastream::InheritableRightsMetadata
7
+ has_metadata "defaultRights", type: Hydra::Datastream::InheritableRightsMetadata
8
8
 
9
9
  # Uses the Hydra Rights Metadata Schema for tracking access permissions & copyright
10
- has_metadata :name => "rightsMetadata", :type => Hydra::Datastream::RightsMetadata
10
+ has_metadata "rightsMetadata", type: Hydra::Datastream::RightsMetadata
11
11
 
12
- has_metadata :name =>'descMetadata', :type => ActiveFedora::QualifiedDublinCoreDatastream do |m|
12
+ has_metadata 'descMetadata', type: ActiveFedora::QualifiedDublinCoreDatastream do |m|
13
13
  m.title :type=> :text, :index_as=>[:searchable]
14
14
 
15
15
  end
16
16
 
17
- delegate_to :descMetadata, [:title, :description], :unique=>true
18
- delegate :license_title, :to=>'rightsMetadata', :at=>[:license, :title], :unique=>true
19
- delegate :license_description, :to=>'rightsMetadata', :at=>[:license, :description], :unique=>true
20
- delegate :license_url, :to=>'rightsMetadata', :at=>[:license, :url], :unique=>true
17
+ delegate_to :descMetadata, [:title, :description], multiple: false
18
+ delegate :license_title, to: 'rightsMetadata', at: [:license, :title], multiple: false
19
+ delegate :license_description, to: 'rightsMetadata', at: [:license, :description], multiple: false
20
+ delegate :license_url, to: 'rightsMetadata', at: [:license, :url], multiple: false
21
21
 
22
22
  # easy access to edit_groups, etc
23
23
  include Hydra::AccessControls::Permissions
@@ -24,18 +24,18 @@ module Hydra::PolicyAwareAbility
24
24
  end
25
25
 
26
26
  # Returns the pid of policy object (is_governed_by) for the specified object
27
- # Assumes that the policy object is associated by an is_governed_by relationship (Whis is stored as "is_governed_by_s" in object's solr document)
27
+ # Assumes that the policy object is associated by an is_governed_by relationship
28
+ # (which is stored as "is_governed_by_ssim" in object's solr document)
28
29
  # Returns nil if no policy associated with the object
29
30
  def policy_pid_for(object_pid)
30
- return @policy_pid if @policy_pid
31
- #is_governed_by_ssim
31
+ policy_pid = policy_pid_cache[object_pid]
32
+ return policy_pid if policy_pid
32
33
  solr_result = ActiveFedora::Base.find_with_conditions({:id=>object_pid}, :fl=>ActiveFedora::SolrService.solr_name('is_governed_by', :symbol))
33
34
  begin
34
- @policy_pid = value_from_solr_field(solr_result, ActiveFedora::SolrService.solr_name('is_governed_by', :symbol)).first.gsub("info:fedora/", "")
35
+ policy_pid_cache[object_pid] = policy_pid = value_from_solr_field(solr_result, ActiveFedora::SolrService.solr_name('is_governed_by', :symbol)).first.gsub("info:fedora/", "")
35
36
  rescue NoMethodError
36
- @policy_pid = nil
37
37
  end
38
- return @policy_pid
38
+ return policy_pid
39
39
  end
40
40
 
41
41
  # Returns the permissions solr document for policy_pid
@@ -127,4 +127,9 @@ module Hydra::PolicyAwareAbility
127
127
  return field_from_result[field_name]
128
128
  end
129
129
  end
130
+
131
+ def policy_pid_cache
132
+ @policy_pid_cache ||= {}
133
+ end
134
+
130
135
  end
@@ -38,7 +38,7 @@ describe Hydra::AccessControls::AccessRight do
38
38
  TEXT
39
39
 
40
40
  it spec_text do
41
- permissions = [{access: :edit, name: givin_permission}]
41
+ permissions = [Hydra::AccessControls::Permission.new({access: :edit, name: givin_permission})]
42
42
  permissionable = double(
43
43
  'permissionable',
44
44
  permissions: permissions,
@@ -34,7 +34,7 @@ describe Hydra::PolicyAwareAbility do
34
34
  ]
35
35
 
36
36
  @policy.save
37
- @asset = ModsAsset.new()
37
+ @asset = ModsAsset.new
38
38
  @asset.admin_policy = @policy
39
39
  @asset.save
40
40
  end
@@ -46,8 +46,31 @@ describe Hydra::PolicyAwareAbility do
46
46
  subject { PolicyAwareClass.new( User.new ) }
47
47
 
48
48
  describe "policy_pid_for" do
49
+ before do
50
+ @policy2 = Hydra::AdminPolicy.new
51
+ @policy2.default_permissions =
52
+ [
53
+ {:type=>"group", :access=>"read", :name=>"untenured-faculty"},
54
+ {:type=>"group", :access=>"edit", :name=>"awesome_kids"},
55
+ {:type=>"group", :access=>"edit", :name=>"bad_crowd"},
56
+ {:type=>"user", :access=>"read", :name=>"constantine"},
57
+ {:type=>"user", :access=>"edit", :name=>"brutus"}
58
+ ]
59
+ @policy2.save
60
+ @asset2 = ModsAsset.new
61
+ @asset2.admin_policy = @policy2
62
+ @asset2.save
63
+ @asset3 = ModsAsset.create
64
+ end
65
+ after do
66
+ @policy2.delete
67
+ @asset2.delete
68
+ @asset3.delete
69
+ end
49
70
  it "should retrieve the pid doc for the current object's governing policy" do
50
71
  subject.policy_pid_for(@asset.pid).should == @policy.pid
72
+ subject.policy_pid_for(@asset2.pid).should == @policy2.pid
73
+ subject.policy_pid_for(@asset3.pid).should be_nil
51
74
  end
52
75
  end
53
76
 
@@ -60,10 +83,80 @@ describe Hydra::PolicyAwareAbility do
60
83
  end
61
84
  end
62
85
  describe "test_edit_from_policy" do
63
- it "should test_edit_from_policy"
86
+ context "public user" do
87
+ it "should return false" do
88
+ subject.stub(:user_groups).and_return(["public"])
89
+ subject.test_edit_from_policy(@asset.pid).should be_false
90
+ end
91
+ end
92
+ context "registered user" do
93
+ it "should return false" do
94
+ subject.user_groups.should include("registered")
95
+ subject.test_edit_from_policy(@asset.pid).should be_false
96
+ end
97
+ end
98
+ context "user with policy read access only" do
99
+ it "should return false" do
100
+ subject.current_user.stub(:user_key).and_return("nero")
101
+ subject.test_edit_from_policy(@asset.pid).should be_false
102
+ end
103
+ end
104
+ context "user with policy edit access" do
105
+ it "should return true" do
106
+ subject.current_user.stub(:user_key).and_return("julius_caesar")
107
+ subject.test_edit_from_policy(@asset.pid).should be_true
108
+ end
109
+ end
110
+ context "user in group with policy read access" do
111
+ it "should return false" do
112
+ subject.stub(:user_groups).and_return(["africana-faculty"])
113
+ subject.test_edit_from_policy(@asset.pid).should be_false
114
+ end
115
+ end
116
+ context "user in group with policy edit access" do
117
+ it "should return true" do
118
+ subject.stub(:user_groups).and_return(["cool_kids"])
119
+ subject.test_edit_from_policy(@asset.pid).should be_true
120
+ end
121
+ end
64
122
  end
65
123
  describe "test_read_from_policy" do
66
- it "should test_read_from_policy"
124
+ context "public user" do
125
+ it "should return false" do
126
+ subject.stub(:user_groups).and_return(["public"])
127
+ subject.test_read_from_policy(@asset.pid).should be_false
128
+ end
129
+ end
130
+ context "registered user" do
131
+ it "should return false" do
132
+ subject.user_groups.should include("registered")
133
+ subject.test_read_from_policy(@asset.pid).should be_false
134
+ end
135
+ end
136
+ context "user with policy read access only" do
137
+ it "should return false" do
138
+ subject.current_user.stub(:user_key).and_return("nero")
139
+ subject.test_read_from_policy(@asset.pid).should be_true
140
+ end
141
+ end
142
+ context "user with policy edit access" do
143
+ it "should return true" do
144
+ subject.current_user.stub(:user_key).and_return("julius_caesar")
145
+ subject.test_read_from_policy(@asset.pid).should be_true
146
+ end
147
+ end
148
+ context "user in group with policy read access" do
149
+ it "should return false" do
150
+ subject.stub(:user_groups).and_return(["africana-faculty"])
151
+ subject.test_read_from_policy(@asset.pid).should be_true
152
+ end
153
+ end
154
+ context "user in group with policy edit access" do
155
+ it "should return true" do
156
+ subject.stub(:user_groups).and_return(["cool_kids"])
157
+ subject.test_read_from_policy(@asset.pid).should be_true
158
+ end
159
+ end
67
160
  end
68
161
  describe "edit_groups_from_policy" do
69
162
  it "should retrieve the list of groups with edit access from the policy" do
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe "WithAccessRight" do
4
+
5
+ before do
6
+ class TestClass < ActiveFedora::Base
7
+ include Hydra::AccessControls::Permissions
8
+ include Hydra::AccessControls::WithAccessRight
9
+ end
10
+ end
11
+
12
+ after do
13
+ Object.send(:remove_const, :TestClass)
14
+ end
15
+
16
+ subject { TestClass.new }
17
+
18
+ context "not persisted" do
19
+ context "when it is public" do
20
+ before { subject.visibility = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC}
21
+ its(:authenticated_only_access?) { should be_false}
22
+ its(:private_access?) { should be_false}
23
+ its(:open_access?) { should be_true}
24
+ its(:open_access_with_embargo_release_date?) { should be_false}
25
+ end
26
+
27
+ context "when it is private" do
28
+ before { subject.visibility = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE }
29
+ its(:authenticated_only_access?) { should be_false}
30
+ its(:private_access?) { should be_true}
31
+ its(:open_access?) { should be_false}
32
+ its(:open_access_with_embargo_release_date?) { should be_false}
33
+ end
34
+ end
35
+
36
+ context "persisted" do
37
+ before { subject.stub( persisted?: true) }
38
+ context "when it is public" do
39
+ before do
40
+ subject.visibility = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
41
+ end
42
+ its(:authenticated_only_access?) { should be_false}
43
+ its(:private_access?) { should be_false}
44
+ its(:open_access?) { should be_true}
45
+ its(:open_access_with_embargo_release_date?) { should be_false}
46
+ end
47
+
48
+ context "when it is private" do
49
+ before do
50
+ subject.visibility = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
51
+ end
52
+ its(:authenticated_only_access?) { should be_false}
53
+ its(:private_access?) { should be_true}
54
+ its(:open_access?) { should be_false}
55
+ its(:open_access_with_embargo_release_date?) { should be_false}
56
+ end
57
+
58
+ context "when it is authenticated access" do
59
+ before do
60
+ subject.visibility = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED
61
+ end
62
+ its(:authenticated_only_access?) { should be_true}
63
+ its(:private_access?) { should be_false}
64
+ its(:open_access?) { should be_false}
65
+ its(:open_access_with_embargo_release_date?) { should be_false}
66
+ end
67
+ end
68
+
69
+ 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: 6.4.0.rc1
4
+ version: 6.4.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: 2013-09-30 00:00:00.000000000 Z
13
+ date: 2013-10-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -30,16 +30,16 @@ dependencies:
30
30
  name: active-fedora
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - ~>
33
+ - - '>='
34
34
  - !ruby/object:Gem::Version
35
- version: '6.1'
35
+ version: 6.6.0.rc1
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: '6.1'
42
+ version: 6.6.0.rc1
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: cancan
45
45
  requirement: !ruby/object:Gem::Requirement
@@ -169,6 +169,7 @@ files:
169
169
  - spec/unit/rights_metadata_spec.rb
170
170
  - spec/unit/role_mapper_spec.rb
171
171
  - spec/unit/visibility_spec.rb
172
+ - spec/unit/with_access_right_spec.rb
172
173
  - tasks/hydra-access-controls.rake
173
174
  homepage: http://projecthydra.org
174
175
  licenses:
@@ -217,4 +218,5 @@ test_files:
217
218
  - spec/unit/rights_metadata_spec.rb
218
219
  - spec/unit/role_mapper_spec.rb
219
220
  - spec/unit/visibility_spec.rb
221
+ - spec/unit/with_access_right_spec.rb
220
222
  has_rdoc: