hydra-access-controls 5.1.0 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/app/models/ability.rb +0 -2
- data/lib/hydra/ability.rb +10 -4
- data/spec/unit/ability_spec.rb +24 -0
- metadata +2 -2
data/app/models/ability.rb
CHANGED
data/lib/hydra/ability.rb
CHANGED
@@ -1,11 +1,18 @@
|
|
1
1
|
# Code for [CANCAN] access to Hydra models
|
2
|
+
require 'cancan'
|
2
3
|
module Hydra::Ability
|
3
4
|
extend ActiveSupport::Concern
|
4
5
|
|
6
|
+
# once you include Hydra::Ability you can add custom permission methods by appending to ability_logic like so:
|
7
|
+
#
|
8
|
+
# self.ability_logic +=[:setup_my_permissions]
|
5
9
|
|
6
10
|
included do
|
11
|
+
include CanCan::Ability
|
7
12
|
include Hydra::AccessControlsEnforcement
|
8
13
|
include Blacklight::SolrHelper
|
14
|
+
class_attribute :ability_logic
|
15
|
+
self.ability_logic = [:create_permissions, :edit_permissions, :read_permissions, :custom_permissions]
|
9
16
|
end
|
10
17
|
|
11
18
|
def self.user_class
|
@@ -38,10 +45,9 @@ module Hydra::Ability
|
|
38
45
|
def hydra_default_permissions(user=nil, session=nil)
|
39
46
|
ActiveSupport::Deprecation.warn("No need to pass user or session to hydra_default_permissions, use the instance_variables", caller()) if user || session
|
40
47
|
logger.debug("Usergroups are " + user_groups.inspect)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
custom_permissions()
|
48
|
+
self.ability_logic.each do |method|
|
49
|
+
send(method)
|
50
|
+
end
|
45
51
|
end
|
46
52
|
|
47
53
|
def create_permissions(user=nil, session=nil)
|
data/spec/unit/ability_spec.rb
CHANGED
@@ -245,6 +245,30 @@ describe Ability do
|
|
245
245
|
|
246
246
|
end
|
247
247
|
|
248
|
+
describe "custom method" do
|
249
|
+
before do
|
250
|
+
class MyAbility
|
251
|
+
include Hydra::Ability
|
252
|
+
self.ability_logic +=[:setup_my_permissions]
|
253
|
+
|
254
|
+
def setup_my_permissions
|
255
|
+
can :accept, ActiveFedora::Base
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
after do
|
261
|
+
Object.send(:remove_const, :MyAbility)
|
262
|
+
end
|
263
|
+
|
264
|
+
subject { MyAbility.new(FactoryGirl.create(:staff)) }
|
265
|
+
|
266
|
+
it "should be set the custom permission" do
|
267
|
+
subject.can?(:accept, ActiveFedora::Base).should be_true
|
268
|
+
end
|
269
|
+
|
270
|
+
end
|
271
|
+
|
248
272
|
#
|
249
273
|
# Policy-based Access Controls
|
250
274
|
#
|
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: 5.
|
4
|
+
version: 5.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2013-01-09 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|