hydra-access-controls 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +7 -0
- data/Rakefile +4 -4
- data/hydra-access-controls.gemspec +2 -0
- data/lib/hydra-access-controls.rb +9 -1
- data/lib/hydra-access-controls/version.rb +1 -1
- data/lib/hydra/ability.rb +5 -1
- data/lib/hydra/access_controls_enforcement.rb +13 -1
- data/lib/hydra/datastream/rights_metadata.rb +12 -5
- data/spec/spec_helper.rb +8 -8
- data/spec/unit/ability_spec.rb +6 -0
- data/spec/unit/hydra_rights_metadata_spec.rb +18 -0
- data/spec/unit/rights_metadata_spec.rb +0 -1
- metadata +19 -4
- data/lib/hydra/model_mixins.rb +0 -7
data/Gemfile
CHANGED
@@ -2,3 +2,10 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in hydra-access-controls.gemspec
|
4
4
|
gemspec
|
5
|
+
|
6
|
+
group :test do
|
7
|
+
gem 'cucumber-rails', '>=1.2.0', :require=>false
|
8
|
+
gem 'rcov', :platform => :mri_18
|
9
|
+
gem 'simplecov', :platform => :mri_19
|
10
|
+
gem 'simplecov-rcov', :platform => :mri_19
|
11
|
+
end
|
data/Rakefile
CHANGED
@@ -7,10 +7,10 @@ task :default => :spec
|
|
7
7
|
|
8
8
|
desc "Run specs"
|
9
9
|
RSpec::Core::RakeTask.new do |t|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
if ENV['COVERAGE'] and RUBY_VERSION =~ /^1.8/
|
11
|
+
t.rcov = true
|
12
|
+
t.rcov_opts = %w{--exclude spec\/*,gems\/*,ruby\/* --aggregate coverage.data}
|
13
|
+
end
|
14
14
|
end
|
15
15
|
|
16
16
|
|
@@ -2,7 +2,10 @@ require 'active_support'
|
|
2
2
|
require 'active-fedora'
|
3
3
|
require 'deprecation'
|
4
4
|
require "hydra-access-controls/version"
|
5
|
-
|
5
|
+
begin
|
6
|
+
require 'hydra/model_mixins'
|
7
|
+
rescue LoadError
|
8
|
+
end
|
6
9
|
require 'hydra/datastream'
|
7
10
|
|
8
11
|
module Hydra
|
@@ -11,6 +14,11 @@ module Hydra
|
|
11
14
|
autoload :AccessControlsEvaluation
|
12
15
|
autoload :Ability
|
13
16
|
autoload :RoleMapperBehavior
|
17
|
+
|
18
|
+
module ModelMixins
|
19
|
+
autoload :RightsMetadata, 'hydra/model_mixins/rights_metadata'
|
20
|
+
end
|
21
|
+
|
14
22
|
end
|
15
23
|
require 'ability'
|
16
24
|
require 'role_mapper'
|
data/lib/hydra/ability.rb
CHANGED
@@ -27,12 +27,17 @@ module Hydra::Ability
|
|
27
27
|
if Deprecation.silence(Hydra::SuperuserAttributes) { user.is_being_superuser?(session) }
|
28
28
|
can :manage, :all
|
29
29
|
else
|
30
|
+
create_permissions(user, session)
|
30
31
|
edit_permissions(user, session)
|
31
32
|
read_permissions(user, session)
|
32
33
|
custom_permissions(user, session)
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
37
|
+
def create_permissions(user, session)
|
38
|
+
can :create, :all if user_groups(user, session).include? 'registered'
|
39
|
+
end
|
40
|
+
|
36
41
|
def edit_permissions(user, session)
|
37
42
|
can :edit, String do |pid|
|
38
43
|
test_edit(pid, user, session)
|
@@ -46,7 +51,6 @@ module Hydra::Ability
|
|
46
51
|
@permissions_solr_document = obj
|
47
52
|
test_edit(obj.id, user, session)
|
48
53
|
end
|
49
|
-
|
50
54
|
end
|
51
55
|
|
52
56
|
def read_permissions(user, session)
|
@@ -19,7 +19,6 @@ module Hydra::AccessControlsEnforcement
|
|
19
19
|
# end
|
20
20
|
def enforce_access_controls(opts={})
|
21
21
|
controller_action = params[:action].to_s
|
22
|
-
controller_action = "edit" if params[:action] == "destroy"
|
23
22
|
delegate_method = "enforce_#{controller_action}_permissions"
|
24
23
|
if self.respond_to?(delegate_method.to_sym, true)
|
25
24
|
self.send(delegate_method.to_sym)
|
@@ -126,6 +125,14 @@ module Hydra::AccessControlsEnforcement
|
|
126
125
|
end
|
127
126
|
end
|
128
127
|
|
128
|
+
## This method is here for you to override
|
129
|
+
def enforce_create_permissions(opts={})
|
130
|
+
logger.debug("Enforcing create permissions")
|
131
|
+
if !can? :create, ActiveFedora::Base.new
|
132
|
+
raise Hydra::AccessDenied.new "You do not have sufficient privileges to create a new document."
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
129
136
|
## proxies to enforce_edit_permssions. This method is here for you to override
|
130
137
|
def enforce_update_permissions(opts={})
|
131
138
|
enforce_edit_permissions(opts)
|
@@ -136,6 +143,11 @@ module Hydra::AccessControlsEnforcement
|
|
136
143
|
enforce_edit_permissions(opts)
|
137
144
|
end
|
138
145
|
|
146
|
+
## proxies to enforce_edit_permssions. This method is here for you to override
|
147
|
+
def enforce_new_permissions(opts={})
|
148
|
+
enforce_create_permissions(opts)
|
149
|
+
end
|
150
|
+
|
139
151
|
# Controller "before" filter for enforcing access controls on index actions
|
140
152
|
# Currently does nothing, instead relies on
|
141
153
|
# @param [Hash] opts (optional, not currently used)
|
@@ -7,14 +7,19 @@ module Hydra
|
|
7
7
|
set_terminology do |t|
|
8
8
|
t.root(:path=>"rightsMetadata", :xmlns=>"http://hydra-collab.stanford.edu/schemas/rightsMetadata/v1", :schema=>"http://github.com/projecthydra/schemas/tree/v1/rightsMetadata.xsd")
|
9
9
|
t.copyright {
|
10
|
+
## BEGIN possible delete, justin 2012-06-22
|
10
11
|
t.machine {
|
11
|
-
t.uvalicense
|
12
12
|
t.cclicense
|
13
13
|
t.license
|
14
14
|
}
|
15
15
|
t.human_readable(:path=>"human")
|
16
16
|
t.license(:proxy=>[:machine, :license ])
|
17
17
|
t.cclicense(:proxy=>[:machine, :cclicense ])
|
18
|
+
## END possible delete
|
19
|
+
|
20
|
+
t.title(:path=>'human', :attributes=>{:type=>'title'})
|
21
|
+
t.description(:path=>'human', :attributes=>{:type=>'description'})
|
22
|
+
t.url(:path=>'machine', :attributes=>{:type=>'uri'})
|
18
23
|
}
|
19
24
|
t.access {
|
20
25
|
t.human_readable(:path=>"human")
|
@@ -40,6 +45,8 @@ module Hydra
|
|
40
45
|
}
|
41
46
|
t.embargo_release_date(:proxy => [:machine, :date])
|
42
47
|
}
|
48
|
+
|
49
|
+
t.license(:ref=>[:copyright])
|
43
50
|
end
|
44
51
|
|
45
52
|
# Generates an empty Mods Article (used when you call ModsArticle.new without passing in existing xml)
|
@@ -47,10 +54,10 @@ module Hydra
|
|
47
54
|
builder = Nokogiri::XML::Builder.new do |xml|
|
48
55
|
xml.rightsMetadata(:version=>"0.1", "xmlns"=>"http://hydra-collab.stanford.edu/schemas/rightsMetadata/v1") {
|
49
56
|
xml.copyright {
|
50
|
-
xml.human
|
51
|
-
xml.
|
52
|
-
|
53
|
-
|
57
|
+
xml.human(:type=>'title')
|
58
|
+
xml.human(:type=>'description')
|
59
|
+
xml.machine(:type=>'uri')
|
60
|
+
|
54
61
|
}
|
55
62
|
xml.access(:type=>"discover") {
|
56
63
|
xml.human
|
data/spec/spec_helper.rb
CHANGED
@@ -3,14 +3,14 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
3
3
|
|
4
4
|
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
if ENV['COVERAGE'] and RUBY_VERSION =~ /^1.9/
|
7
|
+
require 'simplecov'
|
8
|
+
require 'simplecov-rcov'
|
9
|
+
|
10
|
+
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
|
11
|
+
SimpleCov.start
|
12
|
+
end
|
13
|
+
|
14
14
|
require 'rspec/autorun'
|
15
15
|
require 'hydra-access-controls'
|
16
16
|
require 'support/mods_asset'
|
data/spec/unit/ability_spec.rb
CHANGED
@@ -65,6 +65,9 @@ describe Ability do
|
|
65
65
|
@solr_resp.stub(:docs).and_return([{'read_access_group_t' =>['registered']}])
|
66
66
|
subject.can?(:read, registered_object).should_not be_true
|
67
67
|
end
|
68
|
+
it "should not be able to create objects" do
|
69
|
+
subject.can?(:create, :any).should be_false
|
70
|
+
end
|
68
71
|
end
|
69
72
|
context "for a signed in user" do
|
70
73
|
subject { Ability.new(stub("user", :email=>'archivist1@example.com', :new_record? => false, :is_being_superuser? =>false)) }
|
@@ -78,5 +81,8 @@ describe Ability do
|
|
78
81
|
@solr_resp.stub(:docs).and_return([{'read_access_group_t' =>['registered']}])
|
79
82
|
subject.can?(:read, registered_object).should be_true
|
80
83
|
end
|
84
|
+
it "should be able to create objects" do
|
85
|
+
subject.can?(:create, :any).should be_true
|
86
|
+
end
|
81
87
|
end
|
82
88
|
end
|
@@ -10,6 +10,24 @@ describe Hydra::Datastream::RightsMetadata do
|
|
10
10
|
@sample = Hydra::Datastream::RightsMetadata.new(obj.inner_object, nil)
|
11
11
|
@sample.stub(:content).and_return('')
|
12
12
|
end
|
13
|
+
|
14
|
+
describe "license" do
|
15
|
+
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/"
|
19
|
+
end
|
20
|
+
subject { @sample.license}
|
21
|
+
its(:title) {should == ["Creative Commons Attribution 3.0 Unported License."] }
|
22
|
+
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
|
+
its(:url) {should == ["http://creativecommons.org/licenses/by/3.0/"] }
|
24
|
+
|
25
|
+
it "should be accessable as a term path" do
|
26
|
+
# This enables us to use:
|
27
|
+
# delegate :license_title, :to=>'rightsMetadata', :at=>[:license, :title]
|
28
|
+
@sample.term_values(:license, :title).should == ["Creative Commons Attribution 3.0 Unported License."]
|
29
|
+
end
|
30
|
+
end
|
13
31
|
|
14
32
|
describe "permissions" do
|
15
33
|
describe "setter" do
|
@@ -50,7 +50,6 @@ describe Hydra::ModelMixins::RightsMetadata do
|
|
50
50
|
context "with rightsMetadata" do
|
51
51
|
before do
|
52
52
|
subject.rightsMetadata.update_permissions("person"=>{"person1"=>"read","person2"=>"discover"}, "group"=>{'group-6' => 'read', "group-7"=>'read', 'group-8'=>'edit'})
|
53
|
-
subject.save
|
54
53
|
end
|
55
54
|
it "should have read groups accessor" do
|
56
55
|
subject.read_groups.should == ['group-6', 'group-7']
|
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: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -75,6 +75,22 @@ dependencies:
|
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rake
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
78
94
|
- !ruby/object:Gem::Dependency
|
79
95
|
name: rspec
|
80
96
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,7 +128,6 @@ files:
|
|
112
128
|
- lib/hydra/access_controls_evaluation.rb
|
113
129
|
- lib/hydra/datastream.rb
|
114
130
|
- lib/hydra/datastream/rights_metadata.rb
|
115
|
-
- lib/hydra/model_mixins.rb
|
116
131
|
- lib/hydra/model_mixins/rights_metadata.rb
|
117
132
|
- lib/hydra/role_mapper_behavior.rb
|
118
133
|
- lib/role_mapper.rb
|
@@ -143,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
158
|
version: '0'
|
144
159
|
requirements: []
|
145
160
|
rubyforge_project:
|
146
|
-
rubygems_version: 1.8.
|
161
|
+
rubygems_version: 1.8.24
|
147
162
|
signing_key:
|
148
163
|
specification_version: 3
|
149
164
|
summary: Access controls for project hydra
|